Code Monkey home page Code Monkey logo

workflow's Introduction

Django Workflow Application v0.1 (alpha)

(c) 2009 Nicholas H.Tollervey (http://ntoll.org/contact)

See the file LICENSE.txt for the licensing terms and conditions.

This Django application provides a workflow engine for use in your 
web-application. This work is an abstraction of / extraction from a workflow
engine built for an HR application.

Currently only the models have been "extracted". Commented doctests can be 
found in tests.py. I've also created some templates for generating .dot files
for processing by Graphviz. See: http://twitpic.com/7xiz7 for example output.
See the urls.py for paths to use to display the .dot file and resulting .png
image.

To make things easy I've described each model below and made up a couple of 
"user stories" to illustrate how stuff fits together (an Applicant Tracking 
System used by HR and a simple issue tracker for filing bugs, feature requests 
and whatnot). 

I realise the examples might be a tad contrived but I always find that thinking
about tangible examples relating to data models is always helpful.

The order that I describe the tables follows the code outline.

Role - defines what sort of users are associated with different aspects of the
workflow. In the HR project these roles might include: 'HR Consultant', 'Hiring
Manager', 'Interviewer' or 'Assessor'. In the issue tracker these might simply 
be 'Core Developer', 'Release Manager' or 'Tester'. The State and Transition 
models have a many-to-many relationship with Role to indicate what sort of 
person has permission to view a state or use a transition. The Event model has a
many-to-many relationship with Role to indicate who is participating in the
event.

Workflow - names / describes a workflow. In the HR project workflows might be:
'Generic Hiring Process', 'Executive Hiring Process' or 'Employee Appraisal'. In
the issue tracker these might include: 'Bug Report', 'Feature Request' or
'Release Lifecycle'. A workflow can be in one of three states that defines the
life of a workflow: definition -> active -> retired. A workflow can only be
changed when it has the state 'definition' (where changed means states and
transitions added or removed). A workflow can only be used when it has the state
'active'. When a workflow is no longer useful, or is found to contain errors
then it is marked as 'retired'. Why take so much trouble over this? Imagine the
mess that could ensue if a 'live' workflow were changed and states were deleted
or orphaned. Furthermore, retired workflows could be "cloned" as the basis of
new workflows in the 'definition' state. 

State - represents a specific state that a thing can be in. In the HR project
examples might be: 'Open for applications', 'Final shortlisting', 'Employee
Interviews'. In the issue tracker we might have: 'Open', 'Rejected', 'Awaiting
Approval'. Put simply a state is a description of a node in a directed graph. 
Only one state can be marked as 'is_start_state' for each workflow but many can
be marked as 'is_end_state' (indicating the workflow has been completed). Roles
associated with each state indicate *who* has access to the thing when in this
state.

Transition - defines how a workflow can move between states. They *should* be
given "active" names. For example, in the HR project transitions might be:
'Publish Vacancy' (leading to the 'Open for applications' state), 'Publish
applications' (leading to the 'Final shortlisting' state) or 'Publish
meeting slots' (leading to 'Employee Interviews'). The issue tracker transitions
are probably more obvious 'Submit issue' (leads to 'Open' state), 'Reject'
(leads to 'Rejected') and 'Propose new feature' (leads to 'Awaiting Approval').
Put simply, a transition is an edge in a directed graph. Roles associated with
each transition indicate *who* can use the transition to move the workflow to a
new state.

EventType - just defines the name of a type of event. Examples might be:
meeting, assessment, interview, deployment test, feature freeze and so on.

Event - is a specification for something that is supposed to happen whilst in
a state. In the HR project events might be: 'Meeting to approve job
specification', 'Meeting of review board' or 'Contact all managers conducting
employee interviews'. The issue tracker might have: 'Check for duplicate issue',
'Check unit tests pass on staging server'. The roles field indicates *who* is to
participate in the event. I've also included an is_mandatory flag. An event can
be associated with many EventTypes.

WorkflowActivity - is a core model to link "things" to workflows in a similar way
to User objects having a profile. Vacancy and Issue instances in the HR and
issue tracker examples should reference a WorkflowManager. The WorkflowManager
simply references an active Workflow and contains created_on and completed_on
timestamps. The various methods associated with this model should be used move
through the life of the workflow.

Participant - links django.contrib.auth.models.User instances to a Role and 
WorkflowManager. This way we know that user 'Joe Blogs' has the role 'Hiring 
Manager' for the duration of the WorkflowManager that is using the 'Executive
Hiring Process' workflow. We might also know that jtauber is Release Manager 
during the lifetime of the WorkflowManager for Pinax1.0 that follows the Release 
Lifecycle workflow.

WorkflowHistory - simply links up the WorkflowManager, State, Transition and
Events to the State, Participant, a descriptive note and a timestamp enabling 
us to track how the workflow has progressed (with the most recent being the 
current state). Examples might be: Pinax1.0 WorkflowManager, "RC1" state, 
"Prepare Release Candidate" transition, jtauber, 2009-11-5.

As always, comments, ideas, suggestions and improvements are most welcome.

workflow's People

Contributors

jezdez avatar ntoll avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

workflow's Issues

Failed Tests

Python 2.6.2 on Ubuntu Jaunty. Postgresql.

FAIL: Doctest: workflow.tests

Traceback (most recent call last):
File "/var/lib/python-support/python2.6/django/test/_doctest.py", line 2180, in runTest
raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for workflow.tests
File "/usr/local/lib/python2.6/dist-packages/workflow/tests.py", line 1, in tests


File "/usr/local/lib/python2.6/dist-packages/workflow/tests.py", line 159, in workflow.tests
Failed example:
current.state.transitions_from.all()
Expected:
[<Transition: Revise Draft>, <Transition: Publish>]
Got:

[<Transition: Publish>, <Transition: Revise Draft>]

File "/usr/local/lib/python2.6/dist-packages/workflow/tests.py", line 168, in workflow.tests
Failed example:
current.state.transitions_from.all()
Expected:
[<Transition: Archive>]
Got:

[<Transition: Request Approval>]

File "/usr/local/lib/python2.6/dist-packages/workflow/tests.py", line 171, in workflow.tests
Failed example:
d.workflow_manager.progress(my_transition, p2)
Exception raised:
Traceback (most recent call last):
File "/var/lib/python-support/python2.6/django/test/_doctest.py", line 1267, in __run
compileflags, 1) in test.globs
File "<doctest workflow.tests[68]>", line 1, in
d.workflow_manager.progress(my_transition, p2)
File "/usr/local/lib/python2.6/dist-packages/workflow/models.py", line 585, in progress
raise UnableToProgressWorkflow, __('Participant has insufficient'\

UnableToProgressWorkflow: Participant has insufficient authority to use the specified transition

File "/usr/local/lib/python2.6/dist-packages/workflow/tests.py", line 173, in workflow.tests
Failed example:
for item in d.workflow_manager.history.all():
print '%s by %s'%(item.note, item.participant.user.username)
Expected:
Archive by joe
We'll be up for a Pulitzer by joe
A great review meeting, loved the punchline! by joe
Request Approval by fred
Started workflow by fred
Got:
We'll be up for a Pulitzer by joe
A great review meeting, loved the punchline! by joe
Request Approval by fred
Started workflow by fred

Django 1.2 and invalid exclude definition in admin.py

When I enter admin panel I get an error saying that "exclude refers to field created_on that is missing from the form."

The problem is caused by the following definition (admin.py):

class WorkflowAdmin(admin.ModelAdmin):
    """
    Workflow administration
    """
    (...)
    exclude = ['created_on', 'cloned_from']
    list_filter = ['status']

It is enough to remove created_on from the exclude (exclude = ['cloned_from']). created_on field is defined as auto_now_add which makes it automatically editable=False, so it is not included in the form generated for admin.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.