[Erp5-report] r38891 seb - in /erp5/trunk/products/ERP5Type: ./ patches/ tests/

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Oct 5 14:26:17 CEST 2010


Author: seb
Date: Tue Oct  5 14:26:16 2010
New Revision: 38891

URL: http://svn.erp5.org?rev=38891&view=rev
Log:
The priority on actions was somewhat working only by chance.
There was only a sort for action inside a particular provider,
and there was no sorting at all between actions coming from
different action providers.

Modified:
    erp5/trunk/products/ERP5Type/ERP5Type.py
    erp5/trunk/products/ERP5Type/patches/ActionsTool.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=38891&r1=38890&r2=38891&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/ERP5Type.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/ERP5Type.py [utf8] Tue Oct  5 14:26:16 2010
@@ -541,7 +541,6 @@ class ERP5TypeInformation(XMLObject,
 
     def _getActionList(self):
       action_list = self.getCacheableActionList()
-      action_list.sort(key=lambda x:x['priority'])
       return action_list
     _getActionList = CachingMethod(_getActionList,
       id='getActionList',

Modified: erp5/trunk/products/ERP5Type/patches/ActionsTool.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/patches/ActionsTool.py?rev=38891&r1=38890&r2=38891&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/patches/ActionsTool.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/patches/ActionsTool.py [utf8] Tue Oct  5 14:26:16 2010
@@ -100,6 +100,7 @@ def listFilteredActionsFor(self, object=
             # IActionProviders:
             migrateNonProviders(self)
 
+    actions.sort(key=lambda x:x.get('priority', 0))
     # Reorganize the actions by category.
     filtered_actions={'user':[],
                       'folder':[],

Modified: erp5/trunk/products/ERP5Type/tests/testERP5Type.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/tests/testERP5Type.py?rev=38891&r1=38890&r2=38891&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/tests/testERP5Type.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/tests/testERP5Type.py [utf8] Tue Oct  5 14:26:16 2010
@@ -2735,6 +2735,43 @@ class TestPropertySheet:
       self.assertTrue(o.getIcon().endswith(portal.portal_types['Organisation']\
           .getTypeIcon()))
 
+    def test_actionPriority(self):
+      """Tests action priority
+      """
+      portal = self.getPortalObject()
+      portal_actions = self.getPortal().portal_actions
+      try:
+        module = self.getPersonModule()
+        person = module.newContent(id='1', portal_type='Person')
+        def addCustomAction(name, priority):
+          portal_actions.addAction(id=name,
+                                   title=name,
+                                   description='',
+                                   action='string:${object_url}/Base_viewDict',
+                                   condition='',
+                                   permission='View',
+                                   category='object_view',
+                                   priority=priority)
+        initial_action_list = portal_actions.listFilteredActionsFor(person)\
+            .get('object_view',[])
+        addCustomAction('test_before', -1)
+        max_priority = max([x.get('priority', 0) for x in initial_action_list])
+        addCustomAction('test_after', max_priority + 1)
+        final_action_list = portal_actions.listFilteredActionsFor(person)\
+            .get('object_view',[])
+        self.assertEquals(len(final_action_list), len(initial_action_list) + 2)
+        self.assertEquals(final_action_list[0]['id'], 'test_before')
+        self.assertEquals(final_action_list[-1]['id'], 'test_after')
+        # check that we have another portal types action in the middle
+        self.assertTrue('view' in [x['id'] for x in final_action_list[1:-1]])
+      finally:
+        index_list = []
+        action_list = portal_actions._cloneActions()
+        for action in action_list:
+          if action.id in ('test_before', 'test_after'):
+            index_list.append(action_list.index(action))
+        if len(index_list):
+          portal_actions.deleteActions(selections=index_list)
 
 class TestAccessControl(ERP5TypeTestCase):
   # Isolate test in a dedicaced class in order not to break other tests




More information about the Erp5-report mailing list