Metadata-Version: 2.1
Name: roughrider.workflow
Version: 0.2
Summary: Pure python workflow/transition system.
Home-page: https://github.com/HorsemanWSGI/roughrider.workflow
Author: Souheil CHELFOUH
Author-email: trollfot@gmail.com
License: ZPL
Download-URL: http://pypi.python.org/pypi/roughrider.workflow
Description: roughrider.workflow
        *******************
        
        This package allows to define workflows that consist of a set of states,
        transitions between the states. Actions that activate the transitions
        can be guarded by constraints.
        
        
        Example
        =======
        
        .. code-block:: python
        
          from roughrider.predicate import ConstraintError, Validator, Or
          from roughrider.workflow.components import Action, Transition, Transitions
          from roughrider.workflow.workflow import (
              WorkflowItem, WorkflowState, Workflow)
        
        
          class Document:
              state = None
              body = ""
        
        
          class RoleValidator(Validator):
        
              def __init__(self, role):
                  self.role = role
        
              def __call__(self, item, role=None, **namespace):
                  if role != self.role:
                      raise ConstraintError(
                          message=f'Unauthorized. Missing the `{role}` role.')
        
        
          class PublicationWorkflow(Workflow):
        
              class wrapper(WorkflowItem):
        
                  @property
                  def state(self):
                      return self.workflow.get(self.item.state)
        
                  @state.setter
                  def state(self, state):
                      self.item.state = state.name
        
        
              class states(WorkflowState):
                  draft = 'Draft'
                  published = 'Published'
                  submitted = 'Submitted'
        
        
              transitions = Transitions((
                  Transition(
                      origin=states.draft,
                      target=states.published,
                      action=Action(
                          'Publish',
                          constraints=[RoleValidator('publisher')]
                      )
                  ),
                  Transition(
                      origin=states.published,
                      target=states.draft,
                      action=Action(
                          'Retract',
                          constraints=[
                              Or((RoleValidator('owner'),
                                  RoleValidator('publisher')))
                          ]
                      )
                  ),
                  Transition(
                      origin=states.draft,
                      target=states.submitted,
                      action=Action(
                          'Submit',
                          constraints=[RoleValidator('owner')],
                      )
                  ),
                  Transition(
                      origin=states.submitted,
                      target=states.published,
                      action=Action(
                          'Publish',
                          constraints=[RoleValidator('publisher')],
                      )
                  )
              ))
        
        
          workflow = PublicationWorkflow('draft')  # initial state
          item = Document()
          workflow_item = workflow(item, role='owner')
          workflow_item.transition_to(PublicationWorkflow.states.submitted)
        
        CHANGES
        =======
        
        0.2 (2021-10-21)
        ----------------
        
          * Updating to use `roughrider.predicate >= 0.3.1`
        
        0.1 (2021-10-09)
        ----------------
        
          * Initial release.
        
Platform: UNKNOWN
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Zope Public License
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Provides-Extra: test
