570 kwargs['by_transition'] = self._cw.entity_from_eid(treid) |
570 kwargs['by_transition'] = self._cw.entity_from_eid(treid) |
571 if tseid is not None: |
571 if tseid is not None: |
572 kwargs['to_state'] = self._cw.entity_from_eid(tseid) |
572 kwargs['to_state'] = self._cw.entity_from_eid(tseid) |
573 return self._cw.create_entity('TrInfo', **kwargs) |
573 return self._cw.create_entity('TrInfo', **kwargs) |
574 |
574 |
575 def fire_transition(self, tr, comment=None, commentformat=None): |
575 def _get_transition(self, tr): |
576 """change the entity's state by firing transition of the given name in |
|
577 entity's workflow |
|
578 """ |
|
579 assert self.current_workflow |
576 assert self.current_workflow |
580 if isinstance(tr, basestring): |
577 if isinstance(tr, basestring): |
581 _tr = self.current_workflow.transition_by_name(tr) |
578 _tr = self.current_workflow.transition_by_name(tr) |
582 assert _tr is not None, 'not a %s transition: %s' % ( |
579 assert _tr is not None, 'not a %s transition: %s' % ( |
583 self.__regid__, tr) |
580 self.__regid__, tr) |
584 tr = _tr |
581 tr = _tr |
|
582 return tr |
|
583 |
|
584 def fire_transition(self, tr, comment=None, commentformat=None): |
|
585 """change the entity's state by firing given transition (name or entity) |
|
586 in entity's workflow |
|
587 """ |
|
588 tr = self._get_transition(tr) |
585 return self._add_trinfo(comment, commentformat, tr.eid) |
589 return self._add_trinfo(comment, commentformat, tr.eid) |
|
590 |
|
591 def fire_transition_if_possible(self, tr, comment=None, commentformat=None): |
|
592 """change the entity's state by firing given transition (name or entity) |
|
593 in entity's workflow if this transition is possible |
|
594 """ |
|
595 tr = self._get_transition(tr) |
|
596 if any(tr_ for tr_ in self.possible_transitions() |
|
597 if tr_.eid == tr.eid): |
|
598 self.fire_transition(tr) |
586 |
599 |
587 def change_state(self, statename, comment=None, commentformat=None, tr=None): |
600 def change_state(self, statename, comment=None, commentformat=None, tr=None): |
588 """change the entity's state to the given state (name or entity) in |
601 """change the entity's state to the given state (name or entity) in |
589 entity's workflow. This method should only by used by manager to fix an |
602 entity's workflow. This method should only by used by manager to fix an |
590 entity's state when their is no matching transition, otherwise |
603 entity's state when their is no matching transition, otherwise |