Skip to main content

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_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:

{% NoticesModal %} 

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 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 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.

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.

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_one_time_notices-0.1.2.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

django_one_time_notices-0.1.2-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file django_one_time_notices-0.1.2.tar.gz.

File metadata

  • Download URL: django_one_time_notices-0.1.2.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.3 Linux/5.15.0-76-generic

File hashes

Hashes for django_one_time_notices-0.1.2.tar.gz
Algorithm Hash digest
SHA256 daa0100cef9a5c6b901d87aeefc523c6682df1d6e4c4ab6cb839f1d6e19a0f88
MD5 4fc663d082106b5266c992d198549fa0
BLAKE2b-256 cbf39f5d5ccef74fd6400572be6da04dfd6473170f5b465b5300af17967eacc6

See more details on using hashes here.

File details

Details for the file django_one_time_notices-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_one_time_notices-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c77d5be19894296f57e1f439ae0cac5c7e61cf3808cf154b14f83a70fa9194dd
MD5 24a19e55f82100775b5bebd4d761e980
BLAKE2b-256 3b63799b75bac72db3448040a6a0f5426992216bcd8d80ed14935889aefe94b9

See more details on using hashes here.

Supported by

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