Pinax Announcements integration for Django Oscar dashboards
Project description
django-oscar-announcements
Staff-managed site-wide announcements for Django Oscar, built on top of pinax-announcements.
Features:
- Dashboard CRUD (Customers → Announcements)
- Info (blue) and Warning (red) levels that match Oscar/Bootstrap alert colours
- Extensible visibility — built-in Registered and Staff audiences; add your own (e.g. Verified)
- AJAX dismiss with no-JS form fallback
- Test button — preview an announcement on the public site without publishing it
- Re-send checkbox — clear dismissals so users see it again after an edit
- Auto-delete via django-background-tasks when an expiry date passes
Installation
pip install django-oscar-announcements # or install editable from source
1. INSTALLED_APPS
INSTALLED_APPS = [
...
"pinax.announcements", # required dependency
"oscar_announcements",
...
]
2. Context processor
Add to TEMPLATES[0]["OPTIONS"]["context_processors"]:
"oscar_announcements.context_processors.announcements",
This populates site_announcements in every template context.
3. Public dismiss URL
# urls.py
from django.urls import include, path
urlpatterns = [
...
path(
"announcements/",
include("oscar_announcements.urls", namespace="oscar_announcements"),
),
]
4. Oscar dashboard
Wire the CRUD views into your Oscar DashboardConfig:
# myapp/apps/dashboard/apps.py
from oscar.apps.dashboard.apps import DashboardConfig as OscarDashboardConfig
from django.urls import include, path
class DashboardConfig(OscarDashboardConfig):
def configure_permissions(self):
super().configure_permissions()
from oscar_announcements.dashboard.urls import permissions as ann_permissions
self.permissions_map.update(ann_permissions)
def get_urls(self):
from oscar_announcements.dashboard.urls import urlpatterns as ann_urls
return super().get_urls() + self.post_process_urls(ann_urls)
Add a nav entry (Customers section is index 3 in default Oscar navigation):
from django.utils.translation import gettext_lazy as _
OSCAR_DASHBOARD_NAVIGATION[3]["children"].append(
{"label": _("Announcements"), "url_name": "dashboard:announcement-list"}
)
5. Templates — render announcements
Load the tag in any base template and call {% render_announcements %}:
{% load oscar_announcements_tags %}
{# Public site (myco_layout.html, after flash messages): #}
{% render_announcements %}
{# Dashboard (e.g. inside {% block extrascripts %} or any layout block): #}
{% render_announcements %}
Add the JavaScript once (before </body>):
{% load static %}
<script src="{% static 'oscar_announcements/js/announcements.js' %}"></script>
Add the CSS (only needed on non-Bootstrap pages; Oscar dashboard gets colours from Bootstrap):
<link rel="stylesheet" href="{% static 'oscar_announcements/css/announcements.css' %}">
Extending visibility
Register custom audience handlers in your app's AppConfig.ready():
# myapp/apps.py
from oscar_announcements.visibility import register
from django.utils.translation import gettext_lazy as _
class MyAppConfig(AppConfig):
def ready(self):
register(
"verified",
_("Verified users"),
lambda user: getattr(user, "is_verified", False) or user.is_staff,
)
The new option then appears automatically in the dashboard form's Audience dropdown.
Template tags reference
{% load oscar_announcements_tags %}
# Render the built-in partial (oscar_announcements/partials/announcements.html):
{% render_announcements %}
# Assign the list to a variable for custom rendering:
{% get_announcements as my_announcements %}
{% for ann in my_announcements %}
<p class="oa-announcement--{{ ann.level }}">{{ ann.content }}</p>
{% endfor %}
Development
Setup:
git clone https://github.com/niccokunzmann/django-oscar-announcements
cd django-oscar-announcements
make dev
Run tests:
make test
Run the example:
cd example
make superuser # creates a superuser
make test # runs the tests
make run # runs the example
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_oscar_announcements-0.0.1.tar.gz.
File metadata
- Download URL: django_oscar_announcements-0.0.1.tar.gz
- Upload date:
- Size: 32.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
539c476bfeb544031937b33a224bd5d929c0aa2ea5c2a2420bb89f4a376d8b87
|
|
| MD5 |
11a72aa2526ce436d7f62cbad97574f1
|
|
| BLAKE2b-256 |
ac93165213db34dfe6f7e71b3ec8c10eefbbfac4a3144a59315b5fb171070dba
|
File details
Details for the file django_oscar_announcements-0.0.1-py3-none-any.whl.
File metadata
- Download URL: django_oscar_announcements-0.0.1-py3-none-any.whl
- Upload date:
- Size: 33.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c17919df5a6e59c3bf7e7496e0f634b0c62efe153cfcc5839bfa24ad7ce06dc
|
|
| MD5 |
9292fd1f3d7f89dd55da3827444f7cb5
|
|
| BLAKE2b-256 |
f644f447aaec65e4293222109f9e2c4285c6026f9f42f8ff20c53c8d88d1ea1e
|