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:
django-offline-messages - this provides an alternative storage backend that Django’s messages framework can use.
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
File details
Details for the file django-async-messages-0.1.tar.gz
.
File metadata
- Download URL: django-async-messages-0.1.tar.gz
- Upload date:
- Size: 2.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 076a972b7210e80501b032745b7d61091c2b1a8082be1de1e5e763aacd0518a4 |
|
MD5 | dbb560926b067d1e61d644c0f808a195 |
|
BLAKE2b-256 | 46e46b7df8eeaf61803d5b8d9e0d82f849775974503033cabe4b9835630bf4d4 |