aoj-django-async-messages


Nameaoj-django-async-messages JSON
Version 0.3.2 PyPI version JSON
download
home_pagehttps://github.com/ygowill/django-async-messages
SummarySend asynchronous messages to users (eg from offline scripts). Useful for integration with Celery
upload_time2022-12-10 14:30:11
maintainer
docs_urlNone
authorDavid Winterbottom
requires_python
license
keywords
VCS
bugtrack_url
requirements Django django-nose nose pinocchio
Travis-CI
coveralls test coverage No coveralls.
            =====================
django-async-messages
=====================

Simple asynchronous messages for django.  Plays nicely with Celery.

Questions
=========

What problem does this solve?
-----------------------------

Suppose a user instigates an expensive task that you are processing offline (eg
using Celery).  This library provides a simple mechanism for notifying the user
when the task is finished, utilising Django's messaging framework.

What's an example?
------------------

You might use Celery to generate a large report and then employ this library to
notify the user that their report is ready to be downloaded.  The user will see
the message you've sent them when they make their next request after the message
is submitted.

How does it work?
-----------------

A cache is used to persist the messages, and middleware is used to pick these up
and submit them to `Django's messaging framework`_.  All very simple.

.. _`Django's messaging framework`: https://docs.djangoproject.com/en/dev/ref/contrib/messages/

Aren't there other libraries that do this?
------------------------------------------

Yes, there are - but they solve the problem in different ways:

* `django-offline-messages`_ - this provides an alternative storage backend that
  Django's messages framework can use.

* `django-notifications`_  

.. _`django-offline-messages`: https://github.com/dym/django-offline-messages
.. _`django-notifications`: https://github.com/jtauber/django-notification

What's good about this implementation?
--------------------------------------

* It's simple, fast and easy to use.  
* It works cohesively with existing Django cache and messages framework.  It
  will work no matter what cache backend your are using, and whatever storage
  backend is used for messages. 

What's bad?
-----------

* A user may miss the message if they navigating quickly between pages. But 
  this is a general problem of the Django messages framework.

Install
=======

From PyPI (stable)::

    pip install django-async-messages

From Github (unstable)::

    pip install git+git://github.com/codeinthehole/django-async-messages#egg=djang-async-messages

Add ``'async_messages.middleware.AsyncMiddleware'`` to your ``MIDDLEWARE_CLASSES``.
Ensure it comes after ``'django.contrib.messages.middleware.MessageMiddleware'``.

You need to have ``CACHES`` configured in you settings for this to work.  As usual,
memcache is the best choice.  Note that `local memory caching`_ is not suitable as
each process has its own private cache and a Celery task can't communicate with
the webserver process cache.

.. _`local memory caching`: https://docs.djangoproject.com/en/dev/topics/cache/#local-memory-caching

Use
===

Send a message to a single user::

    >>> from async_messages import message_user
    >>> from django.contrib.auth.models import User
    >>> barry = User.objects.get(username='barry')
    >>> message_user(barry, "Barry, your report is ready") 

Send a message to lots of users::

    >>> from async_messages import message_users
    >>> staff = User.objects.filter(is_staff=True)
    >>> message_users(staff, "All budgets must be spent by the end of the day")

Specify message level::

    >>> from django.contrib.messages import constants
    >>> message_users(staff, "Boom!", constants.WARNING)

Send multiple messages to a single user::

    >>> from async_messages import message_user
    >>> from django.contrib.auth.models import User
    >>> barry = User.objects.get(username='barry')
    >>> message_user(barry, "Barry, your report is queued up for processing") 
    >>> # do more awesome stuff
    >>> message_user(barry, "Barry, your report is ready") 

Alternative way to send a message to a single user, imitating the django.contrib.messages API::

    >>> from async_messages import messages
    >>> barry = User.objects.get(username='barry')
    >>> messages.debug(barry, "Barry was here")
    >>> messages.info(barry, "Hi, Barry")
    >>> messages.success(barry, "Barry, your report is ready")
    >>> messages.warning(barry, "Barry, you didn't lock your session")
    >>> messages.error(barry, "You are not Barry")

Contributing
============

Fork, clone and create a virtualenv.  Then run::

    make install

Run tests with::

    ./runtests.py

Please submit pull requests using 'develop' as the target branch.

License
=======

MIT_

.. _MIT: http://en.wikipedia.org/wiki/MIT_License

Changelog
=========

0.3.1
-----
* Fix bug around request instances that don't have a user attribute

0.3
---
* Mimic ``django.contrib.messages`` API for sending a message to a user

0.2
---
* Added possibility to queue multiple messages

0.1.2
-----
* Altered dependency on Django to be only 1.2+

0.1.1
-----
* Altered middleware to use ``process_response``.
* Better docstrings

0.1
---
* Minimum viable product

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ygowill/django-async-messages",
    "name": "aoj-django-async-messages",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "David Winterbottom",
    "author_email": "david.winterbottom@gmail.com",
    "download_url": "",
    "platform": null,
    "description": "=====================\ndjango-async-messages\n=====================\n\nSimple asynchronous messages for django.  Plays nicely with Celery.\n\nQuestions\n=========\n\nWhat problem does this solve?\n-----------------------------\n\nSuppose a user instigates an expensive task that you are processing offline (eg\nusing Celery).  This library provides a simple mechanism for notifying the user\nwhen the task is finished, utilising Django's messaging framework.\n\nWhat's an example?\n------------------\n\nYou might use Celery to generate a large report and then employ this library to\nnotify the user that their report is ready to be downloaded.  The user will see\nthe message you've sent them when they make their next request after the message\nis submitted.\n\nHow does it work?\n-----------------\n\nA cache is used to persist the messages, and middleware is used to pick these up\nand submit them to `Django's messaging framework`_.  All very simple.\n\n.. _`Django's messaging framework`: https://docs.djangoproject.com/en/dev/ref/contrib/messages/\n\nAren't there other libraries that do this?\n------------------------------------------\n\nYes, there are - but they solve the problem in different ways:\n\n* `django-offline-messages`_ - this provides an alternative storage backend that\n  Django's messages framework can use.\n\n* `django-notifications`_  \n\n.. _`django-offline-messages`: https://github.com/dym/django-offline-messages\n.. _`django-notifications`: https://github.com/jtauber/django-notification\n\nWhat's good about this implementation?\n--------------------------------------\n\n* It's simple, fast and easy to use.  \n* It works cohesively with existing Django cache and messages framework.  It\n  will work no matter what cache backend your are using, and whatever storage\n  backend is used for messages. \n\nWhat's bad?\n-----------\n\n* A user may miss the message if they navigating quickly between pages. But \n  this is a general problem of the Django messages framework.\n\nInstall\n=======\n\nFrom PyPI (stable)::\n\n    pip install django-async-messages\n\nFrom Github (unstable)::\n\n    pip install git+git://github.com/codeinthehole/django-async-messages#egg=djang-async-messages\n\nAdd ``'async_messages.middleware.AsyncMiddleware'`` to your ``MIDDLEWARE_CLASSES``.\nEnsure it comes after ``'django.contrib.messages.middleware.MessageMiddleware'``.\n\nYou need to have ``CACHES`` configured in you settings for this to work.  As usual,\nmemcache is the best choice.  Note that `local memory caching`_ is not suitable as\neach process has its own private cache and a Celery task can't communicate with\nthe webserver process cache.\n\n.. _`local memory caching`: https://docs.djangoproject.com/en/dev/topics/cache/#local-memory-caching\n\nUse\n===\n\nSend a message to a single user::\n\n    >>> from async_messages import message_user\n    >>> from django.contrib.auth.models import User\n    >>> barry = User.objects.get(username='barry')\n    >>> message_user(barry, \"Barry, your report is ready\") \n\nSend a message to lots of users::\n\n    >>> from async_messages import message_users\n    >>> staff = User.objects.filter(is_staff=True)\n    >>> message_users(staff, \"All budgets must be spent by the end of the day\")\n\nSpecify message level::\n\n    >>> from django.contrib.messages import constants\n    >>> message_users(staff, \"Boom!\", constants.WARNING)\n\nSend multiple messages to a single user::\n\n    >>> from async_messages import message_user\n    >>> from django.contrib.auth.models import User\n    >>> barry = User.objects.get(username='barry')\n    >>> message_user(barry, \"Barry, your report is queued up for processing\") \n    >>> # do more awesome stuff\n    >>> message_user(barry, \"Barry, your report is ready\") \n\nAlternative way to send a message to a single user, imitating the django.contrib.messages API::\n\n    >>> from async_messages import messages\n    >>> barry = User.objects.get(username='barry')\n    >>> messages.debug(barry, \"Barry was here\")\n    >>> messages.info(barry, \"Hi, Barry\")\n    >>> messages.success(barry, \"Barry, your report is ready\")\n    >>> messages.warning(barry, \"Barry, you didn't lock your session\")\n    >>> messages.error(barry, \"You are not Barry\")\n\nContributing\n============\n\nFork, clone and create a virtualenv.  Then run::\n\n    make install\n\nRun tests with::\n\n    ./runtests.py\n\nPlease submit pull requests using 'develop' as the target branch.\n\nLicense\n=======\n\nMIT_\n\n.. _MIT: http://en.wikipedia.org/wiki/MIT_License\n\nChangelog\n=========\n\n0.3.1\n-----\n* Fix bug around request instances that don't have a user attribute\n\n0.3\n---\n* Mimic ``django.contrib.messages`` API for sending a message to a user\n\n0.2\n---\n* Added possibility to queue multiple messages\n\n0.1.2\n-----\n* Altered dependency on Django to be only 1.2+\n\n0.1.1\n-----\n* Altered middleware to use ``process_response``.\n* Better docstrings\n\n0.1\n---\n* Minimum viable product\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Send asynchronous messages to users (eg from offline scripts).  Useful for integration with Celery",
    "version": "0.3.2",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "35b18d460990a640a79b86732728b2bf",
                "sha256": "692424ae1689aec35a9807be4c4e9a01dbe64aad3aacf20d53eeca4811ace424"
            },
            "downloads": -1,
            "filename": "aoj_django_async_messages-0.3.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "35b18d460990a640a79b86732728b2bf",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 5747,
            "upload_time": "2022-12-10T14:30:11",
            "upload_time_iso_8601": "2022-12-10T14:30:11.679101Z",
            "url": "https://files.pythonhosted.org/packages/03/ba/f5eb6174312ba7bb53add892027187ae64f1e85aa05824d4eb8efbc1016a/aoj_django_async_messages-0.3.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-10 14:30:11",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "ygowill",
    "github_project": "django-async-messages",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "Django",
            "specs": [
                [
                    "==",
                    "1.4"
                ]
            ]
        },
        {
            "name": "django-nose",
            "specs": [
                [
                    "==",
                    "1.1"
                ]
            ]
        },
        {
            "name": "nose",
            "specs": [
                [
                    "==",
                    "1.1.2"
                ]
            ]
        },
        {
            "name": "pinocchio",
            "specs": [
                [
                    "==",
                    "0.3.1"
                ]
            ]
        }
    ],
    "lcname": "aoj-django-async-messages"
}
        
Elapsed time: 0.01750s