django-fsm-2-admin


Namedjango-fsm-2-admin JSON
Version 2.0.1 PyPI version JSON
download
home_pagehttps://github.com/coral-li/django-fsm-2-admin
SummaryIntegrate django-fsm-2 state transitions into the django admin
upload_time2024-07-11 06:42:28
maintainerNone
docs_urlNone
authorCoral.li
requires_pythonNone
licenseMIT
keywords django fsm admin
VCS
bugtrack_url
requirements Django django-fsm-2
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # django-fsm-2-admin

Mixin and template tags to integrate [django-fsm-2](https://github.com/pfouque/django-fsm-2) state transitions into the Django Admin.

> [!IMPORTANT]
> This project is a fork of [django-fsm-admin](https://github.com/gadventures/django-fsm-admin), actively maintained and enhanced. 
> It utilizes [django-fsm-2](https://github.com/pfouque/django-fsm-2) for state transitions in the Django Admin interface.

# Installation

```bash
pip install django-fsm-2-admin
```

Or from GitHub:

```bash
pip install -e git://github.com/coral-li/django-fsm-2-admin.git#egg=django-fsm-2-admin
```

# Usage

1. Add ``fsm_admin`` to your ``INSTALLED_APPS``.

2. In your ``admin.py`` file, use ``FSMTransitionMixin`` to add behaviour to your ModelAdmin. ``FSMTransitionMixin`` should be before ``ModelAdmin``, the order is important.

It assumes that your workflow state field is named ``state``, however you can override it or add additional workflow state fields with the attribute ``fsm_field``.

```python
from fsm_admin.mixins import FSMTransitionMixin

class YourModelAdmin(FSMTransitionMixin, admin.ModelAdmin):
      # The name of one or more FSMFields on the model to transition
      fsm_field = ['wf_state',]

admin.site.register(YourModel, YourModelAdmin)
```

3. By adding ``custom=dict(admin=False)`` to the transition decorator, one can disallow a transition to show up in the admin interface. This specially is useful, if the transition method accepts parameters without default values, since in **django-fsm-2-admin** no arguments can be passed into the transition method.

```python
@transition(
   field='state',
   source=['startstate'],
   target='finalstate',
   custom=dict(admin=False),
)
def do_something(self, param):
   # will not add a button "Do Something" to your admin model interface
```

By adding ``FSM_ADMIN_FORCE_PERMIT = True`` to your configuration settings, the above restriction becomes the default. Then one must explicitly allow that a transition method shows up in the admin interface.

```python
@transition(
      field='state',
      source=['startstate'],
      target='finalstate',
      custom=dict(admin=True),
)
def proceed(self):
      # will add a button "Proceed" to your admin model interface
```

This is useful, if most of your state transitions are handled by other means, such as external events communicating with the API of your application.

# Try the example

```bash
git clone git@github.com:coral-li/django-fsm-2-admin.git
cd django-fsm-2-admin
uv venv
source .venv/bin/activate
uv pip install -r requirements-dev.txt
python setup.py develop
cd example
python manage.py migrate
python manage.py createsuperuser --username admin
python manage.py runserver
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/coral-li/django-fsm-2-admin",
    "name": "django-fsm-2-admin",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "django fsm admin",
    "author": "Coral.li",
    "author_email": "dev@coral.li",
    "download_url": "https://files.pythonhosted.org/packages/2e/5b/eadda5a2715b7facb8b045b966441c44b63fe371e3e2d05733ae556e8d08/django_fsm_2_admin-2.0.1.tar.gz",
    "platform": "any",
    "description": "# django-fsm-2-admin\n\nMixin and template tags to integrate [django-fsm-2](https://github.com/pfouque/django-fsm-2) state transitions into the Django Admin.\n\n> [!IMPORTANT]\n> This project is a fork of [django-fsm-admin](https://github.com/gadventures/django-fsm-admin), actively maintained and enhanced. \n> It utilizes [django-fsm-2](https://github.com/pfouque/django-fsm-2) for state transitions in the Django Admin interface.\n\n# Installation\n\n```bash\npip install django-fsm-2-admin\n```\n\nOr from GitHub:\n\n```bash\npip install -e git://github.com/coral-li/django-fsm-2-admin.git#egg=django-fsm-2-admin\n```\n\n# Usage\n\n1. Add ``fsm_admin`` to your ``INSTALLED_APPS``.\n\n2. In your ``admin.py`` file, use ``FSMTransitionMixin`` to add behaviour to your ModelAdmin. ``FSMTransitionMixin`` should be before ``ModelAdmin``, the order is important.\n\nIt assumes that your workflow state field is named ``state``, however you can override it or add additional workflow state fields with the attribute ``fsm_field``.\n\n```python\nfrom fsm_admin.mixins import FSMTransitionMixin\n\nclass YourModelAdmin(FSMTransitionMixin, admin.ModelAdmin):\n      # The name of one or more FSMFields on the model to transition\n      fsm_field = ['wf_state',]\n\nadmin.site.register(YourModel, YourModelAdmin)\n```\n\n3. By adding ``custom=dict(admin=False)`` to the transition decorator, one can disallow a transition to show up in the admin interface. This specially is useful, if the transition method accepts parameters without default values, since in **django-fsm-2-admin** no arguments can be passed into the transition method.\n\n```python\n@transition(\n   field='state',\n   source=['startstate'],\n   target='finalstate',\n   custom=dict(admin=False),\n)\ndef do_something(self, param):\n   # will not add a button \"Do Something\" to your admin model interface\n```\n\nBy adding ``FSM_ADMIN_FORCE_PERMIT = True`` to your configuration settings, the above restriction becomes the default. Then one must explicitly allow that a transition method shows up in the admin interface.\n\n```python\n@transition(\n      field='state',\n      source=['startstate'],\n      target='finalstate',\n      custom=dict(admin=True),\n)\ndef proceed(self):\n      # will add a button \"Proceed\" to your admin model interface\n```\n\nThis is useful, if most of your state transitions are handled by other means, such as external events communicating with the API of your application.\n\n# Try the example\n\n```bash\ngit clone git@github.com:coral-li/django-fsm-2-admin.git\ncd django-fsm-2-admin\nuv venv\nsource .venv/bin/activate\nuv pip install -r requirements-dev.txt\npython setup.py develop\ncd example\npython manage.py migrate\npython manage.py createsuperuser --username admin\npython manage.py runserver\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Integrate django-fsm-2 state transitions into the django admin",
    "version": "2.0.1",
    "project_urls": {
        "Homepage": "https://github.com/coral-li/django-fsm-2-admin"
    },
    "split_keywords": [
        "django",
        "fsm",
        "admin"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "54b09f00005a97ba91c80e160be742ebe93454cae9cd52a6fa85102f52d8732c",
                "md5": "777bbcef10c10901142658c8d07b655a",
                "sha256": "7649b7b4f4e7d88cab7d608c5e35a732014c9bd1efc2a0598a24813e444b3dae"
            },
            "downloads": -1,
            "filename": "django_fsm_2_admin-2.0.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "777bbcef10c10901142658c8d07b655a",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 14509,
            "upload_time": "2024-07-11T06:42:26",
            "upload_time_iso_8601": "2024-07-11T06:42:26.160898Z",
            "url": "https://files.pythonhosted.org/packages/54/b0/9f00005a97ba91c80e160be742ebe93454cae9cd52a6fa85102f52d8732c/django_fsm_2_admin-2.0.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2e5beadda5a2715b7facb8b045b966441c44b63fe371e3e2d05733ae556e8d08",
                "md5": "b5b3b11676bbca202ed1d4b6c8cb6556",
                "sha256": "da7abef3721e2d79b0a4fb27a94706d2bfcddf6c343d1481646e4a9c5fa43c62"
            },
            "downloads": -1,
            "filename": "django_fsm_2_admin-2.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "b5b3b11676bbca202ed1d4b6c8cb6556",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 10574,
            "upload_time": "2024-07-11T06:42:28",
            "upload_time_iso_8601": "2024-07-11T06:42:28.245084Z",
            "url": "https://files.pythonhosted.org/packages/2e/5b/eadda5a2715b7facb8b045b966441c44b63fe371e3e2d05733ae556e8d08/django_fsm_2_admin-2.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-11 06:42:28",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "coral-li",
    "github_project": "django-fsm-2-admin",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "Django",
            "specs": [
                [
                    ">=",
                    "4.2"
                ]
            ]
        },
        {
            "name": "django-fsm-2",
            "specs": [
                [
                    ">=",
                    "3.0.0"
                ]
            ]
        }
    ],
    "lcname": "django-fsm-2-admin"
}
        
Elapsed time: 0.28001s