entities/wfobjs.py
branch3.5
changeset 2946 957fd4b276e2
parent 2945 f0ab83510477
child 2947 083593802120
equal deleted inserted replaced
2945:f0ab83510477 2946:957fd4b276e2
   259     relation (which implies supporting 'wf_info_for' as well)
   259     relation (which implies supporting 'wf_info_for' as well)
   260     """
   260     """
   261     __implements__ = (IWorkflowable,)
   261     __implements__ = (IWorkflowable,)
   262 
   262 
   263     @property
   263     @property
   264     @cached
       
   265     def current_workflow(self):
   264     def current_workflow(self):
   266         """return current workflow applied to this entity"""
   265         """return current workflow applied to this entity"""
   267         if self.custom_workflow:
   266         if self.custom_workflow:
   268             return self.custom_workflow[0]
   267             return self.custom_workflow[0]
   269         wfrset = self.req.execute('Any WF WHERE X is ET, X eid %(x)s, WF workflow_of ET',
   268         return self.cwetype_workflow()
   270                                   {'x': self.eid}, 'x')
   269 
       
   270     @property
       
   271     def current_state(self):
       
   272         """return current state entity"""
       
   273         return self.in_state and self.in_state[0] or None
       
   274 
       
   275     @property
       
   276     def state(self):
       
   277         """return current state name"""
       
   278         try:
       
   279             return self.in_state[0].name
       
   280         except IndexError:
       
   281             self.warning('entity %s has no state', self)
       
   282             return None
       
   283 
       
   284     @property
       
   285     def printable_state(self):
       
   286         """return current state name translated to context's language"""
       
   287         state = self.current_state
       
   288         if state:
       
   289             return self.req._(state.name)
       
   290         return u''
       
   291 
       
   292     def latest_trinfo(self):
       
   293         """return the latest transition information for this entity"""
       
   294         return self.reverse_wf_info_for[-1]
       
   295 
       
   296     @cached
       
   297     def cwetype_workflow(self):
       
   298         """return the default workflow for entities of this type"""
       
   299         # XXX CWEType method
       
   300         wfrset = self.req.execute('Any WF WHERE X is ET, X eid %(x)s, '
       
   301                                   'WF workflow_of ET', {'x': self.eid}, 'x')
   271         if len(wfrset) == 1:
   302         if len(wfrset) == 1:
   272             return wfrset.get_entity(0, 0)
   303             return wfrset.get_entity(0, 0)
   273         if len(wfrset) > 1:
   304         if len(wfrset) > 1:
   274             for wf in wfrset.entities():
   305             for wf in wfrset.entities():
   275                 if wf.is_default_workflow_of(self.id):
   306                 if wf.is_default_workflow_of(self.id):
   276                     return wf
   307                     return wf
   277             self.warning("can't find default workflow for %s", self.id)
   308             self.warning("can't find default workflow for %s", self.id)
   278         else:
   309         else:
   279             self.warning("can't find any workflow for %s", self.id)
   310             self.warning("can't find any workflow for %s", self.id)
   280         return None
   311         return None
   281 
       
   282     @property
       
   283     def current_state(self):
       
   284         """return current state entity"""
       
   285         return self.in_state and self.in_state[0] or None
       
   286 
       
   287     @property
       
   288     def state(self):
       
   289         """return current state name"""
       
   290         try:
       
   291             return self.in_state[0].name
       
   292         except IndexError:
       
   293             self.warning('entity %s has no state', self)
       
   294             return None
       
   295 
       
   296     @property
       
   297     def printable_state(self):
       
   298         """return current state name translated to context's language"""
       
   299         state = self.current_state
       
   300         if state:
       
   301             return self.req._(state.name)
       
   302         return u''
       
   303 
       
   304     def latest_trinfo(self):
       
   305         """return the latest transition information for this entity"""
       
   306         return self.reverse_wf_info_for[-1]
       
   307 
   312 
   308     def possible_transitions(self):
   313     def possible_transitions(self):
   309         """generates transition that MAY be fired for the given entity,
   314         """generates transition that MAY be fired for the given entity,
   310         expected to be in this state
   315         expected to be in this state
   311         """
   316         """