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
from AccessControl import ClassSecurityInfo
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,
Widget.ListWidget):
"""
......@@ -125,24 +129,29 @@ class ParallelListWidget(Widget.MultiListWidget,
"""
Render dynamically a subfield
"""
REQUEST.set('_v_plf_title', sub_field_property_dict['title'])
REQUEST.set('_v_plf_required', sub_field_property_dict['required'])
REQUEST.set('_v_plf_default', "")
REQUEST.set('_v_plf_first_item', 0)
REQUEST.set('_v_plf_items', sub_field_property_dict['item_list'])
REQUEST.set('_v_plf_size', sub_field_property_dict['size'])
for parameter in ('title', 'required', 'size'):
REQUEST.set(KEYWORD % parameter, sub_field_property_dict[parameter])
REQUEST.set(KEYWORD % 'default', "")
REQUEST.set(KEYWORD % 'first_item', 0)
REQUEST.set(KEYWORD % 'items', sub_field_property_dict['item_list'])
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.generate_subfield_key(sub_field_property_dict['key'],
key=key),
sub_field_property_dict['value'],
REQUEST)
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,
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):
......@@ -192,13 +201,18 @@ class ParallelListValidator(Validator.MultiSelectionValidator):
"""
Validates a subfield (as part of field validation).
"""
REQUEST.set('_v_plf_title', sub_field_property_dict['title'])
REQUEST.set('_v_plf_required', sub_field_property_dict['required'])
REQUEST.set('_v_plf_default', "")
REQUEST.set('_v_plf_items', sub_field_property_dict['item_list'])
REQUEST.set('_v_plf_size', sub_field_property_dict['size'])
return self.sub_validator[sub_field_property_dict['field_type']].validate(
for parameter in ('title', 'required', 'size'):
REQUEST.set(KEYWORD % parameter, sub_field_property_dict[parameter])
REQUEST.set(KEYWORD % 'default', "")
REQUEST.set(KEYWORD % 'items', sub_field_property_dict['item_list'])
result = self.sub_validator[sub_field_property_dict['field_type']].validate(
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()
ParallelListFieldValidatorInstance = ParallelListValidator()
......@@ -210,16 +224,6 @@ class ParallelListField(ZMIField):
widget = ParallelListWidgetInstance
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')
def get_value(self, id, REQUEST=None, **kw):
"""
......@@ -227,11 +231,12 @@ class ParallelListField(ZMIField):
Optionally pass keyword arguments that get passed to TALES
expression.
"""
key = '_v_plf_%s' % id
result = MARKER
key = KEYWORD % id
if (REQUEST is not None) and \
(REQUEST.has_key(key)):
result = REQUEST.get(key)
else:
if result is MARKER:
result = ZMIField.get_value(self, id, REQUEST=REQUEST, **kw)
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