Skip to main content

django-one-time-notices

Displays a modal with notice content if a user hasn't seen it yet.

Install

pip install django-one-time-notices

Settings

Add to INSTALLED_APPS:

django.contrib.auth
django.contrib.admin
...
notices

Add to TEMPLATES['OPTIONS']:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                ...
                'django.core.context_processors.request'
                ...
                'notices.context_processors.notices',
            ]
        }
    }
]

To customise the notice colour (button and title border), add

NOTICES_COLOUR=<colour>  # any css-acceptable colour

Static assets

Add notices/css/notices.css and notices/js/notices.js to your markup.

Usage

In templates, load the tags:

{% load notices_tags %}

and add the modal:

{% notices_modal %} 

The modal will be shown. Once it has been dismissed it won't be shown again unless the notice version changes (see below), the notice_seen cookie is deleted, or the notice timeout is reached.

Setting/updating the notice

via models and django admin

Add a Notice instance in the django admin.

Notices have title, content, version and optional timeout_seconds, starts_at and expires_at fields.

Version can be any positive number; it defaults to incrementing the last version number. Set the expires_at datetime to avoid showing this notice after the specified date, even if the user has never seen/dismissed it. Set the starts_at datetime to avoid showing the notice until a particular date/time.

Note that only the notice with the latest version will be shown. If the latest version has not started yet, a previous version will not be shown, even if it hasn't expired.

Set the timeout_seconds to set a cookie timeout; this means the notice will be reshown.

To show a new notice, add another Notice instance with an incremented version number.

configure settings

NOTICES_COLOUR: Change the colour of the popup with any css colour NOTICES_SAFE: Mark notices content as safe - allow any arbitrary html. Default False.

via django settings

Override the Notice model by adding to your settings.py: NOTICES_VERSION # an integer NOTICES_TITLE # optional, default = "New!" NOTICES_CONTENT # optional, default = "" NOTICES_TIMEOUT_SECONDS # optional, default = None

Set NOTICES_VERSION = 0 to clear the cookie and disable showing notices at all.

Metadata

Release files for django-one-time-notices 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-one-time-notices 1.0.0
File Size Uploaded
django_one_time_notices-1.0.0.tar.gz 9.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-one-time-notices 1.0.0
File Interpreter ABI Platform
django_one_time_notices-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 24.1 kB

Release files / django_one_time_notices-1.0.0.tar.gz

Download URL django_one_time_notices-1.0.0.tar.gz
Size 9.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7eb3b55dda0aea6f4589d58815f4e980927f948239d4db879cb92141e2fbee10
BLAKE2b-256 checksum
How to use checksums
5c13a94b1be8359e865a60c80cda143349832f104308a1a9b129161c478d09f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.11.6 Darwin/23.1.0

Release files / django_one_time_notices-1.0.0-py3-none-any.whl

Download URL django_one_time_notices-1.0.0-py3-none-any.whl
Size 14.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
32efb1c5e9997a411ff1391707689d8fbfad51e656ebc76206457e92922a5221
BLAKE2b-256 checksum
How to use checksums
92b091d3ae392fd12e4a128d10312744299ceace2924fe66d0ca03db97015696
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.11.6 Darwin/23.1.0

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page