django-admin-workflow


Namedjango-admin-workflow JSON
Version 0.8.2 PyPI version JSON
download
home_pagehttps://github.com/esimorre/django-admin-workflow
SummaryA workflow app for django admin
upload_time2024-04-12 12:53:44
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licenseNone
keywords django workflow
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # django-admin-workflow
*example app workflow "vacation" (generated by django_admin_workflow and mermaid):*
![vacation_workflow](https://github.com/esimorre/django-admin-workflow/assets/697460/df2d079c-cfed-486d-bdb5-805b1fac9eea)

*Like a state-machine (Get on up !)*

An application for django that allows you to focus on data modeling,
data process and functionality without investing in the user interface
by taking advantage of the capabilities of the django admin application.

Functionality first, cosmetics and pretty panels can wait.

This application was designed to stay as close as possible to the spirit of contrib admin.

The goal is to add data security to CRUD through workflow: partitioning and management by roles

## Basic principles
Let's illustrate them by example
 * given
   * user1 belongs to the "Dept1" and "customers" groups
   * user2 belongs to the "Dept2" and "customers" groups
 * user2 sees nothing of the data created by user1
 * user1 can only do what the "customers" group allows
 * "Dept1" is a partition group (space)
 * "customers" is a role group.
 * these below no longer have a global scope (except for the superuser):
   * the "fields" and "read_onlyfields" attributes of model admin
   * the permissions on the model
   * it depends on the user role and status of the model instance.
 * the admin interface is no longer reserved for backend use, but also for
the end user interface
 
## Quick start
(First, it is advisable to follow the following in "dry run" mode and browsing the vacation application example).

1. Add "django_admin_workflow" to your INSTALLED_APPS setting like this::
```python
    INSTALLED_APPS = [
        "django_admin_workflow",
        ...,
    ]
```

2. Edit your project urls.py like this
```python
# admin.sites.site.index_title = "Welcome"
# admin.sites.site.site_title = "Django workflow"
# admin.sites.site.site_header = "Workflow pour Django"

urlpatterns = [
    path('', admin.site.urls),
]
```

3. Use BaseStateModel instead of models.ModelAdmin on the object to process
```python
from django_admin_workflow.models import BaseStateModel

class MyTestModel(BaseStateModel):
    a_field = models.XXXFields(...)
    ...
```

3. Similarly, use WorkflowModelAdmin instead of models.ModelAdmin

4. Run ``python manage.py migrate`` to create the models.

5. Run the gen_workflow_template command to help define the workflow
```bash
python manage.py gen_workflow_template -h
usage: manage.py gen_workflow_template [-m app_label.model_name] [options] [ > workflow.toml ]
Generate a .toml workflow template file on stdout
```

6. Edit the .toml file to define the workflow groups and roles, as in this example
```toml
# Group employees
[employees]
    filter = "lambda q, user_space, user: q.filter(space=user_space)"

    # création d'un objet dans le workflow
    [employees.creation]
        fields =  ['begin', 'end', 'comment']

    # Etat DRAFT
    [employees.DRAFT]
        fields =  ['begin', 'end', 'comment']
        actions = [ ["save",     "Save"],
                    ["submit",   "Submit", "check"],
                    ["cancel",   "Cancel",   "canceled"]]
# Group managers
[managers]
    filter = "lambda q, user_space, user: q.filter(space=user_space)"

    [managers.submited]
        fields =  ['begin', 'end', 'comment']
        readonly_fields = ['status']
        actions = [ ["approve",   "Approve", "approved"],
                    ["reject",   "Reject",   "rejected"]]

# autorun
[auto]
    [auto.check]
        actions = [ ['', 'insufficient balance', 'DRAFT'],
                    ['', '', 'submited']]

    [auto.approved]
        actions = [ ['', '', 'archived']]

    [auto.rejected]
    [auto.archived]
    [auto.fail_sent]
```

A view allows the graphical display of the workflow using the mermaid library:
```mermaid
---
title: Workflow
---
graph LR

    DRAFT["fa:fa-tag DRAFT<hr/>fa:fa-user-pen fa:fa-list<hr/>fa:fa-user-group employees"]

    check["fa:fa-tag check<hr/>fa:fa-gears auto"]

    canceled["fa:fa-tag canceled<hr/>fa:fa-trash-can "]

    submited["fa:fa-tag submited<hr/>fa:fa-user-pen fa:fa-list<hr/>fa:fa-user-group managers"]

    approved["fa:fa-tag approved<hr/>fa:fa-gears auto"]

    rejected["fa:fa-tag rejected<hr/>fa:fa-gears auto"]

    archived["fa:fa-tag archived<hr/>fa:fa-gears auto"]

    fail_sent["fa:fa-tag fail_sent<hr/>fa:fa-gears auto"]



    DRAFT -- Submit --> check

    DRAFT -- Cancel --> canceled

    submited -- Approve --> approved

    submited -- Reject --> rejected

    check -- insufficient balance --> DRAFT

    check --> submited

    approved --> archived
```

7. Use the import_workflow command to create the groups, permissions, status, roles
in the database from the workflow file (test it before with the --dry-run option)
```
python manage.py import_workflow -h 
usage: manage.py import_workflow workflow_file [-m app_label.model_name] [-d] [--dry-run] [options]
import a workflow definition file (see gen_workflow_template) to generate objects in db. This command generates groups and permissions.
```

8. Use the add_sample command to populate the database with pre-configured users and spaces
```
python manage.py add_sample -h
usage: manage.py add_sample [-a [username=admin [passwd=username]]]  [options]
Populate database with some sample data
```
The application should implement a data initialization function, typically in tests.create_data
(see application vacation).

9. Enter the workflow file on the model's admin class
```python
@admin.register(MyTestModel)
class MyTestModelAdmin(WorkflowModelAdmin):
    access_rules = get_workflow_data(__file__, file_data="workflow.toml")
    list_display = ...
```

10. Start the development server and visit the admin as super-user, browse the panel,
you will be able to configure the spaces (partitioning), statuses and roles.

11. log in as a regular user...and do your job :)

*Stay on the scene*

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/esimorre/django-admin-workflow",
    "name": "django-admin-workflow",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "django, workflow",
    "author": null,
    "author_email": null,
    "download_url": null,
    "platform": "any",
    "description": "# django-admin-workflow\r\n*example app workflow \"vacation\" (generated by django_admin_workflow and mermaid):*\r\n![vacation_workflow](https://github.com/esimorre/django-admin-workflow/assets/697460/df2d079c-cfed-486d-bdb5-805b1fac9eea)\r\n\r\n*Like a state-machine (Get on up !)*\r\n\r\nAn application for django that allows you to focus on data modeling,\r\ndata process and functionality without investing in the user interface\r\nby taking advantage of the capabilities of the django admin application.\r\n\r\nFunctionality first, cosmetics and pretty panels can wait.\r\n\r\nThis application was designed to stay as close as possible to the spirit of contrib admin.\r\n\r\nThe goal is to add data security to CRUD through workflow: partitioning and management by roles\r\n\r\n## Basic principles\r\nLet's illustrate them by example\r\n * given\r\n   * user1 belongs to the \"Dept1\" and \"customers\" groups\r\n   * user2 belongs to the \"Dept2\" and \"customers\" groups\r\n * user2 sees nothing of the data created by user1\r\n * user1 can only do what the \"customers\" group allows\r\n * \"Dept1\" is a partition group (space)\r\n * \"customers\" is a role group.\r\n * these below no longer have a global scope (except for the superuser):\r\n   * the \"fields\" and \"read_onlyfields\" attributes of model admin\r\n   * the permissions on the model\r\n   * it depends on the user role and status of the model instance.\r\n * the admin interface is no longer reserved for backend use, but also for\r\nthe end user interface\r\n \r\n## Quick start\r\n(First, it is advisable to follow the following in \"dry run\" mode and browsing the vacation application example).\r\n\r\n1. Add \"django_admin_workflow\" to your INSTALLED_APPS setting like this::\r\n```python\r\n    INSTALLED_APPS = [\r\n        \"django_admin_workflow\",\r\n        ...,\r\n    ]\r\n```\r\n\r\n2. Edit your project urls.py like this\r\n```python\r\n# admin.sites.site.index_title = \"Welcome\"\r\n# admin.sites.site.site_title = \"Django workflow\"\r\n# admin.sites.site.site_header = \"Workflow pour Django\"\r\n\r\nurlpatterns = [\r\n    path('', admin.site.urls),\r\n]\r\n```\r\n\r\n3. Use BaseStateModel instead of models.ModelAdmin on the object to process\r\n```python\r\nfrom django_admin_workflow.models import BaseStateModel\r\n\r\nclass MyTestModel(BaseStateModel):\r\n    a_field = models.XXXFields(...)\r\n    ...\r\n```\r\n\r\n3. Similarly, use WorkflowModelAdmin instead of models.ModelAdmin\r\n\r\n4. Run ``python manage.py migrate`` to create the models.\r\n\r\n5. Run the gen_workflow_template command to help define the workflow\r\n```bash\r\npython manage.py gen_workflow_template -h\r\nusage: manage.py gen_workflow_template [-m app_label.model_name] [options] [ > workflow.toml ]\r\nGenerate a .toml workflow template file on stdout\r\n```\r\n\r\n6. Edit the .toml file to define the workflow groups and roles, as in this example\r\n```toml\r\n# Group employees\r\n[employees]\r\n    filter = \"lambda q, user_space, user: q.filter(space=user_space)\"\r\n\r\n    # cr\u00c3\u00a9ation d'un objet dans le workflow\r\n    [employees.creation]\r\n        fields =  ['begin', 'end', 'comment']\r\n\r\n    # Etat DRAFT\r\n    [employees.DRAFT]\r\n        fields =  ['begin', 'end', 'comment']\r\n        actions = [ [\"save\",     \"Save\"],\r\n                    [\"submit\",   \"Submit\", \"check\"],\r\n                    [\"cancel\",   \"Cancel\",   \"canceled\"]]\r\n# Group managers\r\n[managers]\r\n    filter = \"lambda q, user_space, user: q.filter(space=user_space)\"\r\n\r\n    [managers.submited]\r\n        fields =  ['begin', 'end', 'comment']\r\n        readonly_fields = ['status']\r\n        actions = [ [\"approve\",   \"Approve\", \"approved\"],\r\n                    [\"reject\",   \"Reject\",   \"rejected\"]]\r\n\r\n# autorun\r\n[auto]\r\n    [auto.check]\r\n        actions = [ ['', 'insufficient balance', 'DRAFT'],\r\n                    ['', '', 'submited']]\r\n\r\n    [auto.approved]\r\n        actions = [ ['', '', 'archived']]\r\n\r\n    [auto.rejected]\r\n    [auto.archived]\r\n    [auto.fail_sent]\r\n```\r\n\r\nA view allows the graphical display of the workflow using the mermaid library:\r\n```mermaid\r\n---\r\ntitle: Workflow\r\n---\r\ngraph LR\r\n\r\n    DRAFT[\"fa:fa-tag DRAFT<hr/>fa:fa-user-pen fa:fa-list<hr/>fa:fa-user-group employees\"]\r\n\r\n    check[\"fa:fa-tag check<hr/>fa:fa-gears auto\"]\r\n\r\n    canceled[\"fa:fa-tag canceled<hr/>fa:fa-trash-can \"]\r\n\r\n    submited[\"fa:fa-tag submited<hr/>fa:fa-user-pen fa:fa-list<hr/>fa:fa-user-group managers\"]\r\n\r\n    approved[\"fa:fa-tag approved<hr/>fa:fa-gears auto\"]\r\n\r\n    rejected[\"fa:fa-tag rejected<hr/>fa:fa-gears auto\"]\r\n\r\n    archived[\"fa:fa-tag archived<hr/>fa:fa-gears auto\"]\r\n\r\n    fail_sent[\"fa:fa-tag fail_sent<hr/>fa:fa-gears auto\"]\r\n\r\n\r\n\r\n    DRAFT -- Submit --> check\r\n\r\n    DRAFT -- Cancel --> canceled\r\n\r\n    submited -- Approve --> approved\r\n\r\n    submited -- Reject --> rejected\r\n\r\n    check -- insufficient balance --> DRAFT\r\n\r\n    check --> submited\r\n\r\n    approved --> archived\r\n```\r\n\r\n7. Use the import_workflow command to create the groups, permissions, status, roles\r\nin the database from the workflow file (test it before with the --dry-run option)\r\n```\r\npython manage.py import_workflow -h \r\nusage: manage.py import_workflow workflow_file [-m app_label.model_name] [-d] [--dry-run] [options]\r\nimport a workflow definition file (see gen_workflow_template) to generate objects in db. This command generates groups and permissions.\r\n```\r\n\r\n8. Use the add_sample command to populate the database with pre-configured users and spaces\r\n```\r\npython manage.py add_sample -h\r\nusage: manage.py add_sample [-a [username=admin [passwd=username]]]  [options]\r\nPopulate database with some sample data\r\n```\r\nThe application should implement a data initialization function, typically in tests.create_data\r\n(see application vacation).\r\n\r\n9. Enter the workflow file on the model's admin class\r\n```python\r\n@admin.register(MyTestModel)\r\nclass MyTestModelAdmin(WorkflowModelAdmin):\r\n    access_rules = get_workflow_data(__file__, file_data=\"workflow.toml\")\r\n    list_display = ...\r\n```\r\n\r\n10. Start the development server and visit the admin as super-user, browse the panel,\r\nyou will be able to configure the spaces (partitioning), statuses and roles.\r\n\r\n11. log in as a regular user...and do your job :)\r\n\r\n*Stay on the scene*\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A workflow app for django admin",
    "version": "0.8.2",
    "project_urls": {
        "Bug Reports": "https://github.com/esimorre/django-admin-workflow/issues",
        "Homepage": "https://github.com/esimorre/django-admin-workflow",
        "Source": "https://github.com/esimorre/django-admin-workflow"
    },
    "split_keywords": [
        "django",
        " workflow"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "811eb9c348948712e07a686a48f0135d8a6825c7ab3486cfad9aa8fc24df9370",
                "md5": "4ef3868e1c6274ff2c9d8a7bc4fd0176",
                "sha256": "0a862f5b0aacbd0977fb82c36b3e08cde2e2fa463e2ed803373f2ee655ef1d86"
            },
            "downloads": -1,
            "filename": "django_admin_workflow-0.8.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4ef3868e1c6274ff2c9d8a7bc4fd0176",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 36028,
            "upload_time": "2024-04-12T12:53:44",
            "upload_time_iso_8601": "2024-04-12T12:53:44.880396Z",
            "url": "https://files.pythonhosted.org/packages/81/1e/b9c348948712e07a686a48f0135d8a6825c7ab3486cfad9aa8fc24df9370/django_admin_workflow-0.8.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-12 12:53:44",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "esimorre",
    "github_project": "django-admin-workflow",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "django-admin-workflow"
}
        
Elapsed time: 0.21615s