13.1 Workflow definition

We define a workflow as a finite state machine. This is to say, a combination of states, and transitions from one to other state.

\includegraphics[width=0.5\textwidth ]{figures/workflow}
Figure 13.1: A Basic publication workflow represented as a directed graph.

The code below defines the workflow represented by FigureĀ 13.1:

    from itools.workflow import Workflow

    # Workflow definition
    workflow = Workflow()
    # Specify the workflow states
    workflow.add_state('private')
    workflow.add_state('pending')
    workflow.add_state('public')
    # Specify the workflow transitions
    workflow.add_trans('publish', 'private', 'public')
    workflow.add_trans('request', 'private', 'pending')
    workflow.add_trans('reject', 'pending', 'private')
    workflow.add_trans('accept', 'pending', 'public')
    workflow.add_trans('retire', 'public', 'private')
    workflow.set_initstate('private')

The class Workflow is used to define the workflow system. The method add_state defines a state, the method add_trans defines a transition from one state to another. The method set_initstate defines the initial state.

Both states and transitions are identified by a name. It is possible to have two or more transitions with the same name, if they start from different states. A transition may start and end in the same state.