{ "info": { "author": "Loren Davie", "author_email": "code@axilent.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 2 - Pre-Alpha", "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "Ahem\n====\n\nAhem is a notifications framework for Django projects, it uses\ndeclarative style just like Django models.\n\nInstalation\n===========\n\n::\n\n pip install Ahem\n\nAdd it to the list of installed apps in your settings file:\n\n.. code:: python\n\n # settings.py\n\n INSTALLED_APPS = (\n 'ahem',\n )\n\nIf you are using ``Celery``, configure the celery beat schedule variable\nso periodic tasks can run:\n\n.. code:: python\n\n # settings.py\n\n from ahem.loader import get_celery_beat_schedule\n CELERYBEAT_SCHEDULE = get_celery_beat_schedule()\n\n # you may add more periodic tasks after this:\n CELERYBEAT_SCHEDULE.update({\n 'other-task': {\n 'task': 'mytasks.the_taks',\n 'schedule': crontab(...),\n }\n })\n\nDocumentation\n=============\n\n| Ahem can be runned both with or without\n`celery `__. If the celery lib can be\nimported, it will try sending notifications asynchronously, else it will\nsend then in the same thread it was called.\n| Periodic notifications will not work without celery.\n\n| **Attention**\n| Sending notifications without celery may slow down your system, please\nbe careful.\n\nNotifications\n-------------\n\nTo define notifications, create a ``notifications.py`` file in any of\nthe installed apps of your project and create a class that extends ahem\n``Notification`` class.\n\n.. code:: python\n\n # my_django_app/notifications.py\n\n from datetime import timedelta\n from ahem.notification import Notification\n from ahem.scopes import QuerySetScope\n from ahem.triggers import DelayedTrigger\n\n class MyProjectNotification(Notification):\n name = 'my_project'\n\n scope = QuerySetScope()\n trigger = DelayedTrigger(timedelta(days=1))\n\n backends = ['email']\n templates = {\n 'default': 'path/to/template.html'}\n\n- ``name`` will be used as the id of your notification, it should be\n unique in your project.\n- ``scope`` defines which users will receive the notification.\n- ``trigger`` defines how and when the notification will be triggered.\n- ``backends`` is a list of available backend names for the\n notification.\n- ``templates`` dictionary with templates to be used for each backend.\n\nContext\n-------\n\nget\\_context\\_data(self, user, backend\\_name, \\*\\*kwargs):\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nYou can override ``get_context_data`` to add more variables to the\ncontext. ``User`` is added to context by default, remember to call\n``super`` if overriding.\n\n.. code:: python\n\n class TheNotification(Notification):\n ...\n def get_context_data(self, user, backend_name, **kwargs):\n kwargs = super(TheNotification, self).get_context_data(\n user, backend_name, **kwargs)\n kwargs['extra_context'] = 'This will be shown in the notification'\n return kwargs\n\nBackends\n--------\n\nCurrently, ``EmailBackend`` is the only backend available. Developers\nare encouraged to build new ones and merge then to this repository via\nPull Request.\n\nRegistering users in a backend\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nBefore sending a notification to a user using a specific backend, you\nneed to register it.\n\n.. code:: python\n\n from ahem.utils import register_user\n\n register_user('backend_name', user,\n setting1='username', setting2='secure_key')\n\nEmailBackend\n~~~~~~~~~~~~\n\n- name: ``email``\n- settings: no settings required. The ``User`` email will be used.\n\nContext data\n''''''''''''\n\n- ``subject`` will be used as the email subject.\n- ``from_email`` the email the message will be sent from, default is\n DEFAULT\\_FROM\\_EMAIL.\n- ``use_html`` if true, the email will be sent with html content type.\n\nScheduling a notification\n-------------------------\n\nUse the ``schedule`` method to trigger a notification. Use the\n``context`` kwarg to pass a context dictionary to the notification.\n\n.. code:: python\n\n # this will trigger the notification according to it's `trigger`\n # for the MyProjectNotification, it will wait 1 day before sending\n # the notification.\n MyProjectNotification.schedule(context={'some_param': 'value'})\n\nOverriding backends\n~~~~~~~~~~~~~~~~~~~\n\nYou can also limit the backends that will be used by passing a list to\nthe ``backends`` kwarg.\n\n**Since the EmailBackend is currently the only one available, this\nfeature is currently useless**\n\n.. code:: python\n\n MyProjectNotification.schedule(backends=['email'])\n\nOverriding trigger\n~~~~~~~~~~~~~~~~~~\n\nYou can also explicitly tell when the notification should be sent by\npassing ``delay_timedelta`` or ``eta``.\n\n.. code:: python\n\n # Notification will be sent at 23:45\n from celery.schedules import crontab\n MyProjectNotification.schedule(eta=crontab(crontab(hour=23, minute=45)))\n\n # Notification will be send 20 minutes after it was scheduled\n from datetime import timedelta\n MyProjectNotification.schedule(delay_timedelta=timedelta(minutes=20))\n\nScopes\n------\n\nScopes are a declarative way to select which users will receive the\nnotification when it's executed. Ahem comes with 2 scopes by default,\nbut if you are feeling adventurous you can build your onw one.\n\nQuerySetScope\n~~~~~~~~~~~~~\n\n``QuerySetScope`` will return all users if no argument is passed but you\ncan pass a queryset to filter only the ones you desire.\n\n.. code:: python\n\n from ahem.scopes import QuerySetScope\n\n class TheNotification(Notification):\n ...\n scope = QuerySetScope(User.objects.filter(is_staff=True))\n ...\n\nThis will scope the notification only to staff users.\n\nContextFilterScope\n~~~~~~~~~~~~~~~~~~\n\n``ContextFilterScope`` filters the ``User`` model according to a param\nspecified in the context passed to the notification when it's scheduled.\n\n.. code:: python\n\n from ahem.scopes import ContextFilterScope\n class TheNotification(Notification):\n ...\n scope = ContextFilterScope(\n context_key='user_is_admin', lookup_field='is_admin')\n ...\n\n # This will send the notification only to non admin users\n TheNotification.schedule(context={'user_is_admin': False})\n\nfilter\\_scope(self, queryset, context)\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nExtra filters can be performed in the ``Notification`` ``scope`` by\nadding a ``filter_scope`` method to your notification. This method\nshould return a list of ``User``\\ s\n\n.. code:: python\n\n # This will restrict the notification to users with `first_name` \"Camila\"\n class TheNotification(Notification):\n ...\n scope = QuerySetScope(User.objects.filter(is_staff=True))\n\n def filter_scope(self, queryset, context):\n return queryset.filter(first_name='Camila').all()\n\nTriggers\n--------\n\nTriggers define when notifications will be send. Currently the two types\nof triggers available are: ``DelayedTrigger`` and ``CalendarTrigger``,\nbut you can also write custom ones by extending ``NotificationTrigger``.\n\nDelayedTrigger\n~~~~~~~~~~~~~~\n\n``DelayedTrigger``\\ s should receive a timedelta as their first param.\nThis will specify how long should be waited before sending the\nnotification. If a timedelta is not specified, the notification will be\nimediately sent. You can optitionaly pass ``at_hour`` and/or\n``at_minute`` kwargs. By doing this, after timedelta is added to the\ncurrent time, the hour and minute will be overwriten to the ones you\nspecified.\n\n.. code:: python\n\n from datetime import timedelta\n from ahem.triggers import DelayedTrigger\n\n # Will send 2 days after scheduled at 18:00.\n class TheNotification(Notification):\n ...\n trigger = DelayedTrigger(timedelta(days=2), at_hour=18, at_minute=0)\n ...\n\nCalendarTrigger\n~~~~~~~~~~~~~~~\n\n``CalendarTrigger`` are periodic notifications, use ``Celery``\n``crontab`` to define it's periodicity. See ``Celery`` documentation for\nmore info:\nhttp://celery.readthedocs.org/en/latest/userguide/periodic-tasks.html#crontab-schedules\n\n.. code:: python\n\n from celery.schedules import crontab\n from ahem.triggers import CalendarTrigger\n\n # Will send notifications everyday at midnight\n class TheNotification(Notification):\n ...\n trigger = CalendarTrigger(crontab(hour=0, minute=0))\n ...\n\nTemplates\n---------\n\n``templates`` specify which template should be used to render\nnotification content. There should be at least a ``default`` template,\nbut you can specify a different one for each backend. When rendering the\ntemplate, all context variables will be available.\n\n.. code:: python\n\n class TheNotification(Notification):\n ...\n templates = {\n 'default': 'path/to/your/template.html',\n 'email': 'path/to/email/template.html'}\n\nTests\n-----\n\nUse ``tox`` to run tests.\n", "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/Axilent/Ahem", "keywords": null, "license": "BSD", "maintainer": null, "maintainer_email": null, "name": "Ahem", "package_url": "https://pypi.org/project/Ahem/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/Ahem/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/Axilent/Ahem" }, "release_url": "https://pypi.org/project/Ahem/0.2.1/", "requires_dist": null, "requires_python": null, "summary": "Simple, but rich, declarative notification framework for Django", "version": "0.2.1" }, "last_serial": 1717437, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "c433647df836f2e60f416d7d56c0d25b", "sha256": "42b32917f7834dc1e80dd14248c0d35a47d78d6cc25259cab7a4205cf5f4b391" }, "downloads": -1, "filename": "Ahem-0.1.tar.gz", "has_sig": false, "md5_digest": "c433647df836f2e60f416d7d56c0d25b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8765, "upload_time": "2015-06-22T20:46:03", "url": "https://files.pythonhosted.org/packages/03/ed/6e77b07701428a4f3d687a304716c9bc9538a56965857f97fe51a84e956f/Ahem-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "16dee901916ed44558a3a8c544acb357", "sha256": "a5d1a617d79f94bb62c40e457edc27b3348827a07a369c1c46e63f054dfb3e26" }, "downloads": -1, "filename": "Ahem-0.2.tar.gz", "has_sig": false, "md5_digest": "16dee901916ed44558a3a8c544acb357", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8873, "upload_time": "2015-09-08T18:56:25", "url": "https://files.pythonhosted.org/packages/5b/7b/9eeab6df5134cb971bfcec0ca1f18dd79fe9ed868eae118393d962737d4d/Ahem-0.2.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "cbd4ddf7166f648096c25b2f2a5ca2b9", "sha256": "8520250456747978d6519154734f6157eaa36f055c5f69b813e6f63ce73fedaf" }, "downloads": -1, "filename": "Ahem-0.2.1.tar.gz", "has_sig": false, "md5_digest": "cbd4ddf7166f648096c25b2f2a5ca2b9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9093, "upload_time": "2015-09-10T14:20:39", "url": "https://files.pythonhosted.org/packages/77/cf/e85e85a68e1dba4bff28d288e70a7f3dd68cbbf02b6fb1d9eae3ac057201/Ahem-0.2.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "cbd4ddf7166f648096c25b2f2a5ca2b9", "sha256": "8520250456747978d6519154734f6157eaa36f055c5f69b813e6f63ce73fedaf" }, "downloads": -1, "filename": "Ahem-0.2.1.tar.gz", "has_sig": false, "md5_digest": "cbd4ddf7166f648096c25b2f2a5ca2b9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9093, "upload_time": "2015-09-10T14:20:39", "url": "https://files.pythonhosted.org/packages/77/cf/e85e85a68e1dba4bff28d288e70a7f3dd68cbbf02b6fb1d9eae3ac057201/Ahem-0.2.1.tar.gz" } ] }