[Erp5-report] r32365 nicolas - in /erp5/trunk/products/ERP5Type: ./ tests/

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Feb 9 16:04:19 CET 2010


Author: nicolas
Date: Tue Feb  9 16:04:19 2010
New Revision: 32365

URL: http://svn.erp5.org?rev=32365&view=rev
Log:
Handle special use case for Modules
 * action could be categorised as object_list only, getDefaultViewFor
   should fallback to one of them
 * Extend test to avoid regression
Thanks to JM

Modified:
    erp5/trunk/products/ERP5Type/ERP5Type.py
    erp5/trunk/products/ERP5Type/tests/testERP5Type.py

Modified: erp5/trunk/products/ERP5Type/ERP5Type.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/ERP5Type.py?rev=32365&r1=32364&r2=32365&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/ERP5Type.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/ERP5Type.py [utf8] Tue Feb  9 16:04:19 2010
@@ -490,22 +490,22 @@
       """Return the object that renders the default view for the given object
       """
       ec = createExpressionContext(ob)
-      best_action = None
+      other_action = None
       for action in self.getActionList():
-        if action['id'] == view and action.test(ec):
-          best_action = action
-          break
-        else:
+        if action['id'] == view or action['category'].endswith('_' + view):
+          if action.test(ec):
+            break
+        elif other_action is None:
           # In case that "view" (or "list") action is not present or not allowed,
           # find something that's allowed (of the same category, if possible).
-          same_category = action['category'].endswith('_' + view)
-          if same_category and action.test(ec):
-            best_action = action
-            break
+          if action.test(ec):
+            other_action = action
       else:
-        raise AccessControl_Unauthorized(
-          'No accessible views available for %r' % ob.getPath())
-      action = best_action
+        action = other_action
+        if action is None:
+          raise AccessControl_Unauthorized(
+            'No accessible views available for %r' % ob.getPath())
+
       target = action.cook(ec)['url'].strip().split(ec.vars['object_url'])[-1]
       if target.startswith('/'):
           target = target[1:]

Modified: erp5/trunk/products/ERP5Type/tests/testERP5Type.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/tests/testERP5Type.py?rev=32365&r1=32364&r2=32365&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/tests/testERP5Type.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/tests/testERP5Type.py [utf8] Tue Feb  9 16:04:19 2010
@@ -1427,7 +1427,7 @@
 
       # check new default view is resturn
       self.assertEquals("Organisation_viewDetails",
-                  portal_type_object.getDefaultViewFor(obj).getId())  
+                  portal_type_object.getDefaultViewFor(obj).getId())
 
       # Add new action with low priority 
       # We set it no visible
@@ -1444,6 +1444,32 @@
       # Default view must not change
       self.assertEquals("Organisation_viewDetails",
                   portal_type_object.getDefaultViewFor(obj).getId())  
+
+      # If no action belong to view category, getDefaultViewFor
+      # should fallback to first valid Action.
+      # This is the current behaviour for Actions on modules.
+
+      # delete all current actions
+      portal_type_object.manage_delObjects([action.getId() for action in \
+          portal_type_object.contentValues(portal_type='Action Information')])
+
+      # Add new action which does not belong to view category ( action_type: 'object_list')
+      default_list = portal_type_object.newContent(portal_type='Action Information',
+          reference="view_list",
+          title='Web view',
+          action='string:${object_url}/Organisation_viewFinancialInformationList',
+          condition=None,
+          action_permission='View',
+          action_type='object_list',
+          visible=1,
+          float_index=0.2)
+
+      # check new custom action '_list' is return
+      self.assertEquals("Organisation_viewFinancialInformationList",
+                  portal_type_object.getDefaultViewFor(obj).getId())
+
+      # Avoid deletion of actions fo rother tests
+      transaction.abort()
 
     def test_22_securityReindex(self, quiet=quiet, run=run_all_test):
       """




More information about the Erp5-report mailing list