551 entity['from_state'], entity['to_state']) |
551 entity['from_state'], entity['to_state']) |
552 forentity = session.entity_from_eid(entity['wf_info_for']) |
552 forentity = session.entity_from_eid(entity['wf_info_for']) |
553 assert forentity.current_state.eid == entity['to_state'], ( |
553 assert forentity.current_state.eid == entity['to_state'], ( |
554 forentity.eid, forentity.current_state.name) |
554 forentity.eid, forentity.current_state.name) |
555 if forentity.main_workflow.eid != forentity.current_workflow.eid: |
555 if forentity.main_workflow.eid != forentity.current_workflow.eid: |
|
556 SubWorkflowExitOp(session, forentity=forentity, trinfo=entity) |
|
557 |
|
558 class SubWorkflowExitOp(PreCommitOperation): |
|
559 def precommit_event(self): |
|
560 session = self.session |
|
561 forentity = self.forentity |
|
562 trinfo = self.trinfo |
556 # we're in a subworkflow, check if we've reached an exit point |
563 # we're in a subworkflow, check if we've reached an exit point |
557 wftr = forentity.subworkflow_input_transition() |
564 wftr = forentity.subworkflow_input_transition() |
558 if wftr is None: |
565 if wftr is None: |
559 # inconsistency detected |
566 # inconsistency detected |
560 msg = entity.req._("state doesn't belong to entity's current workflow") |
567 msg = session._("state doesn't belong to entity's current workflow") |
561 raise ValidationError(entity.eid, {'to_state': msg}) |
568 raise ValidationError(self.trinfo.eid, {'to_state': msg}) |
562 tostate = wftr.get_exit_point(forentity, entity['to_state']) |
569 tostate = wftr.get_exit_point(forentity, trinfo['to_state']) |
563 if tostate is not None: |
570 if tostate is not None: |
564 # reached an exit point |
571 # reached an exit point |
565 msg = session._('exiting from subworkflow %s') |
572 msg = session._('exiting from subworkflow %s') |
566 msg %= session._(forentity.current_workflow.name) |
573 msg %= session._(forentity.current_workflow.name) |
567 session.transaction_data[(forentity.eid, 'subwfentrytr')] = True |
574 session.transaction_data[(forentity.eid, 'subwfentrytr')] = True |