Commit abd2d6b3 authored by Jérome Perrin's avatar Jérome Perrin

make sure listbox can be used to display objects that does not provides

"asContext" method.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@12138 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 76c91943
...@@ -2010,7 +2010,7 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine): ...@@ -2010,7 +2010,7 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine):
else: else:
error_message = u'' 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) # We needed a way to pass the current line object (ie. brain)
# to the field which is being displayed. Since the # to the field which is being displayed. Since the
# render_view API did not permit this, we pass the line object # render_view API did not permit this, we pass the line object
...@@ -2029,7 +2029,7 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine): ...@@ -2029,7 +2029,7 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine):
, key = key , key = key
) )
else: else:
# No brain, no way # If the brain does not support asContext (eg. it is None), no way
self.renderer.request.cell = self.getObject() self.renderer.request.cell = self.getObject()
cell_html = editable_field.render( value = display_value cell_html = editable_field.render( value = display_value
, REQUEST = brain , REQUEST = brain
......
...@@ -172,6 +172,7 @@ return [] ...@@ -172,6 +172,7 @@ return []
listbox = portal.FooModule_viewFooList.listbox listbox = portal.FooModule_viewFooList.listbox
listbox.ListBox_setPropertyList( listbox.ListBox_setPropertyList(
field_list_method = list_method_id, field_list_method = list_method_id,
field_count_method = '',
field_sort = 'title | ASC\n' field_sort = 'title | ASC\n'
'uid | ASC',) 'uid | ASC',)
...@@ -204,6 +205,7 @@ return [] ...@@ -204,6 +205,7 @@ return []
listbox = portal.FooModule_viewFooList.listbox listbox = portal.FooModule_viewFooList.listbox
listbox.ListBox_setPropertyList( listbox.ListBox_setPropertyList(
field_list_method = list_method_id, field_list_method = list_method_id,
field_count_method = '',
field_default_params = 'dummy_default_param | dummy value',) field_default_params = 'dummy_default_param | dummy value',)
# render the listbox, checks are done by list method itself # render the listbox, checks are done by list method itself
...@@ -229,6 +231,7 @@ return [] ...@@ -229,6 +231,7 @@ return []
listbox = portal.FooModule_viewFooList.listbox listbox = portal.FooModule_viewFooList.listbox
listbox.ListBox_setPropertyList( listbox.ListBox_setPropertyList(
field_list_method = list_method_id, field_list_method = list_method_id,
field_count_method = '',
field_columns = ['alternate_title | Alternate Title',],) field_columns = ['alternate_title | Alternate Title',],)
request = get_request() request = get_request()
...@@ -295,6 +298,39 @@ return [] ...@@ -295,6 +298,39 @@ return []
# Make sure that word is there # Make sure that word is there
self.assertEqual(rendered_listbox.find(word) > 0, True) 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__': if __name__ == '__main__':
framework() framework()
else: else:
......
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