equal
deleted
inserted
replaced
1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
3 # |
3 # |
4 # This file is part of CubicWeb. |
4 # This file is part of CubicWeb. |
5 # |
5 # |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
43 |
43 |
44 # operations ################################################################### |
44 # operations ################################################################### |
45 |
45 |
46 class _SetInitialStateOp(hook.Operation): |
46 class _SetInitialStateOp(hook.Operation): |
47 """make initial state be a default state""" |
47 """make initial state be a default state""" |
|
48 entity = None # make pylint happy |
48 |
49 |
49 def precommit_event(self): |
50 def precommit_event(self): |
50 session = self.session |
51 session = self.session |
51 entity = self.entity |
52 entity = self.entity |
52 iworkflowable = entity.cw_adapt_to('IWorkflowable') |
53 iworkflowable = entity.cw_adapt_to('IWorkflowable') |
59 session.add_relation(entity.eid, 'in_state', state.eid) |
60 session.add_relation(entity.eid, 'in_state', state.eid) |
60 _FireAutotransitionOp(session, entity=entity) |
61 _FireAutotransitionOp(session, entity=entity) |
61 |
62 |
62 class _FireAutotransitionOp(hook.Operation): |
63 class _FireAutotransitionOp(hook.Operation): |
63 """try to fire auto transition after state changes""" |
64 """try to fire auto transition after state changes""" |
|
65 entity = None # make pylint happy |
64 |
66 |
65 def precommit_event(self): |
67 def precommit_event(self): |
66 entity = self.entity |
68 entity = self.entity |
67 iworkflowable = entity.cw_adapt_to('IWorkflowable') |
69 iworkflowable = entity.cw_adapt_to('IWorkflowable') |
68 autotrs = list(iworkflowable.possible_transitions('auto')) |
70 autotrs = list(iworkflowable.possible_transitions('auto')) |
71 iworkflowable.fire_transition(autotrs[0]) |
73 iworkflowable.fire_transition(autotrs[0]) |
72 |
74 |
73 |
75 |
74 class _WorkflowChangedOp(hook.Operation): |
76 class _WorkflowChangedOp(hook.Operation): |
75 """fix entity current state when changing its workflow""" |
77 """fix entity current state when changing its workflow""" |
|
78 eid = wfeid = None # make pylint happy |
76 |
79 |
77 def precommit_event(self): |
80 def precommit_event(self): |
78 # notice that enforcement that new workflow apply to the entity's type is |
81 # notice that enforcement that new workflow apply to the entity's type is |
79 # done by schema rule, no need to check it here |
82 # done by schema rule, no need to check it here |
80 session = self.session |
83 session = self.session |
107 session.transaction_data[(entity.eid, 'customwf')] = self.wfeid |
110 session.transaction_data[(entity.eid, 'customwf')] = self.wfeid |
108 iworkflowable.change_state(deststate, msg, u'text/plain') |
111 iworkflowable.change_state(deststate, msg, u'text/plain') |
109 |
112 |
110 |
113 |
111 class _CheckTrExitPoint(hook.Operation): |
114 class _CheckTrExitPoint(hook.Operation): |
|
115 treid = None # make pylint happy |
112 |
116 |
113 def precommit_event(self): |
117 def precommit_event(self): |
114 tr = self.session.entity_from_eid(self.treid) |
118 tr = self.session.entity_from_eid(self.treid) |
115 outputs = set() |
119 outputs = set() |
116 for ep in tr.subworkflow_exit: |
120 for ep in tr.subworkflow_exit: |
120 raise ValidationError(self.treid, {qname: msg}) |
124 raise ValidationError(self.treid, {qname: msg}) |
121 outputs.add(ep.subwf_state.eid) |
125 outputs.add(ep.subwf_state.eid) |
122 |
126 |
123 |
127 |
124 class _SubWorkflowExitOp(hook.Operation): |
128 class _SubWorkflowExitOp(hook.Operation): |
|
129 forentity = trinfo = None # make pylint happy |
125 |
130 |
126 def precommit_event(self): |
131 def precommit_event(self): |
127 session = self.session |
132 session = self.session |
128 forentity = self.forentity |
133 forentity = self.forentity |
129 iworkflowable = forentity.cw_adapt_to('IWorkflowable') |
134 iworkflowable = forentity.cw_adapt_to('IWorkflowable') |