Commit 16d1962c authored by Jérome Perrin's avatar Jérome Perrin

reuse editable field to render stat line in HTML



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@12093 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8aaffeb0
...@@ -939,7 +939,7 @@ class ListBoxRenderer: ...@@ -939,7 +939,7 @@ class ListBoxRenderer:
params.setdefault('meta_type', meta_type_list) params.setdefault('meta_type', meta_type_list)
# Remove useless parameters as FileUpload # Remove useless parameters as FileUpload
for k, v in params.items(): for k, v in params.items():
if k == "listbox": if k == "listbox":
# listbox can also contain useless parameters # listbox can also contain useless parameters
new_list = [] new_list = []
...@@ -948,7 +948,7 @@ class ListBoxRenderer: ...@@ -948,7 +948,7 @@ class ListBoxRenderer:
if v1 in (None, '') or hasattr(v1, 'read'): if v1 in (None, '') or hasattr(v1, 'read'):
del line[k1] del line[k1]
new_list.append(line) new_list.append(line)
params[k] = new_list params[k] = new_list
if v in (None, '') or hasattr(v, 'read'): if v in (None, '') or hasattr(v, 'read'):
del params[k] del params[k]
...@@ -992,6 +992,16 @@ class ListBoxRenderer: ...@@ -992,6 +992,16 @@ class ListBoxRenderer:
getParamDict = VolatileCachingMethod(getParamDict) getParamDict = VolatileCachingMethod(getParamDict)
def getEditableField(self, alias):
"""Get an editable field for column, using column alias.
Return None if a field for this column does not exist.
"""
form = self.getForm()
editable_field_id = '%s_%s' % (self.getId(), alias)
if form.has_field(editable_field_id):
return form.get_field(editable_field_id)
return None
def getListMethod(self): def getListMethod(self):
"""Return the list method object. """Return the list method object.
""" """
...@@ -1377,6 +1387,10 @@ class ListBoxRenderer: ...@@ -1377,6 +1387,10 @@ class ListBoxRenderer:
else: else:
original_value = stat_method original_value = stat_method
processed_value = original_value processed_value = original_value
editable_field = self.getEditableField(alias)
if editable_field is not None:
processed_value = editable_field.render_view(value=original_value)
if not isinstance(processed_value, unicode): if not isinstance(processed_value, unicode):
processed_value = unicode(str(processed_value), self.getEncoding()) processed_value = unicode(str(processed_value), self.getEncoding())
...@@ -1815,17 +1829,15 @@ class ListBoxRendererLine: ...@@ -1815,17 +1829,15 @@ class ListBoxRendererLine:
brain = self.getBrain() brain = self.getBrain()
# Use a widget, if any. # Use a widget, if any.
editable_field_id = '%s_%s' % (self.renderer.getId(), alias) editable_field = self.renderer.getEditableField(alias)
tales = False tales = False
form = self.renderer.getForm() if editable_field is not None:
if form.has_field(editable_field_id):
editable_field = form.get_field(editable_field_id)
tales = editable_field.tales.get('default', '') tales = editable_field.tales.get('default', '')
if tales: if tales:
original_value = editable_field.__of__(obj).get_value('default', original_value = editable_field.__of__(obj).get_value('default',
cell=brain) cell=brain)
processed_value = original_value processed_value = original_value
# If a tales expression is not defined, get a skin, an accessor or a property. # If a tales expression is not defined, get a skin, an accessor or a property.
if not tales: if not tales:
if hasattr(aq_self(brain), alias): if hasattr(aq_self(brain), alias):
...@@ -1925,11 +1937,9 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine): ...@@ -1925,11 +1937,9 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine):
# If a field is editable, generate an input form. # If a field is editable, generate an input form.
# XXX why don't we generate an input form when a widget is not defined? # XXX why don't we generate an input form when a widget is not defined?
editable_field_id = '%s_%s' % (field_id, alias) editable_field = None
if not self.isSummary() and form.has_field(editable_field_id): if not self.isSummary():
editable_field = form.get_field(editable_field_id) editable_field = self.renderer.getEditableField(alias)
else:
editable_field = None
# Prepare link value - we now use it for both static and field rendering # Prepare link value - we now use it for both static and field rendering
no_link = False no_link = False
...@@ -1976,7 +1986,7 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine): ...@@ -1976,7 +1986,7 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine):
if editable_field is not None and sql in editable_column_id_set: if editable_field is not None and sql in editable_column_id_set:
# XXX what if the object does not have uid? # XXX what if the object does not have uid?
key = '%s_%s' % (editable_field_id, self.getUid()) key = '%s_%s' % (editable_field.getId(), self.getUid())
widget_key = editable_field.generate_field_key(key=key) widget_key = editable_field.generate_field_key(key=key)
if has_error: # If there is any error on listbox, we should use what the user has typed if has_error: # If there is any error on listbox, we should use what the user has typed
display_value = None display_value = None
......
...@@ -310,7 +310,7 @@ ...@@ -310,7 +310,7 @@
<td class="Data" align="left" <td class="Data" align="left"
tal:define="original_value python: value[0]; processed_value python: value[1]" tal:define="original_value python: value[0]; processed_value python: value[1]"
tal:attributes="align python: isinstance(original_value, (float, int, long)) and 'right' or 'left'" tal:attributes="align python: isinstance(original_value, (float, int, long)) and 'right' or 'left'"
tal:content="processed_value" /> tal:content="structure processed_value" />
</tal:block> </tal:block>
</tr> </tr>
</table> </table>
......
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