Commit ef973e35 authored by Romain Courteaud's avatar Romain Courteaud

ParallelListField are now compatible with the ProxyField, and can be surcharged.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@11611 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c1f2e4ee
......@@ -1107,10 +1107,21 @@ def Field_render_htmlgrid(self, value=None, REQUEST=None, key=None):
render_htmlgrid returns a list of tuple (title, html render)
"""
# What about CSS ? What about description ? What about error ?
return ((self.get_value('title'),
self.render_html(value=value, REQUEST=REQUEST, key=key)),)
widget_key = self.generate_field_key(key=key)
value = self._get_default(key, value, REQUEST)
__traceback_info__ = ('key=%s value=%r' % (key, value))
return self.widget.render_htmlgrid(self, widget_key, value, REQUEST)
Field.render_htmlgrid = Field_render_htmlgrid
def Widget_render_htmlgrid(self, field, key, value, REQUEST):
"""
render_htmlgrid returns a list of tuple (title, html render)
"""
# XXX Calling _render_helper on the field is not optimized
return ((field.get_value('title'),
field._render_helper(key, value, REQUEST)),)
Widget.render_htmlgrid = Widget_render_htmlgrid
# Generic possible renderers
# def render_ext(self, field, key, value, REQUEST):
# return getattr(self, '%s_render' % self.__class__.__name__)
......
......@@ -94,7 +94,7 @@ class ParallelListWidget(Widget.MultiListWidget,
}
def render(self, field, key, value, REQUEST):
hash_list = field._generateSubForm(value, REQUEST)
hash_list = generateSubForm(field, value, REQUEST)
# Call render on each sub field
sub_field_render_list = []
for sub_field_property_dict in hash_list:
......@@ -108,7 +108,7 @@ class ParallelListWidget(Widget.MultiListWidget,
return html_string
def render_htmlgrid(self, field, key, value, REQUEST):
hash_list = field._generateSubForm(value, REQUEST)
hash_list = generateSubForm(field, value, REQUEST)
# Call render on each sub field
sub_field_render_list = []
for sub_field_property_dict in hash_list:
......@@ -160,7 +160,7 @@ class ParallelListValidator(Validator.MultiSelectionValidator):
def validate(self, field, key, REQUEST):
result_list = []
hash_list = field._generateSubForm(None, REQUEST)
hash_list = generateSubForm(field, value, REQUEST)
is_sub_field_required = 0
for sub_field_property_dict in hash_list:
try:
......@@ -220,50 +220,6 @@ class ParallelListField(ZMIField):
html = self.widget.render_htmlgrid(self, key, value, REQUEST)
return html
def _generateSubForm(self, value, REQUEST):
item_list = [x for x in self.get_value('items') \
if x not in (('',''), ['',''])]
value_list = value
if not isinstance(value_list, (list, tuple)):
value_list = [value_list]
empty_sub_field_property_dict = {
'key': 'default',
'title': self.get_value('title'),
'required': 0,
'field_type': 'MultiListField',
'item_list': [],
'value': [],
'is_right_display': 0,
'size': 5,
'editable' : self.get_value('editable')
}
hash_list = []
hash_script_id = self.get_value('hash_script_id')
if hash_script_id not in [None, '']:
script = getattr(self, hash_script_id)
script_hash_list = script(
item_list,
value_list,
default_sub_field_property_dict=empty_sub_field_property_dict,
is_right_display=0)
hash_list.extend(script_hash_list)
else:
# No hash_script founded, generate a little hash_script
# to display only a MultiListField
default_sub_field_property_dict = empty_sub_field_property_dict.copy()
default_sub_field_property_dict.update({
'item_list': item_list,
'value': value_list,
})
hash_list.append(default_sub_field_property_dict)
# XXX Clean up old ParallelListField
if hasattr(self, 'sub_form'):
delattr(self, 'sub_form')
return hash_list
security.declareProtected('Access contents information', 'get_value')
def get_value(self, id, **kw):
"""
......@@ -279,3 +235,47 @@ class ParallelListField(ZMIField):
else:
result = ZMIField.get_value(self, id, **kw)
return result
def generateSubForm(self, value, REQUEST):
item_list = [x for x in self.get_value('items') \
if x not in (('',''), ['',''])]
value_list = value
if not isinstance(value_list, (list, tuple)):
value_list = [value_list]
empty_sub_field_property_dict = {
'key': 'default',
'title': self.get_value('title'),
'required': 0,
'field_type': 'MultiListField',
'item_list': [],
'value': [],
'is_right_display': 0,
'size': 5,
'editable' : self.get_value('editable')
}
hash_list = []
hash_script_id = self.get_value('hash_script_id')
if hash_script_id not in [None, '']:
script = getattr(self, hash_script_id)
script_hash_list = script(
item_list,
value_list,
default_sub_field_property_dict=empty_sub_field_property_dict,
is_right_display=0)
hash_list.extend(script_hash_list)
else:
# No hash_script founded, generate a little hash_script
# to display only a MultiListField
default_sub_field_property_dict = empty_sub_field_property_dict.copy()
default_sub_field_property_dict.update({
'item_list': item_list,
'value': value_list,
})
hash_list.append(default_sub_field_property_dict)
# XXX Clean up old ParallelListField
if hasattr(self, 'sub_form'):
delattr(self, 'sub_form')
return hash_list
......@@ -107,6 +107,17 @@ class ProxyWidget(Widget.Widget):
result = proxy_field.widget.render(field, key, value, REQUEST)
return result
def render_htmlgrid(self, field, key, value, REQUEST):
"""
Render proxy field
"""
result = ''
proxy_field = field.getRecursiveTemplateField()
if proxy_field is not None:
REQUEST = field.updateContext(REQUEST)
result = proxy_field.widget.render_htmlgrid(field, key, value, REQUEST)
return result
def render_view(self, field, value):
"""
Display proxy field
......@@ -479,7 +490,3 @@ class ProxyField(ZMIField):
if proxy_field is not None:
result = proxy_field.has_value(id)
return result
def _generateSubForm(self, value, REQUEST):
proxy_field = self.getTemplateField()
return proxy_field._generateSubForm(value, REQUEST)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment