{ "info": { "author": "Red Panda Innovation Labs", "author_email": "nitish@redpanda.co.in", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python" ], "description": "Finite state machine field for plain old python objects (POPOs) (based on sqlalchemy-fsm)\n==============================================================\n\npopo-fsm adds declarative states management for plain old python objects (POPO).\nInstead of adding some state field to a POPO, and managing its\nvalues by hand, you could use a plain old python field and mark POPO methods\nwith the `transition` decorator. Your method will contain the side-effects\nof the state change.\n\nThe decorator also takes a list of conditions, all of which must be met\nbefore a transition is allowed.\n\nDefinition\n----------\n @transition('field_name', source='state1', target='state2')\n\nHere, 'field_name' is the name of the field/property/attribute which needs\nto change from 'state1' to 'state2'.\n\nThe `source` can also be a list of possible states/values from which the field\ncan move to the `target` state/value. e.g.\n\n @transition('field_name', source=['new', 'draft'], target='published')\n\nIn case the decorated method is called when the field value is not one of\nthose specified in `source`, a `TransitionNotAllowed` exception is thrown.\n\nExample\n-------\n\nAdd a plain old python field to your POPO\n from popo_fsm import transition\n\n class BlogPost(object):\n def __init__():\n self.state = 'new'\n\n\nUse the `transition` decorator to annotate POPO methods\n\n @transition('state', source='new', target='published')\n def publish(self):\n \"\"\"\n This function may contain side-effects, \n like updating caches, notifying users, etc.\n The return value will be discarded.\n \"\"\"\n\n`source` parameter accepts a list of states, or an individual state.\nYou can use `*` for source, to allow switching to `target` from any state.\n\nIf calling publish() succeeds without raising an exception, the state field\nwill be changed.\n\n from popo_fsm import can_proceed\n\n def publish_view(request, post_id):\n post = get_object__or_404(BlogPost, pk=post_id)\n if not can_proceed(post.publish):\n raise Http404;\n\n post.publish()\n post.save()\n return redirect('/')\n\n\nIf your given function requires arguments to validate, you need to include them\nwhen calling can_proceed as well as including them when you call the function\nnormally. Say publish() required a date for some reason:\n\n if not can_proceed(post.publish, the_date):\n raise Http404\n else:\n post.publish(the_date)\n\nIf you require some conditions to be met before changing state, use the\n`conditions` argument to `transition`. `conditions` must be a list of functions\nthat take one argument, the POPO instance. The function must return either\n`True` or `False` or a value that evaluates to `True` or `False`. If all\nfunctions return `True`, all conditions are considered to be met and transition\nis allowed to happen. If one of the functions return `False`, the transition\nwill not happen. These functions should not have any side effects.\n\nYou can use ordinary functions\n\n def can_publish(instance):\n # No publishing after 17 hours\n if datetime.datetime.now().hour > 17:\n return False\n return True\n\nOr POPO methods\n\n def can_destroy(self):\n return self.is_under_investigation()\n\nUse the conditions like this:\n\n @transition('state', source='new', target='published', conditions=[can_publish])\n def publish(self):\n \"\"\"\n Side effects galore\n \"\"\"\n\n @transition('state', source='*', target='destroyed', conditions=[can_destroy])\n def destroy(self):\n \"\"\"\n Side effects galore\n \"\"\"\n\n\nHow does popo-fsm diverge from sqlalchemy-fsm?\n------------------------------------------------\n\n* Works with POPOs, doesn't depend on sqlalchemy\n\n* Has no special support for sqlalchemy\n\n* Supports multiple state fields in a single object", "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/redpandalabs/popo-fsm", "keywords": null, "license": "MIT License", "maintainer": null, "maintainer_email": null, "name": "popo-fsm", "package_url": "https://pypi.org/project/popo-fsm/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/popo-fsm/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/redpandalabs/popo-fsm" }, "release_url": "https://pypi.org/project/popo-fsm/0.0.2/", "requires_dist": null, "requires_python": null, "summary": "Plain old python object finite state machine support.", "version": "0.0.2" }, "last_serial": 1569592, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "4b02dcfe9785e5670f6fab22662452b3", "sha256": "95811635cc47b13350ca1ac16bda3ef568474e96ff68d067ccf18c0e0bc0b699" }, "downloads": -1, "filename": "popo-fsm-0.0.1.tar.gz", "has_sig": false, "md5_digest": "4b02dcfe9785e5670f6fab22662452b3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3077, "upload_time": "2015-03-25T10:03:25", "url": "https://files.pythonhosted.org/packages/5c/7b/d748f685692528a12a17ca32b8adc7faac4f0136dfb030d1080a677788b1/popo-fsm-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "4ea5313931fb7b01e78685ffdc96d761", "sha256": "3509a6b43e0faf9cdbe243c4aa63ab408d8882d94285fbe7961748f5e6471b95" }, "downloads": -1, "filename": "popo-fsm-0.0.2.tar.gz", "has_sig": false, "md5_digest": "4ea5313931fb7b01e78685ffdc96d761", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3320, "upload_time": "2015-05-31T05:03:10", "url": "https://files.pythonhosted.org/packages/c7/08/70bd11b078bb0092fe24d18f74cb82bb29019236f2245db07cbb98fcf40d/popo-fsm-0.0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "4ea5313931fb7b01e78685ffdc96d761", "sha256": "3509a6b43e0faf9cdbe243c4aa63ab408d8882d94285fbe7961748f5e6471b95" }, "downloads": -1, "filename": "popo-fsm-0.0.2.tar.gz", "has_sig": false, "md5_digest": "4ea5313931fb7b01e78685ffdc96d761", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3320, "upload_time": "2015-05-31T05:03:10", "url": "https://files.pythonhosted.org/packages/c7/08/70bd11b078bb0092fe24d18f74cb82bb29019236f2245db07cbb98fcf40d/popo-fsm-0.0.2.tar.gz" } ] }