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
...@@ -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.
""" """
...@@ -1378,6 +1388,10 @@ class ListBoxRenderer: ...@@ -1378,6 +1388,10 @@ class ListBoxRenderer:
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,11 +1829,9 @@ class ListBoxRendererLine: ...@@ -1815,11 +1829,9 @@ 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',
...@@ -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)
if not self.isSummary() and form.has_field(editable_field_id):
editable_field = form.get_field(editable_field_id)
else:
editable_field = None editable_field = None
if not self.isSummary():
editable_field = self.renderer.getEditableField(alias)
# 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