entities/wfobjs.py
brancholdstable
changeset 8462 a14b6562082b
parent 8212 a045d3821990
child 8216 99ff746e8de8
equal deleted inserted replaced
8231:1bb43e31032d 8462:a14b6562082b
   181 
   181 
   182     provides a specific may_be_fired method to check if the relation may be
   182     provides a specific may_be_fired method to check if the relation may be
   183     fired by the logged user
   183     fired by the logged user
   184     """
   184     """
   185     __regid__ = 'BaseTransition'
   185     __regid__ = 'BaseTransition'
   186     fetch_attrs, fetch_order = fetch_config(['name', 'type'])
   186     fetch_attrs, cw_fetch_order = fetch_config(['name', 'type'])
   187 
   187 
   188     def __init__(self, *args, **kwargs):
   188     def __init__(self, *args, **kwargs):
   189         if self.__regid__ == 'BaseTransition':
   189         if self.__regid__ == 'BaseTransition':
   190             raise WorkflowException('should not be instantiated')
   190             raise WorkflowException('should not be instantiated')
   191         super(BaseTransition, self).__init__(*args, **kwargs)
   191         super(BaseTransition, self).__init__(*args, **kwargs)
   249             self._cw.execute('INSERT RQLExpression X: X exprtype "ERQLExpression", '
   249             self._cw.execute('INSERT RQLExpression X: X exprtype "ERQLExpression", '
   250                              'X expression %(expr)s, X mainvars %(mainvars)s, '
   250                              'X expression %(expr)s, X mainvars %(mainvars)s, '
   251                              'T condition X WHERE T eid %(x)s', kwargs)
   251                              'T condition X WHERE T eid %(x)s', kwargs)
   252         # XXX clear caches?
   252         # XXX clear caches?
   253 
   253 
   254     @deprecated('[3.6.1] use set_permission')
       
   255     def set_transition_permissions(self, requiredgroups=(), conditions=(),
       
   256                                    reset=True):
       
   257         return self.set_permissions(requiredgroups, conditions, reset)
       
   258 
       
   259 
   254 
   260 class Transition(BaseTransition):
   255 class Transition(BaseTransition):
   261     """customized class for Transition entities"""
   256     """customized class for Transition entities"""
   262     __regid__ = 'Transition'
   257     __regid__ = 'Transition'
       
   258 
       
   259     def dc_long_title(self):
       
   260         return '%s (%s)' % (self.name, self._cw._(self.name))
   263 
   261 
   264     def destination(self, entity):
   262     def destination(self, entity):
   265         try:
   263         try:
   266             return self.destination_state[0]
   264             return self.destination_state[0]
   267         except IndexError:
   265         except IndexError:
   345 
   343 
   346 
   344 
   347 class State(AnyEntity):
   345 class State(AnyEntity):
   348     """customized class for State entities"""
   346     """customized class for State entities"""
   349     __regid__ = 'State'
   347     __regid__ = 'State'
   350     fetch_attrs, fetch_order = fetch_config(['name'])
   348     fetch_attrs, cw_fetch_order = fetch_config(['name'])
   351     rest_attr = 'eid'
   349     rest_attr = 'eid'
       
   350 
       
   351     def dc_long_title(self):
       
   352         return '%s (%s)' % (self.name, self._cw._(self.name))
   352 
   353 
   353     @property
   354     @property
   354     def workflow(self):
   355     def workflow(self):
   355         # take care, may be missing in multi-sources configuration
   356         # take care, may be missing in multi-sources configuration
   356         return self.state_of and self.state_of[0] or None
   357         return self.state_of and self.state_of[0] or None
   358 
   359 
   359 class TrInfo(AnyEntity):
   360 class TrInfo(AnyEntity):
   360     """customized class for Transition information entities
   361     """customized class for Transition information entities
   361     """
   362     """
   362     __regid__ = 'TrInfo'
   363     __regid__ = 'TrInfo'
   363     fetch_attrs, fetch_order = fetch_config(['creation_date', 'comment'],
   364     fetch_attrs, cw_fetch_order = fetch_config(['creation_date', 'comment'],
   364                                             pclass=None) # don't want modification_date
   365                                                pclass=None) # don't want modification_date
   365     @property
   366     @property
   366     def for_entity(self):
   367     def for_entity(self):
   367         return self.wf_info_for[0]
   368         return self.wf_info_for[0]
   368 
   369 
   369     @property
   370     @property
   384     This mixin will be automatically set on class supporting the 'in_state'
   385     This mixin will be automatically set on class supporting the 'in_state'
   385     relation (which implies supporting 'wf_info_for' as well)
   386     relation (which implies supporting 'wf_info_for' as well)
   386     """
   387     """
   387 
   388 
   388     @property
   389     @property
   389     @deprecated('[3.5] use printable_state')
       
   390     def displayable_state(self):
       
   391         return self._cw._(self.state)
       
   392     @property
       
   393     @deprecated("[3.9] use entity.cw_adapt_to('IWorkflowable').main_workflow")
   390     @deprecated("[3.9] use entity.cw_adapt_to('IWorkflowable').main_workflow")
   394     def main_workflow(self):
   391     def main_workflow(self):
   395         return self.cw_adapt_to('IWorkflowable').main_workflow
   392         return self.cw_adapt_to('IWorkflowable').main_workflow
   396     @property
   393     @property
   397     @deprecated("[3.9] use entity.cw_adapt_to('IWorkflowable').current_workflow")
   394     @deprecated("[3.9] use entity.cw_adapt_to('IWorkflowable').current_workflow")
   412     @property
   409     @property
   413     @deprecated("[3.9] use entity.cw_adapt_to('IWorkflowable').workflow_history")
   410     @deprecated("[3.9] use entity.cw_adapt_to('IWorkflowable').workflow_history")
   414     def workflow_history(self):
   411     def workflow_history(self):
   415         return self.cw_adapt_to('IWorkflowable').workflow_history
   412         return self.cw_adapt_to('IWorkflowable').workflow_history
   416 
   413 
   417     @deprecated('[3.5] get transition from current workflow and use its may_be_fired method')
       
   418     def can_pass_transition(self, trname):
       
   419         """return the Transition instance if the current user can fire the
       
   420         transition with the given name, else None
       
   421         """
       
   422         tr = self.current_workflow and self.current_workflow.transition_by_name(trname)
       
   423         if tr and tr.may_be_fired(self.eid):
       
   424             return tr
       
   425     @deprecated("[3.9] use entity.cw_adapt_to('IWorkflowable').cwetype_workflow()")
   414     @deprecated("[3.9] use entity.cw_adapt_to('IWorkflowable').cwetype_workflow()")
   426     def cwetype_workflow(self):
   415     def cwetype_workflow(self):
   427         return self.cw_adapt_to('IWorkflowable').main_workflow()
   416         return self.cw_adapt_to('IWorkflowable').main_workflow()
   428     @deprecated("[3.9] use entity.cw_adapt_to('IWorkflowable').latest_trinfo()")
   417     @deprecated("[3.9] use entity.cw_adapt_to('IWorkflowable').latest_trinfo()")
   429     def latest_trinfo(self):
   418     def latest_trinfo(self):
   605         """
   594         """
   606         assert self.current_workflow
   595         assert self.current_workflow
   607         if hasattr(statename, 'eid'):
   596         if hasattr(statename, 'eid'):
   608             stateeid = statename.eid
   597             stateeid = statename.eid
   609         else:
   598         else:
   610             if not isinstance(statename, basestring):
   599             state = self.current_workflow.state_by_name(statename)
   611                 warn('[3.5] give a state name', DeprecationWarning, stacklevel=2)
       
   612                 state = self.current_workflow.state_by_eid(statename)
       
   613             else:
       
   614                 state = self.current_workflow.state_by_name(statename)
       
   615             if state is None:
   600             if state is None:
   616                 raise WorkflowException('not a %s state: %s' % (self.__regid__,
   601                 raise WorkflowException('not a %s state: %s' % (self.__regid__,
   617                                                                 statename))
   602                                                                 statename))
   618             stateeid = state.eid
   603             stateeid = state.eid
   619         # XXX try to find matching transition?
   604         # XXX try to find matching transition?