hooks/workflow.py
branchstable
changeset 5056 5de07c77d73f
parent 5030 5238d9a8dfee
child 5164 4d99cccffe36
equal deleted inserted replaced
5055:14906474c55d 5056:5de07c77d73f
    43         if not (session.deleted_in_transaction(entity.eid) or entity.in_state) \
    43         if not (session.deleted_in_transaction(entity.eid) or entity.in_state) \
    44                and entity.current_workflow:
    44                and entity.current_workflow:
    45             state = entity.current_workflow.initial
    45             state = entity.current_workflow.initial
    46             if state:
    46             if state:
    47                 session.add_relation(entity.eid, 'in_state', state.eid)
    47                 session.add_relation(entity.eid, 'in_state', state.eid)
    48 
    48                 _FireAutotransitionOp(session, entity=entity)
    49 
    49 
    50 class _FireAutotransitionOp(hook.Operation):
    50 class _FireAutotransitionOp(hook.Operation):
    51     """try to fire auto transition after state changes"""
    51     """try to fire auto transition after state changes"""
    52 
    52 
    53     def precommit_event(self):
    53     def precommit_event(self):
    84             # if there are no history, simply go to new workflow's initial state
    84             # if there are no history, simply go to new workflow's initial state
    85             if not entity.workflow_history:
    85             if not entity.workflow_history:
    86                 if entity.current_state.eid != deststate.eid:
    86                 if entity.current_state.eid != deststate.eid:
    87                     _change_state(session, entity.eid,
    87                     _change_state(session, entity.eid,
    88                                   entity.current_state.eid, deststate.eid)
    88                                   entity.current_state.eid, deststate.eid)
       
    89                     _FireAutotransitionOp(session, entity=entity)
    89                 return
    90                 return
    90             msg = session._('workflow changed to "%s"')
    91             msg = session._('workflow changed to "%s"')
    91             msg %= session._(mainwf.name)
    92             msg %= session._(mainwf.name)
    92             session.transaction_data[(entity.eid, 'customwf')] = self.wfeid
    93             session.transaction_data[(entity.eid, 'customwf')] = self.wfeid
    93             entity.change_state(deststate, msg, u'text/plain')
    94             entity.change_state(deststate, msg, u'text/plain')