diff --git a/product/ERP5Form/ListBox.py b/product/ERP5Form/ListBox.py index fc1557b0515df34823166e67528e58d7b2df56e8..eb9ac9f1eb8e13c485664b00c860f3144f80a230 100644 --- a/product/ERP5Form/ListBox.py +++ b/product/ERP5Form/ListBox.py @@ -2010,7 +2010,7 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine): else: error_message = u'' - if brain is not None: + if getattr(brain, 'asContext', None) is not None: # We needed 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 pass the line object @@ -2029,7 +2029,7 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine): , key = key ) else: - # No brain, no way + # If the brain does not support asContext (eg. it is None), no way self.renderer.request.cell = self.getObject() cell_html = editable_field.render( value = display_value , REQUEST = brain diff --git a/product/ERP5Form/tests/testListBox.py b/product/ERP5Form/tests/testListBox.py index 2abe11ecf82f2262592384fb43b121a1e4f9d8ce..b04f49942e7718c302373bd3cc1c5b8ad6ac0815 100644 --- a/product/ERP5Form/tests/testListBox.py +++ b/product/ERP5Form/tests/testListBox.py @@ -172,6 +172,7 @@ return [] listbox = portal.FooModule_viewFooList.listbox listbox.ListBox_setPropertyList( field_list_method = list_method_id, + field_count_method = '', field_sort = 'title | ASC\n' 'uid | ASC',) @@ -204,6 +205,7 @@ return [] listbox = portal.FooModule_viewFooList.listbox listbox.ListBox_setPropertyList( field_list_method = list_method_id, + field_count_method = '', field_default_params = 'dummy_default_param | dummy value',) # render the listbox, checks are done by list method itself @@ -229,6 +231,7 @@ return [] listbox = portal.FooModule_viewFooList.listbox listbox.ListBox_setPropertyList( field_list_method = list_method_id, + field_count_method = '', field_columns = ['alternate_title | Alternate Title',],) request = get_request() @@ -295,6 +298,39 @@ return [] # Make sure that word is there self.assertEqual(rendered_listbox.find(word) > 0, True) + 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 + # string starting by new_ (a convention to prevent indexing of objects). + portal = self.getPortal() + list_method_id = 'DummyListMethodId' + portal.ListBoxZuite_reset() + form = portal.FooModule_viewFooList + listbox = form.listbox + listbox.ListBox_setPropertyList( + field_list_method = list_method_id, + field_count_method = '', + field_editable_columns = ['title | title'], + field_columns = ['title | Title',],) + form.manage_addField('listbox_title', 'Title', 'StringField') + + createZODBPythonScript( + portal.portal_skins.custom, + list_method_id, + 'selection=None, **kw', + "from Products.PythonScripts.standard import Object\n" + "return [Object(uid='new_', title='Object Title')]") + + request = get_request() + request['here'] = portal.foo_module + line_list = [l for l in listbox.get_value('default', + render_format='list', + REQUEST=request) if l.isDataLine()] + self.assertEquals(1, len(line_list)) + self.assertEquals('Object Title', line_list[0].getColumnProperty('title')) + html = listbox.render(REQUEST=request) + self.failUnless('Object Title' in html, html) + if __name__ == '__main__': framework() else: