Commit eb5af9ec authored by Romain Courteaud's avatar Romain Courteaud

Bug fix: it was not possible to use multiple ParallelListField in the same

Form, because some value were temporary put in the REQUEST and are were not
deleted.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@16025 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 3b269cda
...@@ -36,6 +36,10 @@ from zLOG import LOG ...@@ -36,6 +36,10 @@ from zLOG import LOG
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.Formulator.Errors import ValidationError from Products.Formulator.Errors import ValidationError
# Field is is not used in keyword in order to be compatible with Proxyfield
KEYWORD = '_v_plf_%s'
MARKER = []
class ParallelListWidget(Widget.MultiListWidget, class ParallelListWidget(Widget.MultiListWidget,
Widget.ListWidget): Widget.ListWidget):
""" """
...@@ -125,24 +129,29 @@ class ParallelListWidget(Widget.MultiListWidget, ...@@ -125,24 +129,29 @@ class ParallelListWidget(Widget.MultiListWidget,
""" """
Render dynamically a subfield Render dynamically a subfield
""" """
REQUEST.set('_v_plf_title', sub_field_property_dict['title']) for parameter in ('title', 'required', 'size'):
REQUEST.set('_v_plf_required', sub_field_property_dict['required']) REQUEST.set(KEYWORD % parameter, sub_field_property_dict[parameter])
REQUEST.set('_v_plf_default', "") REQUEST.set(KEYWORD % 'default', "")
REQUEST.set('_v_plf_first_item', 0) REQUEST.set(KEYWORD % 'first_item', 0)
REQUEST.set('_v_plf_items', sub_field_property_dict['item_list']) REQUEST.set(KEYWORD % 'items', sub_field_property_dict['item_list'])
REQUEST.set('_v_plf_size', sub_field_property_dict['size'])
if sub_field_property_dict.get('editable', 1): if sub_field_property_dict.get('editable', 1):
return self.sub_widget[sub_field_property_dict['field_type']].render( result = self.sub_widget[sub_field_property_dict['field_type']].render(
field, field,
field.generate_subfield_key(sub_field_property_dict['key'], field.generate_subfield_key(sub_field_property_dict['key'],
key=key), key=key),
sub_field_property_dict['value'], sub_field_property_dict['value'],
REQUEST) REQUEST)
else: else:
return self.sub_widget[sub_field_property_dict['field_type']].render_view( result = self.sub_widget[sub_field_property_dict['field_type']].render_view(
field, field,
sub_field_property_dict['value'], sub_field_property_dict['value'],
) )
for parameter in ('title', 'required', 'size', 'default', 'first_item',
'items'):
# As it doesn't seem possible to delete value in the REQUEST,
# use a marker
REQUEST.set(KEYWORD % parameter, MARKER)
return result
class ParallelListValidator(Validator.MultiSelectionValidator): class ParallelListValidator(Validator.MultiSelectionValidator):
...@@ -192,13 +201,18 @@ class ParallelListValidator(Validator.MultiSelectionValidator): ...@@ -192,13 +201,18 @@ class ParallelListValidator(Validator.MultiSelectionValidator):
""" """
Validates a subfield (as part of field validation). Validates a subfield (as part of field validation).
""" """
REQUEST.set('_v_plf_title', sub_field_property_dict['title']) for parameter in ('title', 'required', 'size'):
REQUEST.set('_v_plf_required', sub_field_property_dict['required']) REQUEST.set(KEYWORD % parameter, sub_field_property_dict[parameter])
REQUEST.set('_v_plf_default', "") REQUEST.set(KEYWORD % 'default', "")
REQUEST.set('_v_plf_items', sub_field_property_dict['item_list']) REQUEST.set(KEYWORD % 'items', sub_field_property_dict['item_list'])
REQUEST.set('_v_plf_size', sub_field_property_dict['size']) result = self.sub_validator[sub_field_property_dict['field_type']].validate(
return self.sub_validator[sub_field_property_dict['field_type']].validate(
field, id, REQUEST) field, id, REQUEST)
for parameter in ('title', 'required', 'size', 'default', 'first_item',
'items'):
# As it doesn't seem possible to delete value in the REQUEST,
# use a marker
REQUEST.set(KEYWORD % parameter, MARKER)
return result
ParallelListWidgetInstance = ParallelListWidget() ParallelListWidgetInstance = ParallelListWidget()
ParallelListFieldValidatorInstance = ParallelListValidator() ParallelListFieldValidatorInstance = ParallelListValidator()
...@@ -210,16 +224,6 @@ class ParallelListField(ZMIField): ...@@ -210,16 +224,6 @@ class ParallelListField(ZMIField):
widget = ParallelListWidgetInstance widget = ParallelListWidgetInstance
validator = ParallelListFieldValidatorInstance validator = ParallelListFieldValidatorInstance
def render_htmlgrid(self, value=None, REQUEST=None, key=None):
"""
render_htmlgrid returns a list of tuple (title, html render)
We will use title generated by the widget.
"""
key = self.generate_field_key(key=key)
value = self._get_default(key, value, REQUEST)
html = self.widget.render_htmlgrid(self, key, value, REQUEST)
return html
security.declareProtected('Access contents information', 'get_value') security.declareProtected('Access contents information', 'get_value')
def get_value(self, id, REQUEST=None, **kw): def get_value(self, id, REQUEST=None, **kw):
""" """
...@@ -227,11 +231,12 @@ class ParallelListField(ZMIField): ...@@ -227,11 +231,12 @@ class ParallelListField(ZMIField):
Optionally pass keyword arguments that get passed to TALES Optionally pass keyword arguments that get passed to TALES
expression. expression.
""" """
key = '_v_plf_%s' % id result = MARKER
key = KEYWORD % id
if (REQUEST is not None) and \ if (REQUEST is not None) and \
(REQUEST.has_key(key)): (REQUEST.has_key(key)):
result = REQUEST.get(key) result = REQUEST.get(key)
else: if result is MARKER:
result = ZMIField.get_value(self, id, REQUEST=REQUEST, **kw) result = ZMIField.get_value(self, id, REQUEST=REQUEST, **kw)
return result return result
......
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