Skip to main content

Django Workflow Library

Project description

Django River

Logo

Build Status Coverage Status Documentation Status Codacy Badge PyPI - Downloads Discord

Contributors are welcome. Come and give a hand :-)

River is an open source workflow framework for Django which support on the fly changes instead of hardcoding states, transitions and authorization rules.

The main goal of developing this framework is to be able to edit any workflow item on the fly. This means that all the elements in a workflow like states, transitions or authorizations rules are editable at any time so that no changes requires a re-deploying of your application anymore.

Playground: There is a fake jira example repository as a playground of django-river. https://github.com/javrasya/fakejira

Donations

This is a fully open source project and it can be better with your donations.

If you are using django-river to create a commercial product, please consider becoming our sponsor , patron or donate over PayPal

Documentation

Online documentation is available at http://django-river.rtfd.org/

Advance Admin

A very modern admin with some user friendly interfaces that is called River Admin has been published.

Requirements

  • Python (2.7, 3.4, 3.5, 3.6)

  • Django (1.11, 2.0, 2.1, 2.2, 3.0)

  • Django >= 2.0 is supported for Python >= 3.5

Supported (Tested) Databases:

PostgreSQL

Tested

Support

9

10

11

12

MySQL

Tested

Support

5.6

5.7

8.0

MSSQL

Tested

Support

19

17

Usage

  1. Install and enable it

    pip install django-river
    INSTALLED_APPS=[
        ...
        river
        ...
    ]
  2. Create your first state machine in your model and migrate your db

    from django.db import models
    from river.models.fields.state import StateField
    
    class MyModel(models.Model):
        my_state_field = StateField()
  3. Create all your states on the admin page

  4. Create a workflow with your model ( MyModel - my_state_field ) information on the admin page

  5. Create your transition metadata within the workflow created earlier, source and destination states

  6. Create your transition approval metadata within the workflow created earlier and authorization rules along with their priority on the admin page

  7. Enjoy your django-river journey.

    my_model=MyModel.objects.get(....)
    
    my_model.river.my_state_field.approve(as_user=transactioner_user)
    my_model.river.my_state_field.approve(as_user=transactioner_user, next_state=State.objects.get(label='re-opened'))
    
    # and much more. Check the documentation

Hooking Up With The Events

django-river provides you to have your custom code run on certain events. And since version v2.1.0 this has also been supported for on the fly changes. You can create your functions and also the hooks to a certain events by just creating few database items. Let’s see what event types that can be hooked a function to;

  • An approval is approved

  • A transition goes through

  • The workflow is complete

For all these event types, you can create a hooking with a given function which is created separately and preliminary than the hookings for all the workflow objects you have or you will possible have, or for a specific workflow object. You can also hook up before or after the events happen.

1. Create Function

This will be the description of your functions. So you define them once and you can use them with multiple hooking up. Just go to /admin/river/function/ admin page and create your functions there. django-river function admin support python code highlights.

INSTALLED_APPS=[
    ...
    codemirror2
    river
    ...
]

Here is an example function;

from datetime import datetime

def handle(context):
    print(datetime.now())

Important: YOUR FUNCTION SHOULD BE NAMED AS handle. Otherwise django-river won’t execute your function.

django-river will pass a context down to your function in order for you to know why the function is triggered or for which object or so. And the context will look different for different type of events. Please see detailed context documentation to know more on what you would get from context in your functions.

You can find an advance function example on the link.

Create Function Page

2. Hook It Up

The hookings in django-river can be created both specifically for a workflow object or for a whole workflow. django-river comes with some model objects and admin interfaces which you can use to create the hooks.

  • To create one for whole workflow regardless of what the workflow object is, go to

    • /admin/river/onapprovedhook/ to hook up to an approval

    • /admin/river/ontransithook/ to hook up to a transition

    • /admin/river/oncompletehook/ to hook up to the completion of the workflow

  • To create one for a specific workflow object you should use the admin interface for the workflow object itself. One amazing feature of django-river is now that it creates a default admin interface with the hookings for your workflow model class. If you have already defined one, django-river enriches your already defined admin with the hooking section. It is default disabled. To enable it just define RIVER_INJECT_MODEL_ADMIN to be True in the settings.py.

Note: They can programmatically be created as well since they are model objects. If it is needed to be at workflow level, just don’t provide the workflow object column. If it is needed to be for a specific workflow object then provide it.

Here are the list of hook models;

  • OnApprovedHook

  • OnTransitHook

  • OnCompleteHook

Migrations

2.X.X to 3.0.0

django-river v3.0.0 comes with quite number of migrations, but the good news is that even though those are hard to determine kind of migrations, it comes with the required migrations out of the box. All you need to do is to run;

python manage.py migrate river

3.1.X to 3.2.X

django-river started to support Microsoft SQL Server 17 and 19 after version 3.2.0 but the previous migrations didn’t get along with it. We needed to reset all the migrations to have fresh start. If you have already migrated to version 3.1.X all you need to do is to pull your migrations back to the beginning.

python manage.py migrate --fake river zero
python manage.py migrate --fake river

FAQ

Have a look at FAQ

Contributors

Code Contributors

This project exists thanks to all the people who contribute :rocket: :heart:

https://opencollective.com/django-river/contributors.svg?width=890&button=false

Financial Contributors

Become a financial contributor and help us sustain our community. Contribute

Individuals

https://opencollective.com/django-river/individuals.svg?width=890

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. Contribute

https://opencollective.com/django-river/organization/0/avatar.svg

License

This software is licensed under the New BSD License. See the LICENSE file in the top distribution directory for the full license text.

Project details


Download files

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

Source Distribution

django-river-3.2.0.tar.gz (43.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_river-3.2.0-py2.py3-none-any.whl (62.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file django-river-3.2.0.tar.gz.

File metadata

  • Download URL: django-river-3.2.0.tar.gz
  • Upload date:
  • Size: 43.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.6.10

File hashes

Hashes for django-river-3.2.0.tar.gz
Algorithm Hash digest
SHA256 81259c0904bc0ebab4e30add5631dd95f7302167fd6980632f22e05faf373d2f
MD5 b75fd0cec7adda10e39ecb99f5e8af4d
BLAKE2b-256 ab318eefc24cb70b5c6ac50a86b9065f907bc1e84198ee1261af72d13dc7e0e6

See more details on using hashes here.

File details

Details for the file django_river-3.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: django_river-3.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 62.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.6.10

File hashes

Hashes for django_river-3.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1f8c08dff7e50800b7eb43fd345844293915e3eebbd2714659a2eca4303e798a
MD5 87d71f43a0707ce84a5834ba1cee272f
BLAKE2b-256 ab8245db31e5b6dde50ddc7f8ab256c5e507eeae4f6ba5e4fbc82a5b9922d480

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page