[Erp5-report] r12138 - in /erp5/trunk/products/ERP5Form: ListBox.py tests/testListBox.py

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Jan 18 18:37:57 CET 2007


Author: jerome
Date: Thu Jan 18 18:37:55 2007
New Revision: 12138

URL: http://svn.erp5.org?rev=12138&view=rev
Log:
make sure listbox can be used to display objects that does not provides
"asContext" method.


Modified:
    erp5/trunk/products/ERP5Form/ListBox.py
    erp5/trunk/products/ERP5Form/tests/testListBox.py

Modified: erp5/trunk/products/ERP5Form/ListBox.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Form/ListBox.py?rev=12138&r1=12137&r2=12138&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Form/ListBox.py (original)
+++ erp5/trunk/products/ERP5Form/ListBox.py Thu Jan 18 18:37:55 2007
@@ -2010,7 +2010,7 @@
         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 @@
                           , 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

Modified: erp5/trunk/products/ERP5Form/tests/testListBox.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Form/tests/testListBox.py?rev=12138&r1=12137&r2=12138&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Form/tests/testListBox.py (original)
+++ erp5/trunk/products/ERP5Form/tests/testListBox.py Thu Jan 18 18:37:55 2007
@@ -172,6 +172,7 @@
     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 @@
     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 @@
     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()
@@ -294,6 +297,39 @@
 
     # 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()




More information about the Erp5-report mailing list