diff --git a/product/ERP5Form/ListBox.py b/product/ERP5Form/ListBox.py index 3701ff51bf466a6467d1cbd0a298e867b681141b..efdad0eb4d2f925935b16abb74cbc993929c90ba 100644 --- a/product/ERP5Form/ListBox.py +++ b/product/ERP5Form/ListBox.py @@ -2291,37 +2291,41 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine): except AttributeError: pass - if editable_field is not None and sql in editable_column_id_set: + if editable_field is not None: # XXX what if the object does not have uid? key = '%s_%s' % (editable_field.getId(), self.getUid()) - 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 = 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 + if sql in editable_column_id_set: + if has_error: # If there is any error on listbox, we should use what the user has typed + display_value = None 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 = cgi.escape(error_text) - if isinstance(error_text, str): - error_mapping = getattr(error_dict[key], 'error_mapping', None) - if error_mapping is not None: - error_text = u'%s' % Message(domain=ui_domain, - message=error_text, - mapping=error_mapping) + validated_value_dict = 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: - error_text = u'%s' % Message(domain=ui_domain, - message=error_text) - error_message = u'<br />' + error_text + # 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 = cgi.escape(error_text) + if isinstance(error_text, str): + error_mapping = getattr(error_dict[key], 'error_mapping', None) + if error_mapping is not None: + error_text = u'%s' % Message(domain=ui_domain, + message=error_text, + mapping=error_mapping) + else: + error_text = u'%s' % Message(domain=ui_domain, + message=error_text) + error_message = u'<br />' + error_text + else: + error_message = u'' else: 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 diff --git a/product/ERP5Form/tests/testListBox.py b/product/ERP5Form/tests/testListBox.py index 5b081d3fec5d15449fac60835ddc13ddf1ca6cb9..5c0c86ef390b8686aff87cb1ba2bd0d6da97b00d 100644 --- a/product/ERP5Form/tests/testListBox.py +++ b/product/ERP5Form/tests/testListBox.py @@ -296,6 +296,48 @@ return [] # Make sure that word is there self.assertEqual(rendered_listbox.find(word) > 0, True) + def test_07_ExtraAndCssFieldsInIntegerField(self, quiet=0, run=run_all_test): + """ + Check that css_class and extra fields are rendered when used in a + listbox_xxx line, using IntegerField for the check. + """ + portal = self.getPortal() + portal.ListBoxZuite_reset() + + # Reset listbox properties + listbox = portal.FooModule_viewFooList.listbox + listbox.ListBox_setPropertyList( + field_list_method = 'portal_catalog', + field_columns = ['extra | Check extra',], + ) + + form = portal.FooModule_viewFooList + form.manage_addField('listbox_extra', 'extra', 'IntegerField') + integerfield = form.listbox_extra + + word = 'dummy_%s_to_check_for_in_listbox_test' + extra = word % "extra" + css_class = word % "css_class" + integerfield.values['extra'] = "alt='%s'" % extra + integerfield.values['css_class'] = css_class + integerfield.values['default'] = '42' + + # Create an new empty object with a list property + foo_module = portal.foo_module + o = foo_module.newContent() + + # Reindex + o.immediateReindexObject() + + # Render the module in html + request = get_request() + request['here'] = portal.foo_module + rendered_listbox = listbox.render(REQUEST=request) + + # Make sure that the extras and css_classes + self.assertTrue(extra in rendered_listbox) + self.assertTrue(css_class in rendered_listbox) + def test_ObjectSupport(self): # make sure listbox supports rendering of simple objects # the only requirement is that objects have a `uid` attribute which is a