Commit 69cadd08 authored by Jean-Paul Smets's avatar Jean-Paul Smets

Fix bug #55

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@12052 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b20eddbd
...@@ -37,6 +37,7 @@ from Selection import Selection, DomainSelection ...@@ -37,6 +37,7 @@ from Selection import Selection, DomainSelection
from Products.ERP5Type.Utils import getPath from Products.ERP5Type.Utils import getPath
from Products.ERP5Type.Document import newTempBase from Products.ERP5Type.Document import newTempBase
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
from Products.CMFCore.utils import _checkPermission
from Products.ZSQLCatalog.zsqlbrain import ZSQLBrain from Products.ZSQLCatalog.zsqlbrain import ZSQLBrain
from Products.ERP5Type.Message import Message from Products.ERP5Type.Message import Message
...@@ -1711,6 +1712,13 @@ class ListBoxRendererLine: ...@@ -1711,6 +1712,13 @@ class ListBoxRendererLine:
getUid = VolatileCachingMethod(getUid) getUid = VolatileCachingMethod(getUid)
def getUrl(self):
"""Return the absolute URL path of the object
"""
return self.getBrain().getUrl()
getUrl = VolatileCachingMethod(getUrl)
def isSummary(self): def isSummary(self):
"""Return whether this line is a summary or not. """Return whether this line is a summary or not.
""" """
...@@ -1894,6 +1902,19 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine): ...@@ -1894,6 +1902,19 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine):
html_list = [] html_list = []
# Check is there is a validation error at the level of the listbox
# as a whole. This will be required later to decide wherer to
# display values from (ie. from the REQUEST or from the object)
has_error = 0
for key in error_dict.keys():
for editable_id in editable_column_id_set:
candidate_field_key = "%s_%s" % (field_id, editable_id)
if key.startswith(candidate_field_key):
has_error = 1
break
if has_error:
break
for (original_value, processed_value), (sql, title), alias \ for (original_value, processed_value), (sql, title), alias \
in zip(self.getValueList(), self.renderer.getSelectedColumnList(), self.renderer.getColumnAliasList()): in zip(self.getValueList(), self.renderer.getSelectedColumnList(), self.renderer.getColumnAliasList()):
# By default, no error. # By default, no error.
...@@ -1956,38 +1977,51 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine): ...@@ -1956,38 +1977,51 @@ 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_id, self.getUid())
if error_dict.has_key(key): widget_key = editable_field.generate_field_key(key=key)
error = True if has_error: # If there is any error on listbox, we should use what the user has typed
display_value = None
else:
validated_value_dict = self.renderer.request.get(field_id, None)
if validated_value_dict is None:
# If this is neither an error nor a validated listbox
# we should use the original value
display_value = original_value
else:
# If the listbox has been validated (ie. as it is the
# case whenever a relation field displays a popup menu)
# we have to use the value entered by the user
display_value = None #
if error_dict.has_key(key): # If error on current field, we should display message
error_text = error_dict[key].error_text error_text = error_dict[key].error_text
error_text = cgi.escape(error_text) error_text = cgi.escape(error_text)
if isinstance(error_text, str): if isinstance(error_text, str):
error_text = unicode(error_text, encoding) error_text = unicode(error_text, encoding)
error_message = u'<br />' + error_text error_message = u'<br />' + error_text
widget_key = editable_field.generate_field_key(key=key)
error_value = self.renderer.request.get(widget_key, None)
else: else:
error_message = u'' error_message = u''
error_value = None
# XXX this is a horrible hack. if brain is not None:
if editable_field.meta_type in ('DateTimeField', 'ProxyField', ): # We needed a way to pass the current line object (ie. brain)
# XXX Some fields prefer None to ''. # to the field which is being displayed. Since the
# render_view API did not permit this, we pass the line object
# as the REQUEST. But this has side effects since it breaks
# many possibilities. Therefore, the trick is to wrap
# the REQUEST into the brain. In addition, the define a
# cell property on the request itself so that forms may
# use the 'cell' value (refer to get_value method in Form.py)
cell_html = editable_field.render( \ cell_html = editable_field.render( \
value = error_value or original_value value = display_value
, REQUEST = brain.asContext( \ , REQUEST = brain.asContext( \
REQUEST = self.renderer.request REQUEST = self.renderer.request
, form = self.renderer.request.form , form = self.renderer.request.form
, cell = self.getObject()
) )
, key = key , key = key
) )
else: else:
# We use REQUEST which is not so good here. # No brain, no way
# This prevents from using standard display process. self.renderer.request.cell = self.getObject()
# XXX what does the above comment mean exactly? why don't we fix Formulator? cell_html = editable_field.render( value = error_value or user_value or display_value
# XXX (JPS) - render_view does not get REQUEST - this breaks so many possibilities
REQUEST = get_request() # Dirtymax hack by JPS - render_view API update required
REQUEST.cell = self.getObject()
cell_html = editable_field.render( value = error_value or original_value
, REQUEST = brain , REQUEST = brain
, key = key , key = key
) )
...@@ -2010,6 +2044,8 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine): ...@@ -2010,6 +2044,8 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine):
if url is None: if url is None:
html = processed_value html = processed_value
else: else:
# JPS-XXX - I think we should not display a URL for objects
# which do not have the View permission
html = u'<a href="%s">%s</a>' % (url, processed_value) html = u'<a href="%s">%s</a>' % (url, processed_value)
html_list.append((html, original_value, error, editable_field)) html_list.append((html, original_value, error, editable_field))
......
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