[Erp5-report] r35858 kazuhiko - /erp5/trunk/products/ERP5Type/Base.py

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Jun 1 13:47:46 CEST 2010


Author: kazuhiko
Date: Tue Jun  1 13:47:41 2010
New Revision: 35858

URL: http://svn.erp5.org?rev=35858&view=rev
Log:
Introduce a new method getGroupedStateList() that makes it possible to get state list per portal type, and if it cannot be found by workflow chains for the portal type, try to get from portal for compatibility.

Modified:
    erp5/trunk/products/ERP5Type/Base.py

Modified: erp5/trunk/products/ERP5Type/Base.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Base.py?rev=35858&r1=35857&r2=35858&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Base.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Base.py [utf8] Tue Jun  1 13:47:41 2010
@@ -3801,6 +3801,41 @@
   def isItem(self):
     return self.portal_type in self.getPortalItemTypeList()
 
+  security.declareProtected(Permissions.AccessContentsInformation,
+                            'getGroupedStateList')
+  def getGroupedStateList(self, group):
+    """
+    Return a list of workflow states classified to a specific group.
+    """
+    portal_type = self.getPortalType()
+
+    def getStateList(portal_type, group):
+      state_dict = {}
+      portal_workflow = self.getPortalObject().portal_workflow
+      wf_id_list = portal_workflow.getChainFor(portal_type)
+      for wf_id in wf_id_list:
+        states = getattr(portal_workflow[wf_id], 'states', None)
+        if states is not None:
+          for state in states.objectValues():
+            if group in getattr(state, 'type_list', ()):
+              state_dict[state.getId()] = None
+      return tuple(state_dict.keys())
+
+    getStateList = CachingMethod(
+      getStateList,
+      id=('_getPortalGroupedStateList', portal_type, group),
+      cache_factory='erp5_content_medium')
+
+    state_list = getStateList(portal_type, group)
+    if len(state_list) == 0:
+      # If we cannot get state list from this portal type's workflow
+      # chain, try to get from the portal.
+      portal = self.getPortalObject()
+      state_list = portal._getPortalGroupedStateList(group) or \
+          portal._getPortalConfiguration('portal_%s_state_list' % group)
+
+    return state_list
+
 InitializeClass(Base)
 
 try:




More information about the Erp5-report mailing list