We can associate actions to different events. Every time a transition is done, if we have defined these actions, they will be automatically triggered. Here they are, in the order they are called:
Called at the beginning of the transition, where statename is the starting state.
Called in the middle of the transition, where transname is the transition being executed.
Called at the end of the transition, where statename is the ending state.
And here the example, this is the way we define the actions:
class Document(WorkflowAware):
def onleave_private(self):
print 'LEAVE PRIVATE'
def ontrans_request(self):
print 'REQUEST'
def onenter_pending(self):
print 'ENTER PENDING'
And here we test the code:
>>> document = Document()
>>> document.enter_workflow(workflow)
>>> document.do_trans('request')
LEAVE PRIVATE
REQUEST
ENTER PENDING
A much useful action would be, for example, to send an email to the reviewer every time the publication of a document is requested.