Commit 440b3925 authored by Nicolas Dumazet's avatar Nicolas Dumazet

fix TestListBox.test_09_editablePropertyPrecedence:

add an 'editable' parameter to render, to allow overriding a field's
editable property from the listbox renderer


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@33680 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c593cb32
......@@ -2295,6 +2295,7 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine):
# XXX what if the object does not have uid?
key = '%s_%s' % (editable_field.getId(), self.getUid())
if sql in editable_column_id_set:
listbox_defines_column_as_editable = True
if has_error: # If there is any error on listbox, we should use what the user has typed
display_value = None
else:
......@@ -2324,18 +2325,24 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine):
else:
error_message = u''
else:
listbox_defines_column_as_editable = False
error_message = u''
display_value = original_value
# We need a way to pass the current line object (ie. brain) to the
# field which is being displayed. Since the render_view API did not
# permit this, we use the 'cell' value to pass the line object.
request.set('cell', brain)
enabled = editable_field.get_value('enabled', REQUEST=request)
if enabled:
cell_html = editable_field.render(value=display_value,
REQUEST=request,
key=key)
# We need a way to pass the current line object (ie. brain) to the
# field which is being displayed. Since the render_view API did not
# permit this, we use the 'cell' value to pass the line object.
request.set('cell', brain)
# Listbox 'editable' configuration should take precedence over
# individual field configuration
cell_html = editable_field.render(
value=display_value,
REQUEST=request,
key=key,
editable=listbox_defines_column_as_editable,
)
if isinstance(cell_html, str):
cell_html = unicode(cell_html, encoding)
else:
......
......@@ -192,17 +192,20 @@ class Field:
return "Unknown error: %s" % name
security.declarePrivate('_render_helper')
def _render_helper(self, key, value, REQUEST, render_prefix=None):
def _render_helper(self, key, value, REQUEST, render_prefix=None, editable=None):
value = self._get_default(key, value, REQUEST)
__traceback_info__ = ('key=%s value=%r' % (key, value))
if self.get_value('hidden', REQUEST=REQUEST):
return self.widget.render_hidden(self, key, value, REQUEST)
elif (not self.get_value('editable', REQUEST=REQUEST)):
return self.widget.render_view(self, value, REQUEST=REQUEST,
render_prefix=render_prefix)
else:
return self.widget.render(self, key, value, REQUEST,
render_prefix=render_prefix)
if editable is None:
editable = self.get_value('editable', REQUEST=REQUEST)
if not editable:
return self.widget.render_view(self, value, REQUEST=REQUEST,
render_prefix=render_prefix)
else:
return self.widget.render(self, key, value, REQUEST,
render_prefix=render_prefix)
security.declarePrivate('_render_helper')
def _render_odt_helper(self, key, value, as_string, ooo_builder,
......@@ -246,18 +249,25 @@ class Field:
return REQUEST.form[key]
security.declareProtected('View', 'render')
def render(self, value=None, REQUEST=None, key=None, render_prefix=None, key_prefix=None):
def render(self, value=None, REQUEST=None, key=None, render_prefix=None, key_prefix=None, editable=None):
"""Render the field widget.
value -- the value the field should have (for instance
from validation).
REQUEST -- REQUEST can contain raw (unvalidated) field
information. If value is None, REQUEST is searched
for this value.
editable -- if not None, this boolean can override the Editable property
of the rendered field
if value and REQUEST are both None, the 'default' property of
the field will be used for the value.
"""
return self._render_helper(self.generate_field_key(key=key, key_prefix=key_prefix), value, REQUEST,
render_prefix)
return self._render_helper(
self.generate_field_key(key=key, key_prefix=key_prefix),
value,
REQUEST,
render_prefix=render_prefix,
editable=editable,
)
security.declareProtected('View', 'render_view')
def render_view(self, value=None, REQUEST=None, render_prefix=None):
......
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