hooks/workflow.py
changeset 3536 f6c9a5df80fb
parent 3449 063488f14a0f
child 3589 a5432f99f2d9
equal deleted inserted replaced
3524:a3431f4e2f40 3536:f6c9a5df80fb
    44             state = entity.current_workflow.initial
    44             state = entity.current_workflow.initial
    45             if state:
    45             if state:
    46                 # use super session to by-pass security checks
    46                 # use super session to by-pass security checks
    47                 session.super_session.add_relation(entity.eid, 'in_state',
    47                 session.super_session.add_relation(entity.eid, 'in_state',
    48                                                    state.eid)
    48                                                    state.eid)
       
    49 
       
    50 
       
    51 class _FireAutotransitionOp(PreCommitOperation):
       
    52     """try to fire auto transition after state changes"""
       
    53 
       
    54     def precommit_event(self):
       
    55         session = self.session
       
    56         entity = self.entity
       
    57         autotrs = list(entity.possible_transitions('auto'))
       
    58         if autotrs:
       
    59             assert len(autotrs) == 1
       
    60             entity.fire_transition(autotrs[0])
       
    61 
    49 
    62 
    50 class _WorkflowChangedOp(hook.Operation):
    63 class _WorkflowChangedOp(hook.Operation):
    51     """fix entity current state when changing its workflow"""
    64     """fix entity current state when changing its workflow"""
    52 
    65 
    53     def precommit_event(self):
    66     def precommit_event(self):
   204         entity['from_state'] = fromstate.eid
   217         entity['from_state'] = fromstate.eid
   205         entity['to_state'] = deststateeid
   218         entity['to_state'] = deststateeid
   206         nocheck = session.transaction_data.setdefault('skip-security', set())
   219         nocheck = session.transaction_data.setdefault('skip-security', set())
   207         nocheck.add((entity.eid, 'from_state', fromstate.eid))
   220         nocheck.add((entity.eid, 'from_state', fromstate.eid))
   208         nocheck.add((entity.eid, 'to_state', deststateeid))
   221         nocheck.add((entity.eid, 'to_state', deststateeid))
       
   222         FireAutotransitionOp(session, entity=forentity)
   209 
   223 
   210 
   224 
   211 class FiredTransitionHook(WorkflowHook):
   225 class FiredTransitionHook(WorkflowHook):
   212     """change related entity state"""
   226     """change related entity state"""
   213     __regid__ = 'wffiretransition'
   227     __regid__ = 'wffiretransition'