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): ...@@ -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) render_htmlgrid returns a list of tuple (title, html render)
""" """
# What about CSS ? What about description ? What about error ? # What about CSS ? What about description ? What about error ?
return ((self.get_value('title'), widget_key = self.generate_field_key(key=key)
self.render_html(value=value, REQUEST=REQUEST, 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 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 # Generic possible renderers
# def render_ext(self, field, key, value, REQUEST): # def render_ext(self, field, key, value, REQUEST):
# return getattr(self, '%s_render' % self.__class__.__name__) # return getattr(self, '%s_render' % self.__class__.__name__)
......
...@@ -94,7 +94,7 @@ class ParallelListWidget(Widget.MultiListWidget, ...@@ -94,7 +94,7 @@ class ParallelListWidget(Widget.MultiListWidget,
} }
def render(self, field, key, value, REQUEST): 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 # Call render on each sub field
sub_field_render_list = [] sub_field_render_list = []
for sub_field_property_dict in hash_list: for sub_field_property_dict in hash_list:
...@@ -108,7 +108,7 @@ class ParallelListWidget(Widget.MultiListWidget, ...@@ -108,7 +108,7 @@ class ParallelListWidget(Widget.MultiListWidget,
return html_string return html_string
def render_htmlgrid(self, field, key, value, REQUEST): 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 # Call render on each sub field
sub_field_render_list = [] sub_field_render_list = []
for sub_field_property_dict in hash_list: for sub_field_property_dict in hash_list:
...@@ -160,7 +160,7 @@ class ParallelListValidator(Validator.MultiSelectionValidator): ...@@ -160,7 +160,7 @@ class ParallelListValidator(Validator.MultiSelectionValidator):
def validate(self, field, key, REQUEST): def validate(self, field, key, REQUEST):
result_list = [] result_list = []
hash_list = field._generateSubForm(None, REQUEST) hash_list = generateSubForm(field, value, REQUEST)
is_sub_field_required = 0 is_sub_field_required = 0
for sub_field_property_dict in hash_list: for sub_field_property_dict in hash_list:
try: try:
...@@ -220,7 +220,23 @@ class ParallelListField(ZMIField): ...@@ -220,7 +220,23 @@ class ParallelListField(ZMIField):
html = self.widget.render_htmlgrid(self, key, value, REQUEST) html = self.widget.render_htmlgrid(self, key, value, REQUEST)
return html return html
def _generateSubForm(self, value, REQUEST): security.declareProtected('Access contents information', 'get_value')
def get_value(self, id, **kw):
"""
Get value for id.
Optionally pass keyword arguments that get passed to TALES
expression.
"""
REQUEST = kw.get('REQUEST')
key = '_v_plf_%s' % id
if (REQUEST is not None) and \
(REQUEST.has_key(key)):
result = REQUEST.get(key)
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') \ item_list = [x for x in self.get_value('items') \
if x not in (('',''), ['',''])] if x not in (('',''), ['',''])]
...@@ -263,19 +279,3 @@ class ParallelListField(ZMIField): ...@@ -263,19 +279,3 @@ class ParallelListField(ZMIField):
if hasattr(self, 'sub_form'): if hasattr(self, 'sub_form'):
delattr(self, 'sub_form') delattr(self, 'sub_form')
return hash_list return hash_list
security.declareProtected('Access contents information', 'get_value')
def get_value(self, id, **kw):
"""
Get value for id.
Optionally pass keyword arguments that get passed to TALES
expression.
"""
REQUEST = kw.get('REQUEST')
key = '_v_plf_%s' % id
if (REQUEST is not None) and \
(REQUEST.has_key(key)):
result = REQUEST.get(key)
else:
result = ZMIField.get_value(self, id, **kw)
return result
...@@ -107,6 +107,17 @@ class ProxyWidget(Widget.Widget): ...@@ -107,6 +107,17 @@ class ProxyWidget(Widget.Widget):
result = proxy_field.widget.render(field, key, value, REQUEST) result = proxy_field.widget.render(field, key, value, REQUEST)
return result 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): def render_view(self, field, value):
""" """
Display proxy field Display proxy field
...@@ -479,7 +490,3 @@ class ProxyField(ZMIField): ...@@ -479,7 +490,3 @@ class ProxyField(ZMIField):
if proxy_field is not None: if proxy_field is not None:
result = proxy_field.has_value(id) result = proxy_field.has_value(id)
return result 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