entities/wfobjs.py
changeset 3377 dd9d292b6a6d
parent 3038 1261c3df0e5a
child 3405 9d31c9cb8103
equal deleted inserted replaced
3376:f5c69485381f 3377:dd9d292b6a6d
    17 from cubicweb.common.mixins import MI_REL_TRIGGERS
    17 from cubicweb.common.mixins import MI_REL_TRIGGERS
    18 
    18 
    19 class WorkflowException(Exception): pass
    19 class WorkflowException(Exception): pass
    20 
    20 
    21 class Workflow(AnyEntity):
    21 class Workflow(AnyEntity):
    22     id = 'Workflow'
    22     __regid__ = 'Workflow'
    23 
    23 
    24     @property
    24     @property
    25     def initial(self):
    25     def initial(self):
    26         """return the initial state for this workflow"""
    26         """return the initial state for this workflow"""
    27         return self.initial_state and self.initial_state[0] or None
    27         return self.initial_state and self.initial_state[0] or None
   154     """customized class for abstract transition
   154     """customized class for abstract transition
   155 
   155 
   156     provides a specific may_be_fired method to check if the relation may be
   156     provides a specific may_be_fired method to check if the relation may be
   157     fired by the logged user
   157     fired by the logged user
   158     """
   158     """
   159     id = 'BaseTransition'
   159     __regid__ = 'BaseTransition'
   160     fetch_attrs, fetch_order = fetch_config(['name'])
   160     fetch_attrs, fetch_order = fetch_config(['name'])
   161 
   161 
   162     def __init__(self, *args, **kwargs):
   162     def __init__(self, *args, **kwargs):
   163         if self.id == 'BaseTransition':
   163         if self.__regid__ == 'BaseTransition':
   164             raise WorkflowException('should not be instantiated')
   164             raise WorkflowException('should not be instantiated')
   165         super(BaseTransition, self).__init__(*args, **kwargs)
   165         super(BaseTransition, self).__init__(*args, **kwargs)
   166 
   166 
   167     @property
   167     @property
   168     def workflow(self):
   168     def workflow(self):
   231         # XXX clear caches?
   231         # XXX clear caches?
   232 
   232 
   233 
   233 
   234 class Transition(BaseTransition):
   234 class Transition(BaseTransition):
   235     """customized class for Transition entities"""
   235     """customized class for Transition entities"""
   236     id = 'Transition'
   236     __regid__ = 'Transition'
   237 
   237 
   238     def destination(self):
   238     def destination(self):
   239         return self.destination_state[0]
   239         return self.destination_state[0]
   240 
   240 
   241 
   241 
   242 class WorkflowTransition(BaseTransition):
   242 class WorkflowTransition(BaseTransition):
   243     """customized class for WorkflowTransition entities"""
   243     """customized class for WorkflowTransition entities"""
   244     id = 'WorkflowTransition'
   244     __regid__ = 'WorkflowTransition'
   245 
   245 
   246     @property
   246     @property
   247     def subwf(self):
   247     def subwf(self):
   248         return self.subworkflow[0]
   248         return self.subworkflow[0]
   249 
   249 
   282         clear_cache(self, 'exit_points')
   282         clear_cache(self, 'exit_points')
   283 
   283 
   284 
   284 
   285 class SubWorkflowExitPoint(AnyEntity):
   285 class SubWorkflowExitPoint(AnyEntity):
   286     """customized class for SubWorkflowExitPoint entities"""
   286     """customized class for SubWorkflowExitPoint entities"""
   287     id = 'SubWorkflowExitPoint'
   287     __regid__ = 'SubWorkflowExitPoint'
   288 
   288 
   289     @property
   289     @property
   290     def subwf_state(self):
   290     def subwf_state(self):
   291         return self.subworkflow_state[0]
   291         return self.subworkflow_state[0]
   292 
   292 
   295         return self.destination_state[0]
   295         return self.destination_state[0]
   296 
   296 
   297 
   297 
   298 class State(AnyEntity):
   298 class State(AnyEntity):
   299     """customized class for State entities"""
   299     """customized class for State entities"""
   300     id = 'State'
   300     __regid__ = 'State'
   301     fetch_attrs, fetch_order = fetch_config(['name'])
   301     fetch_attrs, fetch_order = fetch_config(['name'])
   302     rest_attr = 'eid'
   302     rest_attr = 'eid'
   303 
   303 
   304     @property
   304     @property
   305     def workflow(self):
   305     def workflow(self):
   316 
   316 
   317 
   317 
   318 class TrInfo(AnyEntity):
   318 class TrInfo(AnyEntity):
   319     """customized class for Transition information entities
   319     """customized class for Transition information entities
   320     """
   320     """
   321     id = 'TrInfo'
   321     __regid__ = 'TrInfo'
   322     fetch_attrs, fetch_order = fetch_config(['creation_date', 'comment'],
   322     fetch_attrs, fetch_order = fetch_config(['creation_date', 'comment'],
   323                                             pclass=None) # don't want modification_date
   323                                             pclass=None) # don't want modification_date
   324     @property
   324     @property
   325     def for_entity(self):
   325     def for_entity(self):
   326         return self.wf_info_for[0]
   326         return self.wf_info_for[0]