Skip to main content

Task based reusable workflow library for django

Project description

Ad-hoc business process automation framework for Django.

The process logic defined with django-viewflow is concentrated in one clearly defined flow. You can organize your views, background jobs, user permission checking in a simple, intuitive django-friendly way.

tests/examples/shipment/doc/ShipmentProcess.png

django-viewflow allows to implement such process, just in about hundred lines of code, and you would still have pure django views for that.

Full documentation is available at http://kmmbvnr.github.io/django-viewflow/

Installation

django-viewflow requires Python 3.3 or greater and django 1.7:

pip install django-viewflow

And add it into INSTALLED_APPS settings

INSTALLED_APPS = (
     ...
     viewflow,
)

Quick start

Let’s define basic Hello Process where one could start hello world request, another person approves it, and as soon as the request is approved it should be send into background.

Start with process database model definition

from django.db import models
from viewflow.models import Process

class HelloworldProcess(Process):
    text = models.ChatField(max_lenght=150, blank=True, null=True)
    approved = models.BooleanField(default=False)

    class Meta:
        permissions = [
            ('can_start_request', 'Can start hello world request'),
            ('can_approve_request', 'Can approve hello world request')
        ]

Define the actual task that says Hello to the World in task.py

import os

from celery import shared_task
from viewflow.flow import flow_job

@shared_task(bind=True)
@flow_job()
def send_hello_world_request(self, activation):
    with open(os.devnull, "w") as world:
        world.write(activation.process.text)

To make the above code work just put the following flow definition in flows.py module from your django application.

from viewflow import flow
from viewflow.base import this, Flow
from viewflow.views import ProcessView

class HelloWorldFlow(Flow):
    start = flow.Start(StartView, fields=["text"]) \
       .Permission('helloworld.can_start_request') \
       .Activate(this.hello_world)

    approve = flow.View(ProcessView, fields=["approve"]) \
        .Permission('helloworld.can_approve_request')
        .Next(this.check_approve)

    check_approve = flow.If(cond=lambda p: p.approved) \
        .OnTrue(this.send) \
        .OnFalse(this.end)

    send = flow.Job(send_hello_world_request) \
        .Next(this.end)

    end = flow.End()

Flow class contains all urls required for the task processing.

from django.conf.urls import patterns, url, include
from .flows import HelloWorldFlow

urlpatterns = patterns('',
    url(r'^helloworld/', include(HelloWorldFlow.instance.urls)))

That’s all you need to setup this flow.

Next, you can see how to define custom views, and meet other concepts of django-viewflow at http://kmmbvnr.github.io/django-viewflow/

More examples are available in the tests/examples directory.

Change log

0.1.0

  • Initial public prototype
  • Basic set of tasks support (View, Job, If/Switch, Split/Join)

Project details


Release history Release notifications

History Node

1.2.5

History Node

1.2.2

History Node

1.2.0

History Node

1.1.0

History Node

1.0.2

History Node

1.0.1

History Node

1.0.0

History Node

0.12.2

History Node

0.12.1

History Node

0.12.0

History Node

0.10.1

History Node

0.10.0

History Node

0.9.0

History Node

0.8.0

History Node

0.7.0

History Node

0.6.0

History Node

0.5.0

History Node

0.4.0

History Node

0.3.0

History Node

0.2.0

This version
History Node

0.1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
django-viewflow-0.1.0.tar.gz (20.6 kB) Copy SHA256 hash SHA256 Source None May 1, 2014

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page