hooks/workflow.py
changeset 3376 f5c69485381f
parent 3072 6fb42c53f6df
child 3449 063488f14a0f
equal deleted inserted replaced
3375:ebb11fa58ab9 3376:f5c69485381f
    99     __abstract__ = True
    99     __abstract__ = True
   100     category = 'worfklow'
   100     category = 'worfklow'
   101 
   101 
   102 
   102 
   103 class SetInitialStateHook(WorkflowHook):
   103 class SetInitialStateHook(WorkflowHook):
   104     __id__ = 'wfsetinitial'
   104     __regid__ = 'wfsetinitial'
   105     __select__ = WorkflowHook.__select__ & entity_implements(IWorkflowable)
   105     __select__ = WorkflowHook.__select__ & entity_implements(IWorkflowable)
   106     events = ('after_add_entity',)
   106     events = ('after_add_entity',)
   107 
   107 
   108     def __call__(self):
   108     def __call__(self):
   109         _SetInitialStateOp(self._cw, entity=self.entity)
   109         _SetInitialStateOp(self._cw, entity=self.entity)
   110 
   110 
   111 
   111 
   112 class PrepareStateChangeHook(WorkflowHook):
   112 class PrepareStateChangeHook(WorkflowHook):
   113     """record previous state information"""
   113     """record previous state information"""
   114     __id__ = 'cwdelstate'
   114     __regid__ = 'cwdelstate'
   115     __select__ = WorkflowHook.__select__ & hook.match_rtype('in_state')
   115     __select__ = WorkflowHook.__select__ & hook.match_rtype('in_state')
   116     events = ('before_delete_relation',)
   116     events = ('before_delete_relation',)
   117 
   117 
   118     def __call__(self):
   118     def __call__(self):
   119         self._cw.transaction_data.setdefault('pendingrelations', []).append(
   119         self._cw.transaction_data.setdefault('pendingrelations', []).append(
   123 class FireTransitionHook(WorkflowHook):
   123 class FireTransitionHook(WorkflowHook):
   124     """check the transition is allowed, add missing information. Expect that:
   124     """check the transition is allowed, add missing information. Expect that:
   125     * wf_info_for inlined relation is set
   125     * wf_info_for inlined relation is set
   126     * by_transition or to_state (managers only) inlined relation is set
   126     * by_transition or to_state (managers only) inlined relation is set
   127     """
   127     """
   128     __id__ = 'wffiretransition'
   128     __regid__ = 'wffiretransition'
   129     __select__ = WorkflowHook.__select__ & entity_implements('TrInfo')
   129     __select__ = WorkflowHook.__select__ & entity_implements('TrInfo')
   130     events = ('before_add_entity',)
   130     events = ('before_add_entity',)
   131 
   131 
   132     def __call__(self):
   132     def __call__(self):
   133         session = self._cw
   133         session = self._cw
   208         nocheck.add((entity.eid, 'to_state', deststateeid))
   208         nocheck.add((entity.eid, 'to_state', deststateeid))
   209 
   209 
   210 
   210 
   211 class FiredTransitionHook(WorkflowHook):
   211 class FiredTransitionHook(WorkflowHook):
   212     """change related entity state"""
   212     """change related entity state"""
   213     __id__ = 'wffiretransition'
   213     __regid__ = 'wffiretransition'
   214     __select__ = WorkflowHook.__select__ & entity_implements('TrInfo')
   214     __select__ = WorkflowHook.__select__ & entity_implements('TrInfo')
   215     events = ('after_add_entity',)
   215     events = ('after_add_entity',)
   216 
   216 
   217     def __call__(self):
   217     def __call__(self):
   218         session = self._cw
   218         session = self._cw
   245 
   245 
   246 
   246 
   247 class CheckInStateChangeAllowed(WorkflowHook):
   247 class CheckInStateChangeAllowed(WorkflowHook):
   248     """check state apply, in case of direct in_state change using unsafe_execute
   248     """check state apply, in case of direct in_state change using unsafe_execute
   249     """
   249     """
   250     __id__ = 'wfcheckinstate'
   250     __regid__ = 'wfcheckinstate'
   251     __select__ = WorkflowHook.__select__ & hook.match_rtype('in_state')
   251     __select__ = WorkflowHook.__select__ & hook.match_rtype('in_state')
   252     events = ('before_add_relation',)
   252     events = ('before_add_relation',)
   253 
   253 
   254     def __call__(self):
   254     def __call__(self):
   255         session = self._cw
   255         session = self._cw
   274             raise ValidationError(self.eidfrom, {'in_state': msg})
   274             raise ValidationError(self.eidfrom, {'in_state': msg})
   275 
   275 
   276 
   276 
   277 class SetModificationDateOnStateChange(WorkflowHook):
   277 class SetModificationDateOnStateChange(WorkflowHook):
   278     """update entity's modification date after changing its state"""
   278     """update entity's modification date after changing its state"""
   279     __id__ = 'wfsyncmdate'
   279     __regid__ = 'wfsyncmdate'
   280     __select__ = WorkflowHook.__select__ & hook.match_rtype('in_state')
   280     __select__ = WorkflowHook.__select__ & hook.match_rtype('in_state')
   281     events = ('after_add_relation',)
   281     events = ('after_add_relation',)
   282 
   282 
   283     def __call__(self):
   283     def __call__(self):
   284         if self._cw.added_in_transaction(self.eidfrom):
   284         if self._cw.added_in_transaction(self.eidfrom):
   294             self.warning('cant change modification date for %s: %s', entity, ex)
   294             self.warning('cant change modification date for %s: %s', entity, ex)
   295 
   295 
   296 
   296 
   297 class CheckWorkflowTransitionExitPoint(WorkflowHook):
   297 class CheckWorkflowTransitionExitPoint(WorkflowHook):
   298     """check that there is no multiple exits from the same state"""
   298     """check that there is no multiple exits from the same state"""
   299     __id__ = 'wfcheckwftrexit'
   299     __regid__ = 'wfcheckwftrexit'
   300     __select__ = WorkflowHook.__select__ & hook.match_rtype('subworkflow_exit')
   300     __select__ = WorkflowHook.__select__ & hook.match_rtype('subworkflow_exit')
   301     events = ('after_add_relation',)
   301     events = ('after_add_relation',)
   302 
   302 
   303     def __call__(self):
   303     def __call__(self):
   304         _CheckTrExitPoint(self._cw, treid=self.eidfrom)
   304         _CheckTrExitPoint(self._cw, treid=self.eidfrom)
   305 
   305 
   306 
   306 
   307 class SetCustomWorkflow(WorkflowHook):
   307 class SetCustomWorkflow(WorkflowHook):
   308     __id__ = 'wfsetcustom'
   308     __regid__ = 'wfsetcustom'
   309     __select__ = WorkflowHook.__select__ & hook.match_rtype('custom_workflow')
   309     __select__ = WorkflowHook.__select__ & hook.match_rtype('custom_workflow')
   310     events = ('after_add_relation',)
   310     events = ('after_add_relation',)
   311 
   311 
   312     def __call__(self):
   312     def __call__(self):
   313         _WorkflowChangedOp(self._cw, eid=self.eidfrom, wfeid=self.eidto)
   313         _WorkflowChangedOp(self._cw, eid=self.eidfrom, wfeid=self.eidto)
   314 
   314 
   315 
   315 
   316 class DelCustomWorkflow(SetCustomWorkflow):
   316 class DelCustomWorkflow(SetCustomWorkflow):
   317     __id__ = 'wfdelcustom'
   317     __regid__ = 'wfdelcustom'
   318     events = ('after_delete_relation',)
   318     events = ('after_delete_relation',)
   319 
   319 
   320     def __call__(self):
   320     def __call__(self):
   321         entity = self._cw.entity_from_eid(self.eidfrom)
   321         entity = self._cw.entity_from_eid(self.eidfrom)
   322         typewf = entity.cwetype_workflow()
   322         typewf = entity.cwetype_workflow()
   324             _WorkflowChangedOp(self._cw, eid=self.eidfrom, wfeid=typewf.eid)
   324             _WorkflowChangedOp(self._cw, eid=self.eidfrom, wfeid=typewf.eid)
   325 
   325 
   326 
   326 
   327 
   327 
   328 class DelWorkflowHook(WorkflowHook):
   328 class DelWorkflowHook(WorkflowHook):
   329     __id__ = 'wfdel'
   329     __regid__ = 'wfdel'
   330     __select__ = WorkflowHook.__select__ & entity_implements('Workflow')
   330     __select__ = WorkflowHook.__select__ & entity_implements('Workflow')
   331     events = ('after_delete_entity',)
   331     events = ('after_delete_entity',)
   332 
   332 
   333     def __call__(self):
   333     def __call__(self):
   334         # cleanup unused state and transition
   334         # cleanup unused state and transition