Skip to main content

Mezzanine Announcements

Workflow status PyPI version Python versions Follows: Semantic Versioning Code style: Black

A Mezzanine app to create and display site-wide announcements.

Features

  • Schedulable announcements (start and end datetimes)
  • Define as many announcement types as you want in settings
  • Make announcements optionally dismissable by the user
  • An announcement will not bother the user after they have dismissed it
  • Optionally make the announcement reappear after a set amount of days
  • Add an optional time delay after page load before showing an announcement

Installation

  1. Install via pip: pip install mezzanine-announcements

  2. Add to "announcements" to INSTALLED_APPS.

  3. Run migrations.

  4. Add "announcements.context_processors.announcements" to your context processors.

  5. Define the list of announcement templates that will be available for your admin users. This is a tuple of two-value tuples defined in settings.ANNOUNCEMENTS_TEMPLATES where the first element is the path to the Django template to be used, and the second element is the friendly name displayed in the admin for said template. For example:

    ANNOUNCEMENTS_TEMPLATES = (
        ("announcements/modal.html", "Modal"),
        ("announcements/top_bar.html", "Top bar"),
    )
    

    You need to create this templates yourself. An example is provided below.

  6. Add some announcements in the new "Announcements" section in the admin.

Then to display the announcements in your templates:

  1. Add the cookies and announcement scripts to the templates where you want to use the announcements

    <script src="{% static 'js/js.cookie.js' %}"></script>
    <script src="{% static 'js/announcements.js' %}"></script>
    
  2. Include the template with all announcements in a {% nevercache %} block:

    {% nevercache %}
    {% include "announcements/announcements.html" %}
    {% endnevercache %}
    

Templates

You can use any markup and styling you want in the announcement templates defined in settings.ANNOUNCEMENTS_TEMPLATES. You could use a Bootstrap modal, or simple horizontal bar on the top of your page. The only conditions that you need to keep in mind are the following:

  • The template must contain a single element of the class announcement.
  • The announcement ID, delay, and expiration must be present as data attributes on the .announcement element.
  • If the announcement is dismissable, you must include a clickable element with the class close-announcement as a child of .announcement.
{% load mezzanine_tags %}
<div
	class="announcement"
	data-appearance-delay="{{ announcement.appearance_delay }}"
	data-announcement-id="{{ announcement.id }}"
	data-expire-days="{{ announcement.expire_days }}"
>
	{{ announcement.content|richtext_filters|safe }}
	{% if announcement.can_dismiss %}
		<button class="close-announcement">Close</button>
	{% endif %}
</div>

Settings

Name Default value Description
ANNOUNCEMENTS_TEMPLATES None List of templates available for announcements. See Templates section above
ANNOUNCEMENTS_EXTRA_FIELDS None List of additional fields to display in the announcement admin: ["extra_content", "video_link", "form"]

Contributing

Review contribution guidelines at CONTRIBUTING.md.

Release files for mezzanine-announcements 3.3.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 mezzanine-announcements 3.3.0
File Size Uploaded
mezzanine-announcements-3.3.0.tar.gz 16.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mezzanine-announcements 3.3.0
File Interpreter ABI Platform
mezzanine_announcements-3.3.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 34.2 kB

Release files / mezzanine-announcements-3.3.0.tar.gz

Download URL mezzanine-announcements-3.3.0.tar.gz
Size 16.1 kB
Tags Source
SHA-256 checksum
How to use checksums
7a8d6f7f7b6d320f712584962af4cdfebf636a77da4b159be30444cac6bacd7f
BLAKE2b-256 checksum
How to use checksums
be83b4950181a3059701a05d46121f02cf343e906646df89d5408e40954b1f7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.12

Release files / mezzanine_announcements-3.3.0-py2.py3-none-any.whl

Download URL mezzanine_announcements-3.3.0-py2.py3-none-any.whl
Size 18.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
c6d467a2de841cc82db18fdcd3fd054fbb50288372325d2d923be1c12e023c18
BLAKE2b-256 checksum
How to use checksums
f1624999069a7acd944823254a9c132928b47d9a3ff5f5af1aa5a48eacc2b996
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.12

Release history Release notifications | RSS feed

This release

3.3.0 This release

2 release files

3.2.1

2 release files

3.2.0

2 release files

3.1.3

2 release files

3.1.2

2 release files

3.1.1

2 release files

3.1.0

2 release files

3.0.0

2 release files

2.0.0

2 release files

1.0.1

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