63 __id__ = 'wfsetinitial' |
63 __id__ = 'wfsetinitial' |
64 __select__ = WorkflowHook.__select__ & entity_implements(IWorkflowable) |
64 __select__ = WorkflowHook.__select__ & entity_implements(IWorkflowable) |
65 events = ('after_add_entity',) |
65 events = ('after_add_entity',) |
66 |
66 |
67 def __call__(self): |
67 def __call__(self): |
68 _SetInitialStateOp(self.cw_req, entity=self.entity) |
68 _SetInitialStateOp(self._cw, entity=self.entity) |
69 |
69 |
70 |
70 |
71 class PrepareStateChangeHook(WorkflowHook): |
71 class PrepareStateChangeHook(WorkflowHook): |
72 """record previous state information""" |
72 """record previous state information""" |
73 __id__ = 'cwdelstate' |
73 __id__ = 'cwdelstate' |
74 __select__ = WorkflowHook.__select__ & hook.match_rtype('in_state') |
74 __select__ = WorkflowHook.__select__ & hook.match_rtype('in_state') |
75 events = ('before_delete_relation',) |
75 events = ('before_delete_relation',) |
76 |
76 |
77 def __call__(self): |
77 def __call__(self): |
78 self.cw_req.transaction_data.setdefault('pendingrelations', []).append( |
78 self._cw.transaction_data.setdefault('pendingrelations', []).append( |
79 (self.eidfrom, self.rtype, self.eidto)) |
79 (self.eidfrom, self.rtype, self.eidto)) |
80 |
80 |
81 |
81 |
82 class FireTransitionHook(PrepareStateChangeHook): |
82 class FireTransitionHook(PrepareStateChangeHook): |
83 """check the transition is allowed and record transition information""" |
83 """check the transition is allowed and record transition information""" |
84 __id__ = 'wffiretransition' |
84 __id__ = 'wffiretransition' |
85 events = ('before_add_relation',) |
85 events = ('before_add_relation',) |
86 |
86 |
87 def __call__(self): |
87 def __call__(self): |
88 session = self.cw_req |
88 session = self._cw |
89 eidfrom = self.eidfrom |
89 eidfrom = self.eidfrom |
90 eidto = self.eidto |
90 eidto = self.eidto |
91 state = previous_state(session, eidfrom) |
91 state = previous_state(session, eidfrom) |
92 etype = session.describe(eidfrom)[0] |
92 etype = session.describe(eidfrom)[0] |
93 if not (session.is_super_session or 'managers' in session.user.groups): |
93 if not (session.is_super_session or 'managers' in session.user.groups): |
132 __id__ = 'wfsyncmdate' |
132 __id__ = 'wfsyncmdate' |
133 __select__ = WorkflowHook.__select__ & hook.match_rtype('in_state') |
133 __select__ = WorkflowHook.__select__ & hook.match_rtype('in_state') |
134 events = ('after_add_relation',) |
134 events = ('after_add_relation',) |
135 |
135 |
136 def __call__(self): |
136 def __call__(self): |
137 if self.cw_req.added_in_transaction(self.eidfrom): |
137 if self._cw.added_in_transaction(self.eidfrom): |
138 # new entity, not needed |
138 # new entity, not needed |
139 return |
139 return |
140 entity = self.cw_req.entity_from_eid(self.eidfrom) |
140 entity = self._cw.entity_from_eid(self.eidfrom) |
141 try: |
141 try: |
142 entity.set_attributes(modification_date=datetime.now()) |
142 entity.set_attributes(modification_date=datetime.now()) |
143 except RepositoryError, ex: |
143 except RepositoryError, ex: |
144 # usually occurs if entity is coming from a read-only source |
144 # usually occurs if entity is coming from a read-only source |
145 # (eg ldap user) |
145 # (eg ldap user) |