[wf] new iter_worfklows method on workflow 3.5
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 25 Aug 2009 12:33:30 +0200
branch3.5
changeset 2976 d01417c14f35
parent 2975 fed52d317ba7
child 2977 6dd4f4a3ff2a
[wf] new iter_worfklows method on workflow
entities/wfobjs.py
--- a/entities/wfobjs.py	Tue Aug 25 12:32:44 2009 +0200
+++ b/entities/wfobjs.py	Tue Aug 25 12:33:30 2009 +0200
@@ -40,6 +40,23 @@
             return self.workflow_of[0].rest_path(), {'vid': 'workflow'}
         return super(Workflow, self).after_deletion_path()
 
+    def iter_workflows(self, _done=None):
+        """return an iterator on actual workflows, eg this workflow and its
+        subworkflows
+        """
+        # infinite loop safety belt
+        if _done is None:
+            _done = set()
+        yield self
+        _done.add(self.eid)
+        for tr in self.req.execute('Any T WHERE T is WorkflowTransition, '
+                                   'T transition_of WF, WF eid %(wf)s',
+                                   {'wf': self.eid}).entities():
+            if tr.subwf.eid in _done:
+                continue
+            for subwf in tr.subwf.iter_workflows(_done):
+                yield subwf
+
     # state / transitions accessors ############################################
 
     def state_by_name(self, statename):