Skip to main content

Wrapper around django.contrib.messages adding persistence.

Project description

# Persistent Messages-like Framework for Django

Persistent, dismissible, targeted, messages framework for Django apps

## STATUS

Alpha - pls do not use. This README is six years old.

## Background

Django messages are great for one-off notifications to users, but not
for persistent notification banners. From the [official
documentation](https://docs.djangoproject.com/en/1.11/ref/contrib/messages/)
on the Django messages framework:

> Quite commonly in web applications, you need to display a one-time
> notification message to the user after processing a form or some other
> types of user input. [...] The messages framework allows you to
> temporarily store messages in one request and retrieve them for
> display in a subsequent request (usually the next one).

These one-time messages are usually dynamic, created within a view
function, to alert the user to something that has just happened. This
project is designed to extend the pattern to support configurable and
persistent messages to users. The canonical use case for this is the EU
Cookie warning. This appears to everyone (logged in or not) until the
user explicitly dismiss it. It is not related to any specific action
that the user has taken (beyond visiting the site for the first time),
and it persists across all requests.

## Requirements

- Messages can be managed via the admin site
- The message can contain HTML (specifically href links)
- The message can be categorised (e.g. INFO | WARNING)
- The message can be targeted to appear to the following groups:
- All users (inc. anonymous)
- Authenticated users only
- Specific user groups only
- The message can be marked as dismissable
- The message can be enabled / disabled
- The message can expire (do not show after {{datetime}})
- Track message dismissals

## Use cases

- As the marketing team I would like to notify users of an event / activity
- As the tech team I would like to alert users to platform maintenance
- As the EU I would like to annoy people with a message about cookies

## Technical implementation

1. Print out all messages targeted at a user

```python
# live == enabled, not expired, not-dismissed, targeted at user
for m in PersistentMessage.objects.for_user(user).active():
print(m.message)
```

2. Display messages in a template using template context

```html
<body>
{% for m in persistent_messages %}
<div class="{{m.extra_tags}}">{{ m.message }}</div>
{% endfor %} ...
</body>
```

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_persistent_messages-0.4.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_persistent_messages-0.4-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file django_persistent_messages-0.4.tar.gz.

File metadata

  • Download URL: django_persistent_messages-0.4.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.3 Darwin/24.5.0

File hashes

Hashes for django_persistent_messages-0.4.tar.gz
Algorithm Hash digest
SHA256 0a6329633dd57ced8bb4158089a7481dbfd5176231c255fc1e4dbe1d45c3fae8
MD5 6a5cf70cca4fa32af17d1d6fdad316e7
BLAKE2b-256 6e85a37f253ecb2c17ef4354c52353f61cccc2fba8e70e0fc16ecd3dab3fc26c

See more details on using hashes here.

File details

Details for the file django_persistent_messages-0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for django_persistent_messages-0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c25f132549d0d0de0f42ff7d0d1981edf2418e857a06720872d346c0d7c187b8
MD5 7045adc3773d5ed4547e94697208f11d
BLAKE2b-256 59d7f1de8bb9be68fc0d8ec0b396ae436b8f8b62787099dd023c18343d8611f9

See more details on using hashes here.

Supported by

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