Offline addon for django.contrib.messages
Project description
django-user-messages adds offline messaging support to Django’s messaging framework. It achieves this by allowing to save messages in the database. The user_messages.api.get_messages utility and the user_messages.context_processors.messages context processor transparently concatenate Django’s messages and our own messages in a single list, therefore existing code works without any changes and without causing database writes. django-user-messages’ functions have to be used explicitly. I consider this a feature, not a bug.
Installation
Install django-user-messages using pip into your virtualenv.
Add user_messages to INSTALLED_APPS and run migrate.
Replace the default messages context processor with user_messages.context_processors.messages. The context processor provides both django.contrib.messages’ and django-user-messages’ messages.
Use user_messages.api as you would use django.contrib.messages except that you pass the user model or ID as first parameter, not the current request.
Usage
Pretty much the same as Django’s messaging framework:
from user_messages import api api.info(user, 'Hey there') api.warning(user, 'Stop this') api.error(user, 'Not nice!') # Passing the ID is also possible; the user instance does not # have to be instantiated at all: api.success(user.id, 'Yay!')
django-user-messages’ messages supports two additional features not available in Django’s messages framework:
Messages can be delivered more than once by passing deliver_once=False. These messages have to be acknowledged explicitly. django-user-messages does not contain any code to do this.
It is possible to attach additional data by passing a dictionary as meta:
api.debug(user, 'Oww', meta={ 'url': 'http://example.com', })
For convenience, our messages have the same tags and level_tag properties as Django’s messages. Meta properties are also accessible in templates:
{% if messages %} <ul class="messages"> {% for message in messages %} <li class="{{ message.tags }}".> {% if message.meta.url %}<a href="{{ message.meta.url }}">{% endif %} {{ message }} {% if message.meta.url %}</a>{% endif %} </li> {% endfor %} </ul> {% endif %}
django-user-messages’ messages are also evaluated lazily.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-user-messages-0.4.0.tar.gz
.
File metadata
- Download URL: django-user-messages-0.4.0.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9dbb775db15b8adcf5eeae9fbfc5ef4c8ba538501d3f42725114a2bf579613f7 |
|
MD5 | 9a97f3532cb68277629d412a205ddb3d |
|
BLAKE2b-256 | 0b29cc83e02b93a79740b28021cd0e328b6ea30dc8e7b36324052b7bee373402 |
File details
Details for the file django_user_messages-0.4.0-py2.py3-none-any.whl
.
File metadata
- Download URL: django_user_messages-0.4.0-py2.py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85d7068749f6a308f544213c9b3501438521411626d205c27441c460ac30d664 |
|
MD5 | 2f3a572ae2ec3ece9b8a686969a2f1da |
|
BLAKE2b-256 | 158f51f8ed6d7f25be9cf1e4ef5cb0f417697f19af72a327d115858184297fed |