{
"info": {
"author": "Jonathan Slenders, Gert van Gool, Maarten Timmerman, Steven (rh0dium), Unleashed NV",
"author_email": "operations@unleashed.be",
"bugtrack_url": null,
"classifiers": [
"Environment :: Web Environment",
"Framework :: Django",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Programming Language :: Python"
],
"description": "Django States\n=============\n\n|Build Status|\n\nDescription\n-----------\n\nState engine for django models. Define a state graph for a model and\nremember the state of each object. State transitions can be logged for\nobjects.\n\nInstallation\n------------\n\n.. code:: sh\n\n pip install django-states2\n\nUsage example\n-------------\n\nTo use a state machine, you should add a state field to the model\n\n.. code:: python\n\n from django_states.fields import StateField\n from django_states.machine import StateMachine, StateDefinition, StateTransition\n\n class PurchaseStateMachine(StateMachine):\n log_transitions = True\n\n # possible states\n class initiated(StateDefinition):\n description = _('Purchase initiated')\n initial = True\n\n class paid(StateDefinition):\n description = _('Purchase paid')\n\n def handler(self, instance):\n code_to_execute_when_arriving_in_this_state()\n\n class shipped(StateDefinition):\n description = _('Purchase shipped')\n\n # state transitions\n class mark_paid(StateTransition):\n from_state = 'initiated'\n to_state = 'paid'\n description = 'Mark this purchase as paid'\n\n class ship(StateTransition):\n from_state = 'paid'\n to_state = 'shipped'\n description = 'Ship purchase'\n\n def handler(transition, instance, user):\n code_to_execute_during_this_transition()\n\n def has_permission(transition, instance, user):\n return true_when_user_can_make_this_transition()\n\n class Purchase(StateModel):\n purchase_state = StateField(machine=PurchaseStateMachine, default='initiated')\n ... (other fields for a purchase)\n\nIf ``log_transitions`` is enabled, another model is created. Everything\nshould be compatible with South\\_ for migrations.\n\nNote: If you're creating a ``DataMigration`` in\n`South `__, remember to use\n``obj.save(no_state_validation=True)``\n\nUsage example:\n\n.. code:: python\n\n p = Purchase()\n\n # Will automatically create state object for this purchase, in the\n # initial state.\n p.save()\n p.get_purchase_state_info().make_transition('mark_paid', request.user) # User parameter is optional\n p.state # Will return 'paid'\n p.get_purchase_state_info().description # Will return 'Purchase paid'\n\n # Returns an iterator of possible transitions for this purchase.\n p.get_purchase_state_info().possible_transitions()\n\n # Which can be used like this..\n [x.get_name() for x in p.possible_transitions]\n\nFor better transition control, override:\n\n- ``has_permission(self, instance, user)``: Check whether this user is\n allowed to make this transition.\n- ``handler(self, instance, user)``: Code to run during this\n transition. When an exception has been raised in here, the transition\n will not be made.\n\nGet all objects in a certain state::\n\n Purchase.objects.filter(state='initiated')\n\nValidation\n----------\n\nYou can add a test that needs to pass before a state transition can be\nexecuted. Well, you can add 2: one based on the current user\n(``has_permission``) and one generic (``validate``).\n\nSo on a ``StateTransition``-object you need to specify an extra\n``validate`` function (signature is ``validate(cls, instance)``). This\nshould yield ``TransitionValidationError``, this way you can return\nmultiple errors on that need to pass before the transition can happen.\n\nThe ``has_permission`` function (signature\n``has_permission(transition, instance, user)``) should check whether the\ngiven user is allowed to make the transition. E.g. a super user can\nmoderate all comments while other users can only moderate comments on\ntheir blog-posts.\n\nGroups\n------\n\nSometimes you want to group several states together, since for a certain\nview (or other content) it doesn't really matter which of the states it\nis. We support 2 different state groups, inclusive (only these) or\nexclusive (everything but these):\n\n.. code:: python\n\n class is_paid(StateGroup):\n states = ['paid', 'shipped']\n\n class is_paid(StateGroup):\n exclude_states = ['initiated']\n\nState graph\n-----------\n\nYou can get a graph of your states by running the ``graph_states``\nmanagement command.\n\n.. code:: sh\n\n python manage.py graph_states myapp.Purchase.state\n\nThis requires `graphviz `__ and python bindings for\ngraphviz: ``pygraphviz`` and ``yapgvb``.\n\n.. |Build Status| image:: https://travis-ci.org/vikingco/django-states2.svg?branch=fix%2F15403%2Fdebug-in_group-and-add-unittests\n :target: https://travis-ci.org/vikingco/django-states2",
"description_content_type": null,
"docs_url": null,
"download_url": "UNKNOWN",
"downloads": {
"last_day": -1,
"last_month": -1,
"last_week": -1
},
"home_page": "https://github.com/vikingco/django-states2",
"keywords": null,
"license": "BSD",
"maintainer": null,
"maintainer_email": null,
"name": "django-states2",
"package_url": "https://pypi.org/project/django-states2/",
"platform": "UNKNOWN",
"project_url": "https://pypi.org/project/django-states2/",
"project_urls": {
"Download": "UNKNOWN",
"Homepage": "https://github.com/vikingco/django-states2"
},
"release_url": "https://pypi.org/project/django-states2/1.6.10/",
"requires_dist": null,
"requires_python": null,
"summary": "State machine for django models",
"version": "1.6.10"
},
"last_serial": 2909394,
"releases": {
"1.6.10": [
{
"comment_text": "",
"digests": {
"md5": "ff2a8f17404bacc59642c637b916bab9",
"sha256": "866473e62ebbb0c1848adf4b1563b82a9ee75bde14c94f293807502156d37854"
},
"downloads": -1,
"filename": "django_states2-1.6.10-py2-none-any.whl",
"has_sig": false,
"md5_digest": "ff2a8f17404bacc59642c637b916bab9",
"packagetype": "bdist_wheel",
"python_version": "2.7",
"requires_python": null,
"size": 26632,
"upload_time": "2017-05-30T13:04:13",
"url": "https://files.pythonhosted.org/packages/08/27/0a75a4ff7afd34434664c1eba36522c594161b9f44d07784ada4725e09e4/django_states2-1.6.10-py2-none-any.whl"
},
{
"comment_text": "",
"digests": {
"md5": "9d7f5408f1c59ebe041c67d3d625324e",
"sha256": "367127203870c90dcc613b52b7a3a7ffabec86cabb2945ff941b11ff7eae22e9"
},
"downloads": -1,
"filename": "django-states2-1.6.10.tar.gz",
"has_sig": false,
"md5_digest": "9d7f5408f1c59ebe041c67d3d625324e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 19375,
"upload_time": "2017-05-30T13:04:06",
"url": "https://files.pythonhosted.org/packages/83/87/2668af768ad68f9b9791d1c1c984d291d60da236364ebb27af13d11d0bcc/django-states2-1.6.10.tar.gz"
}
],
"1.6.5": []
},
"urls": [
{
"comment_text": "",
"digests": {
"md5": "ff2a8f17404bacc59642c637b916bab9",
"sha256": "866473e62ebbb0c1848adf4b1563b82a9ee75bde14c94f293807502156d37854"
},
"downloads": -1,
"filename": "django_states2-1.6.10-py2-none-any.whl",
"has_sig": false,
"md5_digest": "ff2a8f17404bacc59642c637b916bab9",
"packagetype": "bdist_wheel",
"python_version": "2.7",
"requires_python": null,
"size": 26632,
"upload_time": "2017-05-30T13:04:13",
"url": "https://files.pythonhosted.org/packages/08/27/0a75a4ff7afd34434664c1eba36522c594161b9f44d07784ada4725e09e4/django_states2-1.6.10-py2-none-any.whl"
},
{
"comment_text": "",
"digests": {
"md5": "9d7f5408f1c59ebe041c67d3d625324e",
"sha256": "367127203870c90dcc613b52b7a3a7ffabec86cabb2945ff941b11ff7eae22e9"
},
"downloads": -1,
"filename": "django-states2-1.6.10.tar.gz",
"has_sig": false,
"md5_digest": "9d7f5408f1c59ebe041c67d3d625324e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 19375,
"upload_time": "2017-05-30T13:04:06",
"url": "https://files.pythonhosted.org/packages/83/87/2668af768ad68f9b9791d1c1c984d291d60da236364ebb27af13d11d0bcc/django-states2-1.6.10.tar.gz"
}
]
}