{ "info": { "author": "G Adventures", "author_email": "software@gadventures.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6" ], "description": "# django-dispatcher\n\n\nLogic engine for determining order of things to execute\n\n\nSometimes there's a series of things that must run in sequence. This is a\nconfiguration based approach enabling that.\n\n\nTypical Usage\n---\n\n\n1. Create some transition objects. They are basically Interfaces that\nrequire some methods and properties to be defined and reward you with\nsome context built at an appropriate time.\n\nThe required functions/params include:\n\t- final_state (String)\n\t- is_valid (Function returning Boolean)\n\t- context (Function returning Dict)\n\n```\n\nfrom dispatcher import Transition\n\n\nclass Cart2DayReminder(Transition):\n\n final_state = CART_2_DAY_REMINDER_SENT\n\n @property\n def onlinebooking(self):\n if self._onlinebooking is None:\n self._onlinebooking = OnlineBooking.objects.get(pk=self.resources['online_booking'])\n return self._onlinebooking\n _onlinebooking = None\n\n @property\n def profile(self):\n if self._profile is None:\n self._profile = self.onlinebooking.user and self.onlinebooking.user.profile\n return self._profile\n _profile = None\n\n def is_valid(self):\n\n if self.onlinebooking.date_updated < (datetime.now() - timedelta(days=2)):\n self.errors.append('The booking was created less than 2 days ago')\n return False\n\n return True\n\n def build_context(self):\n return {\n 'booking_id': self.onlinebooking.id,\n 'email_to': self.profile.email,\n }\n\n\nclass Cart1WeekReminder(Transition):\n\t...\n\n\n```\n\n2. Create a config, listing the transitions that can happen\n\n```\nDISPATCHER_CONFIG = {\n\t'chains': [\n\t\t{\n\t\t\t'chain_type': 'abandoned_cart',\n\t\t\t'transitions': {\n\t\t\t\tNEW: [Cart2DayReminder, Cart1WeekReminder],\n\t\t\t\tCart2DayReminder.final_state: [Cart1WeekReminder, ],\n\t\t\t\tCart1WeekReminder.final_state: [],\n\t\t\t}\n\t\t}\n\t]\n}\n\n```\n\n\n3. Initialize the dispatcher with the above settings. You'll have to\ndetermine the `chain_type` on your own. Its name must be the same as\nthe above config. We include the `requests_by` to keep track of where\nthe request originates from.\n\n\n```\n\nfrom dispatcher import Dispatcher\n\ndispatcher = Dispatcher(\n\tchain_type='abandoned_cart',\n\tchain_configs=DISPATCHER_CONFIG,\n\trequests_by='cart_abandonment_scripts'\n})\n\n```\n\n4. Provide the resources to query searching for a chain. The chain\nwill query using an `AND` statement, meaning all the resources must\nbe present when retrieving the chain.\n\n```\n\ndispatcher.get_or_create_chain([\n\t('online_booking', '123456'),\n\t('customer', '57844')\n])\n\n```\n\n5. Provide a callback for the chain. Should a chain transition to a new\nvalid state, whatever callback you pass will be sent on. The callback\ntakes the transition passed in and any callback arguments specified.\n\n```\n\ndef some_callback(transition, \\**callback_args):\n\t# so something magical\n\n\ndispatcher.execute_chain(callback=some_callback, callback_args={})\n\n```", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/gadventures/django-dispatcher", "keywords": "dispatcher", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "django-dispatcher", "package_url": "https://pypi.org/project/django-dispatcher/", "platform": "", "project_url": "https://pypi.org/project/django-dispatcher/", "project_urls": { "Homepage": "https://github.com/gadventures/django-dispatcher" }, "release_url": "https://pypi.org/project/django-dispatcher/0.1.1/", "requires_dist": null, "requires_python": "", "summary": "Python client for the G Adventures REST API", "version": "0.1.1" }, "last_serial": 4224174, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "c1991bbbd186e4d545fcb00f730aa873", "sha256": "02651c85b0c0bdc144ba07f6ef1d943061ea25803afd5953a49f4fbf7883623b" }, "downloads": -1, "filename": "django-dispatcher-0.1.0.tar.gz", "has_sig": false, "md5_digest": "c1991bbbd186e4d545fcb00f730aa873", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3501, "upload_time": "2018-08-29T21:31:17", "url": "https://files.pythonhosted.org/packages/5b/29/5e1fb89fd692a848b42de463d931f832ad2479f69584d0542b0132f912ba/django-dispatcher-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "aa6c052e2bea0e7ba2997526057f7752", "sha256": "5e68fa53e7d40ff5b6192f6d9561e8386720fee05f13bc3de6f1a8894edfb64c" }, "downloads": -1, "filename": "django-dispatcher-0.1.1.tar.gz", "has_sig": false, "md5_digest": "aa6c052e2bea0e7ba2997526057f7752", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5121, "upload_time": "2018-08-30T21:27:04", "url": "https://files.pythonhosted.org/packages/4a/93/070a89f705ff5738d94cb56f86aa01998e5de8eaf56959d5307f55c5e6db/django-dispatcher-0.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "aa6c052e2bea0e7ba2997526057f7752", "sha256": "5e68fa53e7d40ff5b6192f6d9561e8386720fee05f13bc3de6f1a8894edfb64c" }, "downloads": -1, "filename": "django-dispatcher-0.1.1.tar.gz", "has_sig": false, "md5_digest": "aa6c052e2bea0e7ba2997526057f7752", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5121, "upload_time": "2018-08-30T21:27:04", "url": "https://files.pythonhosted.org/packages/4a/93/070a89f705ff5738d94cb56f86aa01998e5de8eaf56959d5307f55c5e6db/django-dispatcher-0.1.1.tar.gz" } ] }