Skip to main content

Send asynchronous messages to users

Project description

Simple asynchronous messages for django.

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.

For instance, you might use Celery to generate a large report and then use this library to notify the user that their report is ready to be downloaded.

How does it work?

A cache is used to persist the messages, and middleware is used to pick these up and add them to Django’s messages. All very simple.

Aren’t there other libraries that do this?

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

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 INSTALLED_APPS. Ensure it comes after django.contrib.messages.middleware.MessageMiddleware.

You need to have a cache set up in you settings for this to work. As usual, memcache is the best choice.

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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-async-messages-0.1.tar.gz (2.6 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page