entities/wfobjs.py
branch3.5
changeset 2980 292387ed37f3
parent 2978 d8c5ad14ab8e
child 2986 d8f2e53702be
equal deleted inserted replaced
2979:94277323239d 2980:292387ed37f3
   386         self.req.create_entity('TrInfo', ('by_transition', 'T'),
   386         self.req.create_entity('TrInfo', ('by_transition', 'T'),
   387                                ('wf_info_for', 'E'), T=tr.eid, E=self.eid,
   387                                ('wf_info_for', 'E'), T=tr.eid, E=self.eid,
   388                                **self._get_tr_kwargs(comment, commentformat))
   388                                **self._get_tr_kwargs(comment, commentformat))
   389 
   389 
   390     def change_state(self, statename, comment=None, commentformat=None):
   390     def change_state(self, statename, comment=None, commentformat=None):
   391         """change the entity's state to the state of the given name in entity's
   391         """change the entity's state to the given state (name or entity) in
   392         workflow. This method should only by used by manager to fix an entity's
   392         entity's workflow. This method should only by used by manager to fix an
   393         state when their is no matching transition, otherwise fire_transition
   393         entity's state when their is no matching transition, otherwise
   394         should be used.
   394         fire_transition should be used.
   395         """
   395         """
   396         assert self.current_workflow
   396         assert self.current_workflow
   397         if not isinstance(statename, basestring):
   397         if hasattr(statename, 'eid'):
   398             warn('give a state name')
   398             stateeid = statename.eid
   399             state = self.current_workflow.state_by_eid(statename)
       
   400             assert state is not None, 'not a %s state: %s' % (self.id, state)
       
   401         else:
   399         else:
   402             state = self.current_workflow.state_by_name(statename)
   400             if not isinstance(statename, basestring):
       
   401                 warn('give a state name')
       
   402                 state = self.current_workflow.state_by_eid(statename)
       
   403             else:
       
   404                 state = self.current_workflow.state_by_name(statename)
       
   405             if state is None:
       
   406                 raise Exception('not a %s state: %s' % (self.id, statename))
       
   407             stateeid = state.eid
   403         # XXX try to find matching transition?
   408         # XXX try to find matching transition?
   404         self.req.create_entity('TrInfo', ('to_state', 'S'),
   409         self.req.create_entity('TrInfo', ('to_state', 'S'),
   405                                ('wf_info_for', 'E'), S=state.eid, E=self.eid,
   410                                ('wf_info_for', 'E'), S=stateeid, E=self.eid,
   406                                **self._get_tr_kwargs(comment, commentformat))
   411                                **self._get_tr_kwargs(comment, commentformat))
   407 
   412 
   408 
   413 
   409     def clear_all_caches(self):
   414     def clear_all_caches(self):
   410         super(WorkflowableMixIn, self).clear_all_caches()
   415         super(WorkflowableMixIn, self).clear_all_caches()