[wf] refactor current_workflow by extracting cwetype_workflow method 3.5
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 21 Aug 2009 08:44:16 +0200
branch3.5
changeset 2946 957fd4b276e2
parent 2945 f0ab83510477
child 2947 083593802120
[wf] refactor current_workflow by extracting cwetype_workflow method
entities/wfobjs.py
--- a/entities/wfobjs.py	Fri Aug 21 08:43:28 2009 +0200
+++ b/entities/wfobjs.py	Fri Aug 21 08:44:16 2009 +0200
@@ -261,23 +261,11 @@
     __implements__ = (IWorkflowable,)
 
     @property
-    @cached
     def current_workflow(self):
         """return current workflow applied to this entity"""
         if self.custom_workflow:
             return self.custom_workflow[0]
-        wfrset = self.req.execute('Any WF WHERE X is ET, X eid %(x)s, WF workflow_of ET',
-                                  {'x': self.eid}, 'x')
-        if len(wfrset) == 1:
-            return wfrset.get_entity(0, 0)
-        if len(wfrset) > 1:
-            for wf in wfrset.entities():
-                if wf.is_default_workflow_of(self.id):
-                    return wf
-            self.warning("can't find default workflow for %s", self.id)
-        else:
-            self.warning("can't find any workflow for %s", self.id)
-        return None
+        return self.cwetype_workflow()
 
     @property
     def current_state(self):
@@ -305,6 +293,23 @@
         """return the latest transition information for this entity"""
         return self.reverse_wf_info_for[-1]
 
+    @cached
+    def cwetype_workflow(self):
+        """return the default workflow for entities of this type"""
+        # XXX CWEType method
+        wfrset = self.req.execute('Any WF WHERE X is ET, X eid %(x)s, '
+                                  'WF workflow_of ET', {'x': self.eid}, 'x')
+        if len(wfrset) == 1:
+            return wfrset.get_entity(0, 0)
+        if len(wfrset) > 1:
+            for wf in wfrset.entities():
+                if wf.is_default_workflow_of(self.id):
+                    return wf
+            self.warning("can't find default workflow for %s", self.id)
+        else:
+            self.warning("can't find any workflow for %s", self.id)
+        return None
+
     def possible_transitions(self):
         """generates transition that MAY be fired for the given entity,
         expected to be in this state