entities/wfobjs.py
changeset 9256 697a8181ba30
parent 8930 6a02be304486
child 9892 928732ec00dd
equal deleted inserted replaced
9255:46f41c3e1443 9256:697a8181ba30
    30 from logilab.common.compat import any
    30 from logilab.common.compat import any
    31 
    31 
    32 from cubicweb.entities import AnyEntity, fetch_config
    32 from cubicweb.entities import AnyEntity, fetch_config
    33 from cubicweb.view import EntityAdapter
    33 from cubicweb.view import EntityAdapter
    34 from cubicweb.predicates import relation_possible
    34 from cubicweb.predicates import relation_possible
    35 from cubicweb.mixins import MI_REL_TRIGGERS
       
    36 
    35 
    37 class WorkflowException(Exception): pass
    36 class WorkflowException(Exception): pass
    38 
    37 
    39 class Workflow(AnyEntity):
    38 class Workflow(AnyEntity):
    40     __regid__ = 'Workflow'
    39     __regid__ = 'Workflow'
   377     @property
   376     @property
   378     def transition(self):
   377     def transition(self):
   379         return self.by_transition and self.by_transition[0] or None
   378         return self.by_transition and self.by_transition[0] or None
   380 
   379 
   381 
   380 
   382 class WorkflowableMixIn(object):
   381 
   383     """base mixin providing workflow helper methods for workflowable entities.
   382 class IWorkflowableAdapter(EntityAdapter):
   384     This mixin will be automatically set on class supporting the 'in_state'
       
   385     relation (which implies supporting 'wf_info_for' as well)
       
   386     """
       
   387 
       
   388     @property
       
   389     @deprecated("[3.9] use entity.cw_adapt_to('IWorkflowable').main_workflow")
       
   390     def main_workflow(self):
       
   391         return self.cw_adapt_to('IWorkflowable').main_workflow
       
   392     @property
       
   393     @deprecated("[3.9] use entity.cw_adapt_to('IWorkflowable').current_workflow")
       
   394     def current_workflow(self):
       
   395         return self.cw_adapt_to('IWorkflowable').current_workflow
       
   396     @property
       
   397     @deprecated("[3.9] use entity.cw_adapt_to('IWorkflowable').current_state")
       
   398     def current_state(self):
       
   399         return self.cw_adapt_to('IWorkflowable').current_state
       
   400     @property
       
   401     @deprecated("[3.9] use entity.cw_adapt_to('IWorkflowable').state")
       
   402     def state(self):
       
   403         return self.cw_adapt_to('IWorkflowable').state
       
   404     @property
       
   405     @deprecated("[3.9] use entity.cw_adapt_to('IWorkflowable').printable_state")
       
   406     def printable_state(self):
       
   407         return self.cw_adapt_to('IWorkflowable').printable_state
       
   408     @property
       
   409     @deprecated("[3.9] use entity.cw_adapt_to('IWorkflowable').workflow_history")
       
   410     def workflow_history(self):
       
   411         return self.cw_adapt_to('IWorkflowable').workflow_history
       
   412 
       
   413     @deprecated("[3.9] use entity.cw_adapt_to('IWorkflowable').cwetype_workflow()")
       
   414     def cwetype_workflow(self):
       
   415         return self.cw_adapt_to('IWorkflowable').main_workflow()
       
   416     @deprecated("[3.9] use entity.cw_adapt_to('IWorkflowable').latest_trinfo()")
       
   417     def latest_trinfo(self):
       
   418         return self.cw_adapt_to('IWorkflowable').latest_trinfo()
       
   419     @deprecated("[3.9] use entity.cw_adapt_to('IWorkflowable').possible_transitions()")
       
   420     def possible_transitions(self, type='normal'):
       
   421         return self.cw_adapt_to('IWorkflowable').possible_transitions(type)
       
   422     @deprecated("[3.9] use entity.cw_adapt_to('IWorkflowable').fire_transition()")
       
   423     def fire_transition(self, tr, comment=None, commentformat=None):
       
   424         return self.cw_adapt_to('IWorkflowable').fire_transition(tr, comment, commentformat)
       
   425     @deprecated("[3.9] use entity.cw_adapt_to('IWorkflowable').change_state()")
       
   426     def change_state(self, statename, comment=None, commentformat=None, tr=None):
       
   427         return self.cw_adapt_to('IWorkflowable').change_state(statename, comment, commentformat, tr)
       
   428     @deprecated("[3.9] use entity.cw_adapt_to('IWorkflowable').subworkflow_input_trinfo()")
       
   429     def subworkflow_input_trinfo(self):
       
   430         return self.cw_adapt_to('IWorkflowable').subworkflow_input_trinfo()
       
   431     @deprecated("[3.9] use entity.cw_adapt_to('IWorkflowable').subworkflow_input_transition()")
       
   432     def subworkflow_input_transition(self):
       
   433         return self.cw_adapt_to('IWorkflowable').subworkflow_input_transition()
       
   434 
       
   435 
       
   436 MI_REL_TRIGGERS[('in_state', 'subject')] = WorkflowableMixIn
       
   437 
       
   438 
       
   439 
       
   440 class IWorkflowableAdapter(WorkflowableMixIn, EntityAdapter):
       
   441     """base adapter providing workflow helper methods for workflowable entities.
   383     """base adapter providing workflow helper methods for workflowable entities.
   442     """
   384     """
   443     __regid__ = 'IWorkflowable'
   385     __regid__ = 'IWorkflowable'
   444     __select__ = relation_possible('in_state')
   386     __select__ = relation_possible('in_state')
   445 
   387