No project description provided
Project description
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_COLOR=<color> # 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:
{% NoticesModal %}
The modal will be shown. Once it has been dismissed it won't be shown again unless the notice version changes (see below) or the notice_seen
cookie is deleted.
Setting/updating the notice
via models and django admin
Add a Notice
instance in the django admin.
Notices have title
, content
, version
and optional 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.
To show a new notice, add another Notice instance with an incremented version number.
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 = ""
Set NOTICES_VERSION = 0
to clear the cookie and disable showing notices at all.
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
Built Distribution
Hashes for django_one_time_notices-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f15ba026aedccca69266a4d3ee4387c92cdb20d5808769b99517b1729b228a04 |
|
MD5 | 0f221c6d046ddc46d222861beebc5ad2 |
|
BLAKE2b-256 | 2b49ff3ade2bfd20a779452455d9eb658c5f08a1c7633cf8c01a7dc51541a42c |
Hashes for django_one_time_notices-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c37cbc332e87abe60e4ef7b78c74cffda250a2d036efdf78520fd78d776f3cd3 |
|
MD5 | b7d64c1d9f5ce63f815c9073dc3078fa |
|
BLAKE2b-256 | faba89ed4e079c32654a9932b35a2e1f9bb8a9149ec4190aba70c78b24cf2081 |