author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 20 Apr 2010 09:58:28 +0200 | |
changeset 5334 | 7da1a6ca8f65 |
parent 5224 | 34e669b6fd95 |
child 5423 | e15abfdcce38 |
permissions | -rw-r--r-- |
0 | 1 |
"""workflow definition and history related entities |
2 |
||
3 |
:organization: Logilab |
|
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4002
diff
changeset
|
4 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1572
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 7 |
""" |
8 |
__docformat__ = "restructuredtext en" |
|
9 |
||
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
10 |
from warnings import warn |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
11 |
|
2948
d3cd8bd20ee5
override clear_all_caches to clear cwetype_workflow cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2947
diff
changeset
|
12 |
from logilab.common.decorators import cached, clear_cache |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
13 |
from logilab.common.deprecation import deprecated |
3757 | 14 |
from logilab.common.compat import any |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
15 |
|
0 | 16 |
from cubicweb.entities import AnyEntity, fetch_config |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
17 |
from cubicweb.interfaces import IWorkflowable |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4012
diff
changeset
|
18 |
from cubicweb.mixins import MI_REL_TRIGGERS |
0 | 19 |
|
2988
89d97d7c0508
[wf] use custom exception class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2987
diff
changeset
|
20 |
class WorkflowException(Exception): pass |
1572 | 21 |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
22 |
class Workflow(AnyEntity): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3038
diff
changeset
|
23 |
__regid__ = 'Workflow' |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
24 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
25 |
@property |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
26 |
def initial(self): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
27 |
"""return the initial state for this workflow""" |
2944
3bd49b70f7f9
[wf] return None, not empty list
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2943
diff
changeset
|
28 |
return self.initial_state and self.initial_state[0] or None |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
29 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
30 |
def is_default_workflow_of(self, etype): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
31 |
"""return True if this workflow is the default workflow for the given |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
32 |
entity type |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
33 |
""" |
2943
77622caef9bd
[schema] default_workflow_of more naturally expressed as default_workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
34 |
return any(et for et in self.reverse_default_workflow |
77622caef9bd
[schema] default_workflow_of more naturally expressed as default_workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
35 |
if et.name == etype) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
36 |
|
3982
ac2a54a6f36f
implements 'parent' method on workflow entity types
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3959
diff
changeset
|
37 |
# XXX define parent() instead? what if workflow of multiple types? |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
38 |
def after_deletion_path(self): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
39 |
"""return (path, parameters) which should be used as redirect |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
40 |
information when this entity is being deleted |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
41 |
""" |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
42 |
if self.workflow_of: |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
43 |
return self.workflow_of[0].rest_path(), {'vid': 'workflow'} |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
44 |
return super(Workflow, self).after_deletion_path() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
45 |
|
2976
d01417c14f35
[wf] new iter_worfklows method on workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2975
diff
changeset
|
46 |
def iter_workflows(self, _done=None): |
d01417c14f35
[wf] new iter_worfklows method on workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2975
diff
changeset
|
47 |
"""return an iterator on actual workflows, eg this workflow and its |
d01417c14f35
[wf] new iter_worfklows method on workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2975
diff
changeset
|
48 |
subworkflows |
d01417c14f35
[wf] new iter_worfklows method on workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2975
diff
changeset
|
49 |
""" |
d01417c14f35
[wf] new iter_worfklows method on workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2975
diff
changeset
|
50 |
# infinite loop safety belt |
d01417c14f35
[wf] new iter_worfklows method on workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2975
diff
changeset
|
51 |
if _done is None: |
d01417c14f35
[wf] new iter_worfklows method on workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2975
diff
changeset
|
52 |
_done = set() |
d01417c14f35
[wf] new iter_worfklows method on workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2975
diff
changeset
|
53 |
yield self |
d01417c14f35
[wf] new iter_worfklows method on workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2975
diff
changeset
|
54 |
_done.add(self.eid) |
3406
e343f37f7013
use self._cw instead of self.req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3405
diff
changeset
|
55 |
for tr in self._cw.execute('Any T WHERE T is WorkflowTransition, ' |
2976
d01417c14f35
[wf] new iter_worfklows method on workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2975
diff
changeset
|
56 |
'T transition_of WF, WF eid %(wf)s', |
d01417c14f35
[wf] new iter_worfklows method on workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2975
diff
changeset
|
57 |
{'wf': self.eid}).entities(): |
d01417c14f35
[wf] new iter_worfklows method on workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2975
diff
changeset
|
58 |
if tr.subwf.eid in _done: |
d01417c14f35
[wf] new iter_worfklows method on workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2975
diff
changeset
|
59 |
continue |
d01417c14f35
[wf] new iter_worfklows method on workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2975
diff
changeset
|
60 |
for subwf in tr.subwf.iter_workflows(_done): |
d01417c14f35
[wf] new iter_worfklows method on workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2975
diff
changeset
|
61 |
yield subwf |
d01417c14f35
[wf] new iter_worfklows method on workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2975
diff
changeset
|
62 |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
63 |
# state / transitions accessors ############################################ |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
64 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
65 |
def state_by_name(self, statename): |
3406
e343f37f7013
use self._cw instead of self.req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3405
diff
changeset
|
66 |
rset = self._cw.execute('Any S, SN WHERE S name SN, S name %(n)s, ' |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
67 |
'S state_of WF, WF eid %(wf)s', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
68 |
{'n': statename, 'wf': self.eid}) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
69 |
if rset: |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
70 |
return rset.get_entity(0, 0) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
71 |
return None |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
72 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
73 |
def state_by_eid(self, eid): |
3406
e343f37f7013
use self._cw instead of self.req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3405
diff
changeset
|
74 |
rset = self._cw.execute('Any S, SN WHERE S name SN, S eid %(s)s, ' |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
75 |
'S state_of WF, WF eid %(wf)s', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
76 |
{'s': eid, 'wf': self.eid}) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
77 |
if rset: |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
78 |
return rset.get_entity(0, 0) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
79 |
return None |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
80 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
81 |
def transition_by_name(self, trname): |
3406
e343f37f7013
use self._cw instead of self.req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3405
diff
changeset
|
82 |
rset = self._cw.execute('Any T, TN WHERE T name TN, T name %(n)s, ' |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
83 |
'T transition_of WF, WF eid %(wf)s', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
84 |
{'n': trname, 'wf': self.eid}) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
85 |
if rset: |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
86 |
return rset.get_entity(0, 0) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
87 |
return None |
0 | 88 |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
89 |
def transition_by_eid(self, eid): |
3406
e343f37f7013
use self._cw instead of self.req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3405
diff
changeset
|
90 |
rset = self._cw.execute('Any T, TN WHERE T name TN, T eid %(t)s, ' |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
91 |
'T transition_of WF, WF eid %(wf)s', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
92 |
{'t': eid, 'wf': self.eid}) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
93 |
if rset: |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
94 |
return rset.get_entity(0, 0) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
95 |
return None |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
96 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
97 |
# wf construction methods ################################################## |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
98 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
99 |
def add_state(self, name, initial=False, **kwargs): |
2986
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
100 |
"""add a state to this workflow""" |
3406
e343f37f7013
use self._cw instead of self.req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3405
diff
changeset
|
101 |
state = self._cw.create_entity('State', name=unicode(name), **kwargs) |
e343f37f7013
use self._cw instead of self.req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3405
diff
changeset
|
102 |
self._cw.execute('SET S state_of WF WHERE S eid %(s)s, WF eid %(wf)s', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
103 |
{'s': state.eid, 'wf': self.eid}) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
104 |
if initial: |
3959
e6ecaf93c0ba
improve error message for redundant initial workflow states
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
3765
diff
changeset
|
105 |
assert not self.initial, "Initial state already defined as %s" % self.initial |
3406
e343f37f7013
use self._cw instead of self.req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3405
diff
changeset
|
106 |
self._cw.execute('SET WF initial_state S ' |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
107 |
'WHERE S eid %(s)s, WF eid %(wf)s', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
108 |
{'s': state.eid, 'wf': self.eid}) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
109 |
return state |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
110 |
|
2986
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
111 |
def _add_transition(self, trtype, name, fromstates, |
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
112 |
requiredgroups=(), conditions=(), **kwargs): |
3406
e343f37f7013
use self._cw instead of self.req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3405
diff
changeset
|
113 |
tr = self._cw.create_entity(trtype, name=unicode(name), **kwargs) |
e343f37f7013
use self._cw instead of self.req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3405
diff
changeset
|
114 |
self._cw.execute('SET T transition_of WF ' |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
115 |
'WHERE T eid %(t)s, WF eid %(wf)s', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
116 |
{'t': tr.eid, 'wf': self.eid}) |
2987
5082dec70ed8
[wf] ensure fromstates given, allow to give an entity (avoid spotless error, we can iter on entities...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2986
diff
changeset
|
117 |
assert fromstates, fromstates |
5082dec70ed8
[wf] ensure fromstates given, allow to give an entity (avoid spotless error, we can iter on entities...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2986
diff
changeset
|
118 |
if not isinstance(fromstates, (tuple, list)): |
5082dec70ed8
[wf] ensure fromstates given, allow to give an entity (avoid spotless error, we can iter on entities...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2986
diff
changeset
|
119 |
fromstates = (fromstates,) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
120 |
for state in fromstates: |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
121 |
if hasattr(state, 'eid'): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
122 |
state = state.eid |
3406
e343f37f7013
use self._cw instead of self.req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3405
diff
changeset
|
123 |
self._cw.execute('SET S allowed_transition T ' |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
124 |
'WHERE S eid %(s)s, T eid %(t)s', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
125 |
{'s': state, 't': tr.eid}) |
4645
fd4e32f17211
deprecate Transition.set_transition_permissions in favor of set_permissions (after all we know we're on a transition entity)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4644
diff
changeset
|
126 |
tr.set_permissions(requiredgroups, conditions, reset=False) |
2986
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
127 |
return tr |
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
128 |
|
3628
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
129 |
def add_transition(self, name, fromstates, tostate=None, |
2986
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
130 |
requiredgroups=(), conditions=(), **kwargs): |
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
131 |
"""add a transition to this workflow from some state(s) to another""" |
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
132 |
tr = self._add_transition('Transition', name, fromstates, |
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
133 |
requiredgroups, conditions, **kwargs) |
3628
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
134 |
if tostate is not None: |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
135 |
if hasattr(tostate, 'eid'): |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
136 |
tostate = tostate.eid |
3629 | 137 |
self._cw.execute('SET T destination_state S ' |
3628
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
138 |
'WHERE S eid %(s)s, T eid %(t)s', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
139 |
{'t': tr.eid, 's': tostate}) |
2986
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
140 |
return tr |
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
141 |
|
3628
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
142 |
def add_wftransition(self, name, subworkflow, fromstates, exitpoints=(), |
3582
28547f21308e
two bits of docstring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3542
diff
changeset
|
143 |
requiredgroups=(), conditions=(), **kwargs): |
2986
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
144 |
"""add a workflow transition to this workflow""" |
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
145 |
tr = self._add_transition('WorkflowTransition', name, fromstates, |
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
146 |
requiredgroups, conditions, **kwargs) |
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
147 |
if hasattr(subworkflow, 'eid'): |
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
148 |
subworkflow = subworkflow.eid |
4024
6a14cff373c3
more api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
149 |
assert self._cw.execute('SET T subworkflow WF WHERE WF eid %(wf)s,T eid %(t)s', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
150 |
{'t': tr.eid, 'wf': subworkflow}) |
2986
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
151 |
for fromstate, tostate in exitpoints: |
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
152 |
tr.add_exit_point(fromstate, tostate) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
153 |
return tr |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
154 |
|
3999
5dd6ffc2ccae
added replace_state method to ease workflow migration. backported from forge as a reminder, not really tested yet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3986
diff
changeset
|
155 |
def replace_state(self, todelstate, replacement): |
5dd6ffc2ccae
added replace_state method to ease workflow migration. backported from forge as a reminder, not really tested yet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3986
diff
changeset
|
156 |
"""migration convenience method""" |
5dd6ffc2ccae
added replace_state method to ease workflow migration. backported from forge as a reminder, not really tested yet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3986
diff
changeset
|
157 |
if not hasattr(todelstate, 'eid'): |
5dd6ffc2ccae
added replace_state method to ease workflow migration. backported from forge as a reminder, not really tested yet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3986
diff
changeset
|
158 |
todelstate = self.state_by_name(todelstate) |
5dd6ffc2ccae
added replace_state method to ease workflow migration. backported from forge as a reminder, not really tested yet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3986
diff
changeset
|
159 |
if not hasattr(replacement, 'eid'): |
5dd6ffc2ccae
added replace_state method to ease workflow migration. backported from forge as a reminder, not really tested yet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3986
diff
changeset
|
160 |
replacement = self.state_by_name(replacement) |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4716
diff
changeset
|
161 |
execute = self._cw.execute |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
162 |
execute('SET X in_state S WHERE S eid %(s)s', {'s': todelstate.eid}) |
3999
5dd6ffc2ccae
added replace_state method to ease workflow migration. backported from forge as a reminder, not really tested yet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3986
diff
changeset
|
163 |
execute('SET X from_state NS WHERE X to_state OS, OS eid %(os)s, NS eid %(ns)s', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
164 |
{'os': todelstate.eid, 'ns': replacement.eid}) |
3999
5dd6ffc2ccae
added replace_state method to ease workflow migration. backported from forge as a reminder, not really tested yet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3986
diff
changeset
|
165 |
execute('SET X to_state NS WHERE X to_state OS, OS eid %(os)s, NS eid %(ns)s', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
166 |
{'os': todelstate.eid, 'ns': replacement.eid}) |
4002
4edff8bce44b
should delete state once replacement has been done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3999
diff
changeset
|
167 |
todelstate.delete() |
3999
5dd6ffc2ccae
added replace_state method to ease workflow migration. backported from forge as a reminder, not really tested yet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3986
diff
changeset
|
168 |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
169 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
170 |
class BaseTransition(AnyEntity): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
171 |
"""customized class for abstract transition |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
172 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
173 |
provides a specific may_be_fired method to check if the relation may be |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
174 |
fired by the logged user |
0 | 175 |
""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3038
diff
changeset
|
176 |
__regid__ = 'BaseTransition' |
5224
34e669b6fd95
[mq]: worklfow view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
177 |
fetch_attrs, fetch_order = fetch_config(['name', 'type']) |
1572 | 178 |
|
2951
d0b77dd27740
[wf] BaseTransition is a virtual type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2948
diff
changeset
|
179 |
def __init__(self, *args, **kwargs): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3038
diff
changeset
|
180 |
if self.__regid__ == 'BaseTransition': |
2988
89d97d7c0508
[wf] use custom exception class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2987
diff
changeset
|
181 |
raise WorkflowException('should not be instantiated') |
2954
48507919b6e3
[wf] oops, BaseTransition.__init__ may be called for subclasses
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2951
diff
changeset
|
182 |
super(BaseTransition, self).__init__(*args, **kwargs) |
2951
d0b77dd27740
[wf] BaseTransition is a virtual type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2948
diff
changeset
|
183 |
|
2975
fed52d317ba7
[wf] new .workflow property on states and transitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2954
diff
changeset
|
184 |
@property |
fed52d317ba7
[wf] new .workflow property on states and transitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2954
diff
changeset
|
185 |
def workflow(self): |
fed52d317ba7
[wf] new .workflow property on states and transitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2954
diff
changeset
|
186 |
return self.transition_of[0] |
fed52d317ba7
[wf] new .workflow property on states and transitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2954
diff
changeset
|
187 |
|
2991 | 188 |
def has_input_state(self, state): |
189 |
if hasattr(state, 'eid'): |
|
190 |
state = state.eid |
|
191 |
return any(s for s in self.reverse_allowed_transition if s.eid == state) |
|
192 |
||
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
193 |
def may_be_fired(self, eid): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
194 |
"""return true if the logged user may fire this transition |
0 | 195 |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
196 |
`eid` is the eid of the object on which we may fire the transition |
0 | 197 |
""" |
3406
e343f37f7013
use self._cw instead of self.req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3405
diff
changeset
|
198 |
user = self._cw.user |
0 | 199 |
# check user is at least in one of the required groups if any |
200 |
groups = frozenset(g.name for g in self.require_group) |
|
201 |
if groups: |
|
202 |
matches = user.matching_groups(groups) |
|
203 |
if matches: |
|
204 |
return matches |
|
205 |
if 'owners' in groups and user.owns(eid): |
|
206 |
return True |
|
207 |
# check one of the rql expression conditions matches if any |
|
208 |
if self.condition: |
|
209 |
for rqlexpr in self.condition: |
|
3406
e343f37f7013
use self._cw instead of self.req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3405
diff
changeset
|
210 |
if rqlexpr.check_expression(self._cw, eid): |
0 | 211 |
return True |
212 |
if self.condition or groups: |
|
213 |
return False |
|
214 |
return True |
|
215 |
||
216 |
def after_deletion_path(self): |
|
217 |
"""return (path, parameters) which should be used as redirect |
|
218 |
information when this entity is being deleted |
|
219 |
""" |
|
220 |
if self.transition_of: |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
221 |
return self.transition_of[0].rest_path(), {} |
4716
55b6a3262071
fix some pylint detected errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4647
diff
changeset
|
222 |
return super(BaseTransition, self).after_deletion_path() |
0 | 223 |
|
4645
fd4e32f17211
deprecate Transition.set_transition_permissions in favor of set_permissions (after all we know we're on a transition entity)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4644
diff
changeset
|
224 |
def set_permissions(self, requiredgroups=(), conditions=(), reset=True): |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
225 |
"""set or add (if `reset` is False) groups and conditions for this |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
226 |
transition |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
227 |
""" |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
228 |
if reset: |
3406
e343f37f7013
use self._cw instead of self.req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3405
diff
changeset
|
229 |
self._cw.execute('DELETE T require_group G WHERE T eid %(x)s', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
230 |
{'x': self.eid}) |
3406
e343f37f7013
use self._cw instead of self.req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3405
diff
changeset
|
231 |
self._cw.execute('DELETE T condition R WHERE T eid %(x)s', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
232 |
{'x': self.eid}) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
233 |
for gname in requiredgroups: |
3406
e343f37f7013
use self._cw instead of self.req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3405
diff
changeset
|
234 |
rset = self._cw.execute('SET T require_group G ' |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
235 |
'WHERE T eid %(x)s, G name %(gn)s', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
236 |
{'x': self.eid, 'gn': gname}) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
237 |
assert rset, '%s is not a known group' % gname |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
238 |
if isinstance(conditions, basestring): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
239 |
conditions = (conditions,) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
240 |
for expr in conditions: |
3542 | 241 |
if isinstance(expr, basestring): |
3528
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3038
diff
changeset
|
242 |
kwargs = {'expr': unicode(expr)} |
3542 | 243 |
else: |
244 |
assert isinstance(expr, dict) |
|
3528
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3038
diff
changeset
|
245 |
kwargs = expr |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3038
diff
changeset
|
246 |
kwargs['x'] = self.eid |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3038
diff
changeset
|
247 |
kwargs.setdefault('mainvars', u'X') |
3406
e343f37f7013
use self._cw instead of self.req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3405
diff
changeset
|
248 |
self._cw.execute('INSERT RQLExpression X: X exprtype "ERQLExpression", ' |
3528
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3038
diff
changeset
|
249 |
'X expression %(expr)s, X mainvars %(mainvars)s, ' |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
250 |
'T condition X WHERE T eid %(x)s', kwargs) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
251 |
# XXX clear caches? |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
252 |
|
4645
fd4e32f17211
deprecate Transition.set_transition_permissions in favor of set_permissions (after all we know we're on a transition entity)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4644
diff
changeset
|
253 |
@deprecated('[3.6.1] use set_permission') |
fd4e32f17211
deprecate Transition.set_transition_permissions in favor of set_permissions (after all we know we're on a transition entity)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4644
diff
changeset
|
254 |
def set_transition_permissions(self, requiredgroups=(), conditions=(), |
fd4e32f17211
deprecate Transition.set_transition_permissions in favor of set_permissions (after all we know we're on a transition entity)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4644
diff
changeset
|
255 |
reset=True): |
fd4e32f17211
deprecate Transition.set_transition_permissions in favor of set_permissions (after all we know we're on a transition entity)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4644
diff
changeset
|
256 |
return self.set_permissions(requiredgroups, conditions, reset) |
fd4e32f17211
deprecate Transition.set_transition_permissions in favor of set_permissions (after all we know we're on a transition entity)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4644
diff
changeset
|
257 |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
258 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
259 |
class Transition(BaseTransition): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
260 |
"""customized class for Transition entities""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3038
diff
changeset
|
261 |
__regid__ = 'Transition' |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
262 |
|
4644
021035b9a7ab
introduce 'go back' transition: transition without destination state will go to the state we were coming from
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4436
diff
changeset
|
263 |
def destination(self, entity): |
021035b9a7ab
introduce 'go back' transition: transition without destination state will go to the state we were coming from
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4436
diff
changeset
|
264 |
try: |
021035b9a7ab
introduce 'go back' transition: transition without destination state will go to the state we were coming from
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4436
diff
changeset
|
265 |
return self.destination_state[0] |
021035b9a7ab
introduce 'go back' transition: transition without destination state will go to the state we were coming from
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4436
diff
changeset
|
266 |
except IndexError: |
021035b9a7ab
introduce 'go back' transition: transition without destination state will go to the state we were coming from
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4436
diff
changeset
|
267 |
return entity.latest_trinfo().previous_state |
021035b9a7ab
introduce 'go back' transition: transition without destination state will go to the state we were coming from
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4436
diff
changeset
|
268 |
|
4646
322c3dd96dd5
[workflow] finish refactoring introduced by 021035b9a7ab for 'go back' transition:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4645
diff
changeset
|
269 |
def potential_destinations(self): |
322c3dd96dd5
[workflow] finish refactoring introduced by 021035b9a7ab for 'go back' transition:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4645
diff
changeset
|
270 |
try: |
322c3dd96dd5
[workflow] finish refactoring introduced by 021035b9a7ab for 'go back' transition:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4645
diff
changeset
|
271 |
yield self.destination_state[0] |
322c3dd96dd5
[workflow] finish refactoring introduced by 021035b9a7ab for 'go back' transition:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4645
diff
changeset
|
272 |
except IndexError: |
4647
6d7589b4ae6f
[workflow] fix potential destination for go back transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4646
diff
changeset
|
273 |
for incomingstate in self.reverse_allowed_transition: |
6d7589b4ae6f
[workflow] fix potential destination for go back transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4646
diff
changeset
|
274 |
for tr in incomingstate.reverse_destination_state: |
6d7589b4ae6f
[workflow] fix potential destination for go back transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4646
diff
changeset
|
275 |
for previousstate in tr.reverse_allowed_transition: |
6d7589b4ae6f
[workflow] fix potential destination for go back transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4646
diff
changeset
|
276 |
yield previousstate |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
277 |
|
3982
ac2a54a6f36f
implements 'parent' method on workflow entity types
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3959
diff
changeset
|
278 |
def parent(self): |
ac2a54a6f36f
implements 'parent' method on workflow entity types
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3959
diff
changeset
|
279 |
return self.workflow |
ac2a54a6f36f
implements 'parent' method on workflow entity types
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3959
diff
changeset
|
280 |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
281 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
282 |
class WorkflowTransition(BaseTransition): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
283 |
"""customized class for WorkflowTransition entities""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3038
diff
changeset
|
284 |
__regid__ = 'WorkflowTransition' |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
285 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
286 |
@property |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
287 |
def subwf(self): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
288 |
return self.subworkflow[0] |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
289 |
|
4646
322c3dd96dd5
[workflow] finish refactoring introduced by 021035b9a7ab for 'go back' transition:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4645
diff
changeset
|
290 |
def destination(self, entity): |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
291 |
return self.subwf.initial |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
292 |
|
4646
322c3dd96dd5
[workflow] finish refactoring introduced by 021035b9a7ab for 'go back' transition:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4645
diff
changeset
|
293 |
def potential_destinations(self): |
322c3dd96dd5
[workflow] finish refactoring introduced by 021035b9a7ab for 'go back' transition:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4645
diff
changeset
|
294 |
yield self.subwf.initial |
322c3dd96dd5
[workflow] finish refactoring introduced by 021035b9a7ab for 'go back' transition:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4645
diff
changeset
|
295 |
|
2986
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
296 |
def add_exit_point(self, fromstate, tostate): |
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
297 |
if hasattr(fromstate, 'eid'): |
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
298 |
fromstate = fromstate.eid |
3628
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
299 |
if tostate is None: |
3629 | 300 |
self._cw.execute('INSERT SubWorkflowExitPoint X: T subworkflow_exit X, ' |
3628
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
301 |
'X subworkflow_state FS WHERE T eid %(t)s, FS eid %(fs)s', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
302 |
{'t': self.eid, 'fs': fromstate}) |
3628
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
303 |
else: |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
304 |
if hasattr(tostate, 'eid'): |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
305 |
tostate = tostate.eid |
3629 | 306 |
self._cw.execute('INSERT SubWorkflowExitPoint X: T subworkflow_exit X, ' |
3628
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
307 |
'X subworkflow_state FS, X destination_state TS ' |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
308 |
'WHERE T eid %(t)s, FS eid %(fs)s, TS eid %(ts)s', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
309 |
{'t': self.eid, 'fs': fromstate, 'ts': tostate}) |
2986
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
310 |
|
3628
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
311 |
def get_exit_point(self, entity, stateeid): |
2986
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
312 |
"""if state is an exit point, return its associated destination state""" |
3628
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
313 |
if hasattr(stateeid, 'eid'): |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
314 |
stateeid = stateeid.eid |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
315 |
try: |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
316 |
tostateeid = self.exit_points()[stateeid] |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
317 |
except KeyError: |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
318 |
return None |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
319 |
if tostateeid is None: |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
320 |
# go back to state from which we've entered the subworkflow |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
321 |
return entity.subworkflow_input_trinfo().previous_state |
3629 | 322 |
return self._cw.entity_from_eid(tostateeid) |
2986
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
323 |
|
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
324 |
@cached |
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
325 |
def exit_points(self): |
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
326 |
result = {} |
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
327 |
for ep in self.subworkflow_exit: |
3628
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
328 |
result[ep.subwf_state.eid] = ep.destination and ep.destination.eid |
2986
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
329 |
return result |
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
330 |
|
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
331 |
def clear_all_caches(self): |
4716
55b6a3262071
fix some pylint detected errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4647
diff
changeset
|
332 |
super(WorkflowTransition, self).clear_all_caches() |
2986
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
333 |
clear_cache(self, 'exit_points') |
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
334 |
|
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
335 |
|
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
336 |
class SubWorkflowExitPoint(AnyEntity): |
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
337 |
"""customized class for SubWorkflowExitPoint entities""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3038
diff
changeset
|
338 |
__regid__ = 'SubWorkflowExitPoint' |
2986
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
339 |
|
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
340 |
@property |
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
341 |
def subwf_state(self): |
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
342 |
return self.subworkflow_state[0] |
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
343 |
|
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
344 |
@property |
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
345 |
def destination(self): |
3628
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
346 |
return self.destination_state and self.destination_state[0] or None |
2986
d8f2e53702be
[wf] new methods to build wf w/ workflow transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2980
diff
changeset
|
347 |
|
3982
ac2a54a6f36f
implements 'parent' method on workflow entity types
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3959
diff
changeset
|
348 |
def parent(self): |
ac2a54a6f36f
implements 'parent' method on workflow entity types
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3959
diff
changeset
|
349 |
return self.reverse_subworkflow_exit[0] |
ac2a54a6f36f
implements 'parent' method on workflow entity types
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3959
diff
changeset
|
350 |
|
1572 | 351 |
|
0 | 352 |
class State(AnyEntity): |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
353 |
"""customized class for State entities""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3038
diff
changeset
|
354 |
__regid__ = 'State' |
0 | 355 |
fetch_attrs, fetch_order = fetch_config(['name']) |
356 |
rest_attr = 'eid' |
|
1572 | 357 |
|
2975
fed52d317ba7
[wf] new .workflow property on states and transitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2954
diff
changeset
|
358 |
@property |
fed52d317ba7
[wf] new .workflow property on states and transitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2954
diff
changeset
|
359 |
def workflow(self): |
3038
1261c3df0e5a
[multi-sources] in ms config we don't have state_of (and probably others, but that's the one used until now...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2991
diff
changeset
|
360 |
# take care, may be missing in multi-sources configuration |
1261c3df0e5a
[multi-sources] in ms config we don't have state_of (and probably others, but that's the one used until now...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2991
diff
changeset
|
361 |
return self.state_of and self.state_of[0] |
2975
fed52d317ba7
[wf] new .workflow property on states and transitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2954
diff
changeset
|
362 |
|
3982
ac2a54a6f36f
implements 'parent' method on workflow entity types
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3959
diff
changeset
|
363 |
def parent(self): |
ac2a54a6f36f
implements 'parent' method on workflow entity types
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3959
diff
changeset
|
364 |
return self.workflow |
0 | 365 |
|
1572 | 366 |
|
0 | 367 |
class TrInfo(AnyEntity): |
368 |
"""customized class for Transition information entities |
|
369 |
""" |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3038
diff
changeset
|
370 |
__regid__ = 'TrInfo' |
0 | 371 |
fetch_attrs, fetch_order = fetch_config(['creation_date', 'comment'], |
372 |
pclass=None) # don't want modification_date |
|
373 |
@property |
|
374 |
def for_entity(self): |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
375 |
return self.wf_info_for[0] |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
376 |
|
0 | 377 |
@property |
378 |
def previous_state(self): |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
379 |
return self.from_state[0] |
1572 | 380 |
|
0 | 381 |
@property |
382 |
def new_state(self): |
|
383 |
return self.to_state[0] |
|
384 |
||
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
385 |
@property |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
386 |
def transition(self): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
387 |
return self.by_transition and self.by_transition[0] or None |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
388 |
|
3982
ac2a54a6f36f
implements 'parent' method on workflow entity types
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3959
diff
changeset
|
389 |
def parent(self): |
ac2a54a6f36f
implements 'parent' method on workflow entity types
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3959
diff
changeset
|
390 |
return self.for_entity |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
391 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
392 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
393 |
class WorkflowableMixIn(object): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
394 |
"""base mixin providing workflow helper methods for workflowable entities. |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
395 |
This mixin will be automatically set on class supporting the 'in_state' |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
396 |
relation (which implies supporting 'wf_info_for' as well) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
397 |
""" |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
398 |
__implements__ = (IWorkflowable,) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
399 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
400 |
@property |
2978
d8c5ad14ab8e
[wf]Â distinguish main workflow / current workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2976
diff
changeset
|
401 |
def main_workflow(self): |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
402 |
"""return current workflow applied to this entity""" |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
403 |
if self.custom_workflow: |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
404 |
return self.custom_workflow[0] |
2946
957fd4b276e2
[wf] refactor current_workflow by extracting cwetype_workflow method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2945
diff
changeset
|
405 |
return self.cwetype_workflow() |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
406 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
407 |
@property |
2978
d8c5ad14ab8e
[wf]Â distinguish main workflow / current workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2976
diff
changeset
|
408 |
def current_workflow(self): |
d8c5ad14ab8e
[wf]Â distinguish main workflow / current workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2976
diff
changeset
|
409 |
"""return current workflow applied to this entity""" |
2991 | 410 |
return self.current_state and self.current_state.workflow or self.main_workflow |
2978
d8c5ad14ab8e
[wf]Â distinguish main workflow / current workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2976
diff
changeset
|
411 |
|
d8c5ad14ab8e
[wf]Â distinguish main workflow / current workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2976
diff
changeset
|
412 |
@property |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
413 |
def current_state(self): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
414 |
"""return current state entity""" |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
415 |
return self.in_state and self.in_state[0] or None |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
416 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
417 |
@property |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
418 |
def state(self): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
419 |
"""return current state name""" |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
420 |
try: |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
421 |
return self.in_state[0].name |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
422 |
except IndexError: |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
423 |
self.warning('entity %s has no state', self) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
424 |
return None |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
425 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
426 |
@property |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
427 |
def printable_state(self): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
428 |
"""return current state name translated to context's language""" |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
429 |
state = self.current_state |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
430 |
if state: |
3406
e343f37f7013
use self._cw instead of self.req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3405
diff
changeset
|
431 |
return self._cw._(state.name) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
432 |
return u'' |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
433 |
|
2947
083593802120
[wf] new workflow_history property, nicer the reverse_wf_info_for...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2946
diff
changeset
|
434 |
@property |
083593802120
[wf] new workflow_history property, nicer the reverse_wf_info_for...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2946
diff
changeset
|
435 |
def workflow_history(self): |
083593802120
[wf] new workflow_history property, nicer the reverse_wf_info_for...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2946
diff
changeset
|
436 |
"""return the workflow history for this entity (eg ordered list of |
083593802120
[wf] new workflow_history property, nicer the reverse_wf_info_for...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2946
diff
changeset
|
437 |
TrInfo entities) |
083593802120
[wf] new workflow_history property, nicer the reverse_wf_info_for...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2946
diff
changeset
|
438 |
""" |
083593802120
[wf] new workflow_history property, nicer the reverse_wf_info_for...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2946
diff
changeset
|
439 |
return self.reverse_wf_info_for |
083593802120
[wf] new workflow_history property, nicer the reverse_wf_info_for...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2946
diff
changeset
|
440 |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
441 |
def latest_trinfo(self): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
442 |
"""return the latest transition information for this entity""" |
3765
769dc0107f31
latst_trinfo : do not crash on absent wf history
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3757
diff
changeset
|
443 |
try: |
769dc0107f31
latst_trinfo : do not crash on absent wf history
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3757
diff
changeset
|
444 |
return self.reverse_wf_info_for[-1] |
769dc0107f31
latst_trinfo : do not crash on absent wf history
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3757
diff
changeset
|
445 |
except IndexError: |
769dc0107f31
latst_trinfo : do not crash on absent wf history
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3757
diff
changeset
|
446 |
return None |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
447 |
|
2946
957fd4b276e2
[wf] refactor current_workflow by extracting cwetype_workflow method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2945
diff
changeset
|
448 |
@cached |
957fd4b276e2
[wf] refactor current_workflow by extracting cwetype_workflow method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2945
diff
changeset
|
449 |
def cwetype_workflow(self): |
957fd4b276e2
[wf] refactor current_workflow by extracting cwetype_workflow method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2945
diff
changeset
|
450 |
"""return the default workflow for entities of this type""" |
957fd4b276e2
[wf] refactor current_workflow by extracting cwetype_workflow method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2945
diff
changeset
|
451 |
# XXX CWEType method |
3674 | 452 |
wfrset = self._cw.execute('Any WF WHERE ET default_workflow WF, ' |
3675 | 453 |
'ET name %(et)s', {'et': self.__regid__}) |
3663
c74d8ec4cdb2
simpler implementation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3628
diff
changeset
|
454 |
if wfrset: |
2946
957fd4b276e2
[wf] refactor current_workflow by extracting cwetype_workflow method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2945
diff
changeset
|
455 |
return wfrset.get_entity(0, 0) |
3675 | 456 |
self.warning("can't find any workflow for %s", self.__regid__) |
2946
957fd4b276e2
[wf] refactor current_workflow by extracting cwetype_workflow method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2945
diff
changeset
|
457 |
return None |
957fd4b276e2
[wf] refactor current_workflow by extracting cwetype_workflow method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2945
diff
changeset
|
458 |
|
3528
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3038
diff
changeset
|
459 |
def possible_transitions(self, type='normal'): |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
460 |
"""generates transition that MAY be fired for the given entity, |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
461 |
expected to be in this state |
3986
cc29eddf51ad
add postcommit_event on Operations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3982
diff
changeset
|
462 |
used only by the UI |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
463 |
""" |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
464 |
if self.current_state is None or self.current_workflow is None: |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
465 |
return |
3406
e343f37f7013
use self._cw instead of self.req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3405
diff
changeset
|
466 |
rset = self._cw.execute( |
3528
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3038
diff
changeset
|
467 |
'Any T,TT, TN WHERE S allowed_transition T, S eid %(x)s, ' |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3038
diff
changeset
|
468 |
'T type TT, T type %(type)s, ' |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3038
diff
changeset
|
469 |
'T name TN, T transition_of WF, WF eid %(wfeid)s', |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3038
diff
changeset
|
470 |
{'x': self.current_state.eid, 'type': type, |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
471 |
'wfeid': self.current_workflow.eid}) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
472 |
for tr in rset.entities(): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
473 |
if tr.may_be_fired(self.eid): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
474 |
yield tr |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
475 |
|
2989
dfb3506647e4
[wf] refactor change_state/fire_transition to share more code, change_state can also take an optional tr argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2988
diff
changeset
|
476 |
def _add_trinfo(self, comment, commentformat, treid=None, tseid=None): |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
477 |
kwargs = {} |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
478 |
if comment is not None: |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
479 |
kwargs['comment'] = comment |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
480 |
if commentformat is not None: |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
481 |
kwargs['comment_format'] = commentformat |
3687
859f7d741bfb
update for new create_entity implementation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3663
diff
changeset
|
482 |
kwargs['wf_info_for'] = self |
2989
dfb3506647e4
[wf] refactor change_state/fire_transition to share more code, change_state can also take an optional tr argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2988
diff
changeset
|
483 |
if treid is not None: |
4024
6a14cff373c3
more api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
484 |
kwargs['by_transition'] = self._cw.entity_from_eid(treid) |
2989
dfb3506647e4
[wf] refactor change_state/fire_transition to share more code, change_state can also take an optional tr argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2988
diff
changeset
|
485 |
if tseid is not None: |
4024
6a14cff373c3
more api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
486 |
kwargs['to_state'] = self._cw.entity_from_eid(tseid) |
3720 | 487 |
return self._cw.create_entity('TrInfo', **kwargs) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
488 |
|
3528
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3038
diff
changeset
|
489 |
def fire_transition(self, tr, comment=None, commentformat=None): |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
490 |
"""change the entity's state by firing transition of the given name in |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
491 |
entity's workflow |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
492 |
""" |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
493 |
assert self.current_workflow |
3528
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3038
diff
changeset
|
494 |
if isinstance(tr, basestring): |
3628
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
495 |
_tr = self.current_workflow.transition_by_name(tr) |
3629 | 496 |
assert _tr is not None, 'not a %s transition: %s' % ( |
497 |
self.__regid__, tr) |
|
3628
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
498 |
tr = _tr |
2989
dfb3506647e4
[wf] refactor change_state/fire_transition to share more code, change_state can also take an optional tr argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2988
diff
changeset
|
499 |
return self._add_trinfo(comment, commentformat, tr.eid) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
500 |
|
2989
dfb3506647e4
[wf] refactor change_state/fire_transition to share more code, change_state can also take an optional tr argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2988
diff
changeset
|
501 |
def change_state(self, statename, comment=None, commentformat=None, tr=None): |
2980
292387ed37f3
[wf] allow state entity as argument to change_state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2978
diff
changeset
|
502 |
"""change the entity's state to the given state (name or entity) in |
292387ed37f3
[wf] allow state entity as argument to change_state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2978
diff
changeset
|
503 |
entity's workflow. This method should only by used by manager to fix an |
292387ed37f3
[wf] allow state entity as argument to change_state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2978
diff
changeset
|
504 |
entity's state when their is no matching transition, otherwise |
292387ed37f3
[wf] allow state entity as argument to change_state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2978
diff
changeset
|
505 |
fire_transition should be used. |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
506 |
""" |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
507 |
assert self.current_workflow |
2980
292387ed37f3
[wf] allow state entity as argument to change_state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2978
diff
changeset
|
508 |
if hasattr(statename, 'eid'): |
292387ed37f3
[wf] allow state entity as argument to change_state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2978
diff
changeset
|
509 |
stateeid = statename.eid |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
510 |
else: |
2980
292387ed37f3
[wf] allow state entity as argument to change_state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2978
diff
changeset
|
511 |
if not isinstance(statename, basestring): |
4403
53f5d52085b4
add version number to deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
512 |
warn('[3.5] give a state name', DeprecationWarning) |
2980
292387ed37f3
[wf] allow state entity as argument to change_state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2978
diff
changeset
|
513 |
state = self.current_workflow.state_by_eid(statename) |
292387ed37f3
[wf] allow state entity as argument to change_state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2978
diff
changeset
|
514 |
else: |
292387ed37f3
[wf] allow state entity as argument to change_state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2978
diff
changeset
|
515 |
state = self.current_workflow.state_by_name(statename) |
292387ed37f3
[wf] allow state entity as argument to change_state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2978
diff
changeset
|
516 |
if state is None: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3406
diff
changeset
|
517 |
raise WorkflowException('not a %s state: %s' % (self.__regid__, |
2989
dfb3506647e4
[wf] refactor change_state/fire_transition to share more code, change_state can also take an optional tr argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2988
diff
changeset
|
518 |
statename)) |
2980
292387ed37f3
[wf] allow state entity as argument to change_state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2978
diff
changeset
|
519 |
stateeid = state.eid |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
520 |
# XXX try to find matching transition? |
2989
dfb3506647e4
[wf] refactor change_state/fire_transition to share more code, change_state can also take an optional tr argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2988
diff
changeset
|
521 |
return self._add_trinfo(comment, commentformat, tr and tr.eid, stateeid) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
522 |
|
3628
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
523 |
def subworkflow_input_trinfo(self): |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
524 |
"""return the TrInfo which has be recorded when this entity went into |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
525 |
the current sub-workflow |
2990
f221ba8552ab
[wf] new method on WorkflowableMixIn to get the transition which had led to the current sub-workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2989
diff
changeset
|
526 |
""" |
f221ba8552ab
[wf] new method on WorkflowableMixIn to get the transition which had led to the current sub-workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2989
diff
changeset
|
527 |
if self.main_workflow.eid == self.current_workflow.eid: |
f221ba8552ab
[wf] new method on WorkflowableMixIn to get the transition which had led to the current sub-workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2989
diff
changeset
|
528 |
return # doesn't make sense |
f221ba8552ab
[wf] new method on WorkflowableMixIn to get the transition which had led to the current sub-workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2989
diff
changeset
|
529 |
subwfentries = [] |
3621
1ec4452aa36f
[wf] fix detection of transition where we've entered a subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3609
diff
changeset
|
530 |
for trinfo in self.workflow_history: |
2990
f221ba8552ab
[wf] new method on WorkflowableMixIn to get the transition which had led to the current sub-workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2989
diff
changeset
|
531 |
if (trinfo.transition and |
f221ba8552ab
[wf] new method on WorkflowableMixIn to get the transition which had led to the current sub-workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2989
diff
changeset
|
532 |
trinfo.previous_state.workflow.eid != trinfo.new_state.workflow.eid): |
f221ba8552ab
[wf] new method on WorkflowableMixIn to get the transition which had led to the current sub-workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2989
diff
changeset
|
533 |
# entering or leaving a subworkflow |
f221ba8552ab
[wf] new method on WorkflowableMixIn to get the transition which had led to the current sub-workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2989
diff
changeset
|
534 |
if (subwfentries and |
3621
1ec4452aa36f
[wf] fix detection of transition where we've entered a subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3609
diff
changeset
|
535 |
subwfentries[-1].new_state.workflow.eid == trinfo.previous_state.workflow.eid and |
1ec4452aa36f
[wf] fix detection of transition where we've entered a subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3609
diff
changeset
|
536 |
subwfentries[-1].previous_state.workflow.eid == trinfo.new_state.workflow.eid): |
2990
f221ba8552ab
[wf] new method on WorkflowableMixIn to get the transition which had led to the current sub-workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2989
diff
changeset
|
537 |
# leave |
f221ba8552ab
[wf] new method on WorkflowableMixIn to get the transition which had led to the current sub-workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2989
diff
changeset
|
538 |
del subwfentries[-1] |
f221ba8552ab
[wf] new method on WorkflowableMixIn to get the transition which had led to the current sub-workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2989
diff
changeset
|
539 |
else: |
f221ba8552ab
[wf] new method on WorkflowableMixIn to get the transition which had led to the current sub-workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2989
diff
changeset
|
540 |
# enter |
f221ba8552ab
[wf] new method on WorkflowableMixIn to get the transition which had led to the current sub-workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2989
diff
changeset
|
541 |
subwfentries.append(trinfo) |
f221ba8552ab
[wf] new method on WorkflowableMixIn to get the transition which had led to the current sub-workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2989
diff
changeset
|
542 |
if not subwfentries: |
f221ba8552ab
[wf] new method on WorkflowableMixIn to get the transition which had led to the current sub-workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2989
diff
changeset
|
543 |
return None |
3628
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
544 |
return subwfentries[-1] |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
545 |
|
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
546 |
def subworkflow_input_transition(self): |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
547 |
"""return the transition which has went through the current sub-workflow |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
548 |
""" |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3621
diff
changeset
|
549 |
return getattr(self.subworkflow_input_trinfo(), 'transition', None) |
2948
d3cd8bd20ee5
override clear_all_caches to clear cwetype_workflow cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2947
diff
changeset
|
550 |
|
d3cd8bd20ee5
override clear_all_caches to clear cwetype_workflow cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2947
diff
changeset
|
551 |
def clear_all_caches(self): |
d3cd8bd20ee5
override clear_all_caches to clear cwetype_workflow cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2947
diff
changeset
|
552 |
super(WorkflowableMixIn, self).clear_all_caches() |
d3cd8bd20ee5
override clear_all_caches to clear cwetype_workflow cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2947
diff
changeset
|
553 |
clear_cache(self, 'cwetype_workflow') |
d3cd8bd20ee5
override clear_all_caches to clear cwetype_workflow cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2947
diff
changeset
|
554 |
|
3405
9d31c9cb8103
nicer deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3377
diff
changeset
|
555 |
@deprecated('[3.5] get transition from current workflow and use its may_be_fired method') |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
556 |
def can_pass_transition(self, trname): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
557 |
"""return the Transition instance if the current user can fire the |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
558 |
transition with the given name, else None |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
559 |
""" |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
560 |
tr = self.current_workflow and self.current_workflow.transition_by_name(trname) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
561 |
if tr and tr.may_be_fired(self.eid): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
562 |
return tr |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
563 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
564 |
@property |
3405
9d31c9cb8103
nicer deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3377
diff
changeset
|
565 |
@deprecated('[3.5] use printable_state') |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
566 |
def displayable_state(self): |
3406
e343f37f7013
use self._cw instead of self.req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3405
diff
changeset
|
567 |
return self._cw._(self.state) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
568 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2917
diff
changeset
|
569 |
MI_REL_TRIGGERS[('in_state', 'subject')] = WorkflowableMixIn |