Code


Version 18 (modified by anonymous, 7 years ago) (diff)

--

GoFlow: a workflow engine for Django

News:

download

Sites

  • contact: goflow(at)alwaysdata.net

The Leave workflow application

Follow instructions in the INSTALL.TXT file included in the goflow distribution. You can then play with the leave demo application (available online too). You will find here some details of the leave application implementation.

defining the workflow process

First, let's take a look at the process definition; the process is stored in the database, by using entities like Process, Activities, Transitions, Application (see workflow/models.py). In the leavedemo project, the process is dumped with the django dumpdata utility, and provided as a fixture. Typically, when you want to define a process, you will use the admin web console.

So, the process is the following: http://goflow.alwaysdata.net/leavedemo/media/img/leaveactivities.png

below, the process translated as django entities, with a python syntax (it is not a real code, it's just more readable by humans):

Process(title='leave', begin='Begin', end='End')

Activity(title='Begin', application='checkstatus',
         pushApplication='route_to_secretary',
         splitMode='xor', roles=('secretary',))

Activity(title='Approval', application='approvalform',
         pushApplication='route_to_supervisor',
         splitMode='xor', roles=('secretary',))

Activity(title='Refinement', application='refine',
         pushApplication='route_to_customer',
         joinMode='xor', splitMode='xor')

Activity(title='UpdateHR', application='hrform',
         pushApplication='route_to_secretary',
         roles=('supervisor',))

Activity(title='End', application='finalinfo',
         pushApplication='route_to_customer',
         joinMode='xor', roles=('secretary',),
         autoFinish=False)

Transition(name='send_to_approval',
           input = 'Begin', output='Approval',
           condition="instance.condition=='OK: Forward to supervisor'")

Transition(name='send_to_refinement',
           input = 'Begin', output='Refinement',
           condition="instance.condition=='Denied: Back to requester'")

Transition(name='request_approved',
           input = 'Approval', output='UpdateHR',
           condition="instance.condition=='OK: Forward to secretary'")

Transition(name='not_approved',
           input = 'Approval', output='Refinement',
           condition="instance.condition=='Denied: Back to requester'")

Transition(name='tell_employee',
           input = 'UpdateHR', output='End')

Transition(name='cancel_request',
           input = 'Refinement', output='End',
           condition="instance.condition=='Withdraw request'")

Transition(name='re_request',
           input = 'Refinement', output='Begin',
           condition="instance.condition=='Re-request'")

Some definitions:
A transition is a path from an Activity to another one.
An Activity is a task that a person (or an automatic process) with a specific role must achieve: it is linked to an Application which is typically an URL declared in the urls.py file.
A push application is a handler that return a user, given the context of process instance (in fact the parameter of the handler is a workitem, we will see this later)

settings file

standard settings

First, tell Django you want to use the workflow engine:

INSTALLED_APPS = (
    ....
    'django.contrib.workflow',    # uses the workflow engine
    #'contrib.workflow',          # alternative if workflow engine is not installed as contrib
    'leavedemo.leave',            # the leave application
)

specific settings

WF_APPS_PREFIX = 'leavedemo'

This is the url prefix for workflow application definition; for example, in the workflow definition the application app1 is mapped on the url /leavedemo/app1

WF_PUSH_APPS_PREFIX = 'leavedemo.leave.pushapplications'

this is the module containing the push applications functions; for example, the push application pushapp1 is a function defined as following in the leavedemo/leave/pushapplications.py module:

def pushapp1(workitem):
    ...
    return aUser

urls.py file

Starting a workflow instance

the start_application is a handler that display a form used to create an instance of the workflow process:

usage:

    (r'^leavedemo/request/$',
     'django.contrib.workflow.applications.start_application',
     {'process_name':'leave', 'form_class':RequestForm, 'template':'start_leave.html'}),

next soon ...

workflow urls

Some urls are workflow standard tasks, managed by the engine itself; like CRUD urls managed by admin, the workflow standard tasks are available with the following line in the urls.py file:

    (r'^leavedemo/', include('django.contrib.workflow.urls')),

So the workflow engine provides handlers and default templates below:

    (r'^mywork/$', 'django.contrib.workflow.views.mywork', {'template':'mywork.html'}),
    (r'^otherswork/$', 'django.contrib.workflow.views.otherswork', {'template':'otherswork.html'}),
    (r'^otherswork/instancehistory/$', 'django.contrib.workflow.views.instancehistory', {'template':'instancehistory.html'}),
    (r'^myrequests/$', 'django.contrib.workflow.views.myrequests', {'template':'myrequests.html'}),
    (r'^myrequests/instancehistory/$', 'django.contrib.workflow.views.instancehistory', {'template':'instancehistory.html'}),
    (r'^mywork/activate/$', 'django.contrib.workflow.views.activate', {'template':'activate.html'}),
    (r'^mywork/complete/$', 'django.contrib.workflow.views.complete', {'template':'complete.html'}),

mywork: displays the tasks list of the current user

next soon

Attachments (3)

Download all attachments as: .zip