13.3 Metadata & Introspection

It is possible to add arbitrary metadata to the states and transitions definition:

    workflow.add_state('private', title=u'Private')
    workflow.add_state('pending', title=u'Pending')
    workflow.add_state('public', title=u'Public')

    workflow.add_trans('publish', 'private', 'public',
        title=u'Publish')
    workflow.add_trans('request', 'private', 'pending',
        title=u'Request')
    workflow.add_trans('reject', 'pending', 'private',
        title=u'Reject')
    workflow.add_trans('accept', 'pending', 'public',
        title=u'Accept')
    workflow.add_trans('retire', 'public', 'private',
        title=u'Retire')

In this example we have added a title to every state and transition, but we could have added anything else, like a description or access control information.

To get the metadata for an state we use the method get_state:

    >>> state = document.get_state()
    >>> print state['title']
    Public

The method get_state returns the State object for the current workflow state. Then we can access its metadata with the mapping interface.

Something else we can do is to find out the transitions that leave from that state:

    >>> for name, transition in state.transitions.items():
    ...    print '->', transition['title']
    -> Retire