Skip to content


Repository files navigation

OpenWISP Notifications

CI build status

Test Coverage

Dependency monitoring


Pypi Version


code style: black

OpenWISP Notifications provides email and web notifications for OpenWISP.

Its main goal is to allow the other OpenWISP modules to notify users about meaningful events that happen in their network.

For a more complete overview of the OpenWISP modules and architecture, see the OpenWISP Architecture Overview.

Table of Contents:

Available features

Installation instructions

Install stable version from pypi

Install from pypi:

pip install openwisp-notifications

Install development version

Install tarball:

pip install

Alternatively, you can install via pip using git:

pip install -e git+git://

Installing for development

We use Redis as celery broker (you can use a different broker if you want). The recommended way for development is running it using Docker so you will need to install docker and docker-compose beforehand.

In case you prefer not to use Docker you can install Redis from your repositories, but keep in mind that the version packaged by your distribution may be different.

Install SQLite:

sudo apt install sqlite3 libsqlite3-dev openssl libssl-dev

Fork and clone the forked repository:

git clone git://<your_fork>/openwisp-notifications

Navigate into the cloned repository:

cd openwisp-notifications/

Setup and activate a virtual-environment. (we'll be using virtualenv)

python -m virtualenv env
source env/bin/activate

Upgrade the following base python packages:

pip install -U pip wheel setuptools

Install development dependencies:

pip install -e .
pip install -r requirements-test.txt
npm install -g jslint stylelint

Start Redis using docker-compose:

docker-compose up -d

Create a database:

cd tests/
./ migrate
./ createsuperuser

Launch the development server:

./ runserver

You can access the admin interface at

Run celery worker (separate terminal window is needed):

# (cd tests)
celery -A openwisp2 worker -l info

Run tests with:

# run qa checks

# standard tests

# tests for the sample app

# If you running tests on PROD environment
./ --exclude skip_prod

When running the last line of the previous example, the environment variable SAMPLE_APP activates the sample app in /tests/openwisp2/ which is a simple django app that extends openwisp-notifications with the sole purpose of testing its extensibility, for more information regarding this concept, read the following section.

Setup (integrate into an existing Django project)

INSTALLED_APPS in should look like the following:

Note: openwisp_utils.admin_theme and django.contrib.admin should always follow openwisp_notifications in INSTALLED_APPS as shown in the example above. It might result in undesired behavior otherwise, e.g. notification bell not being shown on admin site.

Add notification_api_settings context processor:

Add routes for websockets:

Configure caching (you may use a different cache storage if you want):

Configure celery:

Configure celery beat:

Note: You will only need to add CELERY_BEAT_SCHEDULE setting if you want automatic deletion of old notifications. Please read Scheduled deletion of notifications section to learn more about this feature.

If you decide to use redis (as shown in these examples), make sure the python dependencies are installed in your system:

pip install redis django-redis


Configure channel layers (you may use a different channel layer):

While development, you can configure it to localhost as shown below:

Run migrations

./ migrate

Note: Running migrations is also required for creating notification settings apart from creating database schema.

Sending notifications

Notifications can be created using the notify signal. Eg:

The above code snippet creates and sends a notification to all users belonging to the Operators group if they have opted-in to receive notifications. Non-superusers receive notifications only for organizations which they are a member of.

Note: If recipient is not provided, it defaults to all superusers. If the target is provided, users of same organization of the target object are added to the list of recipients given that they have staff status and opted-in to receive notifications.

The complete syntax for notify is:

Note: Since openwisp-notifications uses django-notifications under the hood, usage of the notify signal has been kept unaffected to maintain consistency with django-notifications. You can learn more about accepted parameters from django-notifications documentation.

Additional notify keyword arguments

Parameter Description

Sets subject of email notification to be sent.

Defaults to the notification message.


Adds a URL in the email text, eg:

For more information see <url>.

Defaults to None, meaning the above message would not be added to the email text.


Set values of other parameters based on registered notification types

Defaults to None meaning you need to provide other arguments.

Web Notifications

Openwisp Notifications send a web notification to the recipients through django's admin site. Following are the components which allows browsing web notifications:

Notification Widget

A javascript widget has been added to make consuming notifications easy for users. The notification widget provides following features:

  • A minimalistic UI to help getting things done quickly.
  • Dynamically loading notifications with infinite scrolling to prevent unnecessary network requests.
  • Option to filter unread notifications.
  • Option to mark all notifications as read on a single click.

Notification Toasts

A notification toast delivers notifications at real-time. This allows users to read notifications without even opening the notification widget. A notification bell is also played to alert each time a notification is displayed through notification toast.

Email Notifications

Along with web notifications OpenWISP Notifications also sends email notifications leveraging the openwisp-utils send_email feature.

Notification Cache

In a typical OpenWISP installation, actor, action_object and target objects are same for a number of notifications. To optimize database queries, these objects are cached using Django's cache framework. The cached values are updated automatically to reflect actual data from database. You can control the duration of caching these objects using OPENWISP_NOTIFICATIONS_CACHE_TIMEOUT setting.

Cache invalidation

The function register_notification_cache_update can be used to register a signal of a model which is being used as an actor, action_object and target objects. As these values are cached for the optimization purpose so their cached values are need to be changed when they are changed. You can register any signal you want which will delete the cached value. To register a signal you need to include following code in your

Note: You need to import register_notification_cache_update inside the ready function or you can define another funtion to register signals which will be called in ready and then it will be imported in this function. Also dispatch_uid is unique identifier of a signal. You can pass any value you want but it needs to be unique. For more details read preventing duplicate signals section of Django documentation

Notification Types

OpenWISP Notifications simplifies configuring individual notification by using notification types. You can think of a notification type as a template for notifications.

These properties can be configured for each notification type:

Property Description
level Sets level attribute of the notification.
verb Sets verb attribute of the notification.
verbose_name Sets display name of notification type.
message Sets message attribute of the notification.
email_subject Sets subject of the email notification.
message_template Path to file having template for message of the notification.
email_notification Sets preference for email notifications. Defaults to True.
web_notification Sets preference for web notifications. Defaults to True.

Overrides the default URL used for the actor object.

You can pass a static URL or a dotted path to a callable which returns the object URL.


Overrides the default URL used for the action object.

You can pass a static URL or a dotted path to a callable which returns the object URL.


Overrides the default URL used for the target object.

You can pass a static URL or a dotted path to a callable which returns the object URL.

Note: A notification type configuration should contain atleast one of message or message_template settings. If both of them are present, message is given preference over message_template.

Note: The callable for actor_link, action_object_link and target_link should have the following signature:

Defining message_template

You can either extend default message template or write your own markdown formatted message template from scratch. An example to extend default message template is shown below.

# In templates/your_notifications/
{% extends 'openwisp_notifications/' %}
{% block body %}
    [{{ }}]({{ notification.target_link }}) has malfunctioned.
{% endblock body %}

Note: You can access all attributes of the notification using notification variables in your message template as shown above. Additional attributes actor_link, action_link and target_link are also available for providing hyperlinks to respective object.

Note: After writing code for registering or unregistering notification types, it is recommended to run database migrations to create notification settlings for these notification types.

Registering / Unregistering Notification Types

OpenWISP Notifications provides registering and unregistering notifications through utility functions openwisp_notifications.types.register_notification_type and openwisp_notifications.types.unregister_notification_type. Using these functions you can register or unregister notification types from your code.


This function is used to register a new notification type from your code.


Parameter Description
type_name A str defining name of the notification type.
type_config A dict defining configuration of the notification type.
models An optional list of models that can be associated with the notification type.

An example usage has been shown below.

Note: It will raise ImproperlyConfigured exception if a notification type is already registered with same name(not to be confused with verbose_name).

Note: You can use site and notification variables while defining message and email_subject configuration of notification type. They refer to objects of django.contrib.sites.models.Site and openwisp_notifications.models.Notification respectively. This allows you to use any of their attributes in your configuration. Similarly to message_template, message property can also be formatted using markdown.


This function is used to unregister a notification type from anywhere in your code.


Parameter Description
type_name A str defining name of the notification type.

An example usage is shown below.

Note: It will raise ImproperlyConfigured exception if the concerned notification type is not registered.

Passing extra data to notifications

If needed, additional data, not known beforehand, can be included in the notification message.

A perfect example for this case is an error notification, the error message will vary depending on what has happened, so we cannot know until the notification is generated.

Here's how to do it:

Then in the application code:

Note: It is recommended that all notification types are registered or unregistered in ready method of your Django application's AppConfig.

Notification Preferences


OpenWISP Notifications allows users to select their preferred way of receiving notifications. Users can choose from web or email notifications. These settings have been categorized over notification type and organization, therefore allowing users to only receive notifications from selected organization or notification type.

Notification settings are automatically created for all notification types and organizations for all users. While superusers can add or delete notification settings for everyone, staff users can only modify their preferred ways for receiving notifications. With provided functionality, users can choose to receive both web and email notifications or only web notifications. Users can also stop receiving notifications by disabling both web and email option for a notification setting.

Note: If a user has not configured their email or web preference for a particular notification setting, then email_notification or web_notification option of concerned notification type will be used respectively.

Deleting Notification Preferences

Deleting the notification preferences is an advanced option. Users should turn off web and email notifications instead of deleting notification preferences. Deleted notification preferences may be re-created automatically if the system needs it.

Silencing notifications for specific objects temporarily or permanently


OpenWISP Notifications allows users to silence all notifications generated by specific objects they are not interested in for a desired period of time or even permanently, while other users will keep receiving notifications normally.

Using the widget on an object's admin change form, a user can disable all notifications generated by that object for a day, week, month or permanently.

Note: This feature requires configuring "OPENWISP_NOTIFICATIONS_IGNORE_ENABLED_ADMIN" to enable the widget in the admin section of the required models.

Scheduled deletion of notifications

OpenWISP Notifications provides a celery task to automatically delete notifications older than a pre-configured number of days. In order to run this task periodically, you will need to configure CELERY_BEAT_SCHEDULE setting as shown in setup instructions.

The celery task takes only one argument, i.e. number of days. You can provide any number of days in args key while configuring CELERY_BEAT_SCHEDULE setting.

E.g., if you want notifications older than 10 days to get deleted automatically, then configure CELERY_BEAT_SCHEDULE as follows:

Please refer to "Periodic Tasks" section of Celery's documentation to learn more.



type str
default Any domain defined in ALLOWED_HOST

This setting defines the domain at which API and Web Socket communicate for working of notification widget.

Note: You don't need to configure this setting if you don't host your API endpoints on a different sub-domain.

If your root domain is and API and Web Socket are hosted at, then configure setting as follows:

This feature requires you to allow CORS on your server. We use django-cors-headers module to easily setup CORS headers. Please refer django-core-headers' setup documentation.

Configure django-cors-headers settings as follows:

Configure Django's settings as follows:

Please refer to Django's settings documentation for more information on SESSION_COOKIE_DOMAIN and CSRF_COOKIE_DOMAIN settings.


type str
default notification_bell.mp3 < \ openwisp_notifications/static/openwisp-notifications/audio/notification_bell.mp3>

This setting defines notification sound to be played when notification is received in real-time on admin site.

Provide a relative path (hosted on your webserver) to audio file as show below.


type int
default 172800 (2 days, in seconds)

It sets the number of seconds the notification contents should be stored in the cache. If you want cached notification content to never expire, then set it to None. Set it to 0 if you don't want to store notification contents in cache at all.






This setting enables the widget which allows users to silence notifications for specific objects temporarily or permanently. in the change page of the specified ModelAdmin classes.

E.g., if you want to enable the widget for objects of openwisp_users.models.User model, then configure the setting as following:


type bool
default True

This setting allows to disable creating notification preferences on running migrations.


When the system starts creating a lot of notifications because of a general network outage (e.g.: a power outage, a global misconfiguration), the notification storm prevention mechanism avoids the constant displaying of new notification alerts as well as their sound, only the notification counter will continue updating periodically, although it won't emit any sound or create any other visual element until the notification storm is over.

This setting allows tweaking how this mechanism works.

The default configuration is as follows:



Raised when notification properties(email or message) cannot be rendered from concerned notification type. It sub-classes Exception class.

It can be raised due to accessing non-existing keys like missing related objects in email or message setting of concerned notification type.


Live documentation


A general live API documentation (following the OpenAPI specification) is available at /api/v1/docs/.

Browsable web interface


Additionally, opening any of the endpoints listed below directly in the browser will show the browsable API interface of Django-REST-Framework, which makes it even easier to find out the details of each endpoint.


See openwisp-users: authenticating with the user token.

When browsing the API via the Live documentation or the Browsable web interface, you can use the session authentication by logging in the django admin.


The list endpoint support the page_size parameter that allows paginating the results in conjunction with the page parameter.

GET /api/v1/notifications/notification/?page_size=10
GET /api/v1/notifications/notification/?page_size=10&page=2

List of endpoints

Since the detailed explanation is contained in the Live documentation and in the Browsable web page of each endpoint, here we'll provide just a list of the available endpoints, for further information please open the URL of the endpoint in your browser.

List user's notifications

GET /api/v1/notifications/notification/

Available Filters

You can filter the list of notifications based on whether they are read or unread using the unread parameter.

To list read notifications:

GET /api/v1/notifications/notification/?unread=false

To list unread notifications:

GET /api/v1/notifications/notification/?unread=true

Mark all user's notifications as read

POST /api/v1/notifications/notification/read/

Get notification details

GET /api/v1/notifications/notification/{pk}/

Mark a notification read

PATCH /api/v1/notifications/notification/{pk}/

Delete a notification

DELETE /api/v1/notifications/notification/{pk}/

List user's notification setting

GET /api/v1/notifications/notification/user-setting/

Available Filters

You can filter the list of user's notification setting based on their organization_id.

GET /api/v1/notifications/notification/user-setting/?organization={organization_id}

You can filter the list of user's notification setting based on their organization_slug.

GET /api/v1/notifications/notification/user-setting/?organization_slug={organization_slug}

You can filter the list of user's notification setting based on their type.

GET /api/v1/notifications/notification/user-setting/?type={type}

Get notification setting details

GET /api/v1/notifications/notification/user-setting/{pk}/

Update notification setting details

PATCH /api/v1/notifications/notification/user-setting/{pk}/

List user's object notification setting

GET /api/v1/notifications/notification/ignore/

Get object notification setting details

GET /api/v1/notifications/notification/ignore/{app_label}/{model_name}/{object_id}/

Create object notification setting

PUT /api/v1/notifications/notification/ignore/{app_label}/{model_name}/{object_id}/

Delete object notification setting

DELETE /api/v1/notifications/notification/ignore/{app_label}/{model_name}/{object_id}/

Management Commands


This command will populate notification preferences for all users for organizations they are member of.

Example usage:

# cd tests/
./ populate_notification_preferences

Note: Before running this command make sure that the celery broker is running and reachable by celery workers.


This command will create a dummy notification with default notification type for the members of default organization. This command is primarily provided for the sole purpose of testing notification in development only.

Example usage:

# cd tests/
./ create_notification

Extending openwisp-notifications

One of the core values of the OpenWISP project is Software Reusability, for this reason OpenWISP Notifications provides a set of base classes which can be imported, extended and reused to create derivative apps.

In order to implement your custom version of openwisp-notifications, you need to perform the steps described in the rest of this section.

When in doubt, the code in test project and sample_notifications will guide you in the correct direction: just replicate and adapt that code to get a basic derivative of openwisp-notifications working.

Premise: if you plan on using a customized version of this module, we suggest to start with it since the beginning, because migrating your data from the default module to your extended version may be time consuming.

1. Initialize your custom module

The first thing you need to do in order to extend openwisp-notifications is create a new django app which will contain your custom version of that openwisp-notifications app.

A django app is nothing more than a python package (a directory of python scripts), in the following examples we'll call this django app as mynotifications but you can name it how you want:

django-admin startapp mynotifications

Keep in mind that the command mentioned above must be called from a directory which is available in your PYTHON_PATH so that you can then import the result into your project.

Now you need to add mynotifications to INSTALLED_APPS in your, ensuring also that openwisp_notifications has been removed:

For more information about how to work with django projects and django apps, please refer to the django documentation.

2. Install openwisp-notifications

Install (and add to the requirement of your project) openwisp-notifications:

pip install -U


Add the following to your

4. Add openwisp_utils.staticfiles.DependencyFinder

Add openwisp_utils.staticfiles.DependencyFinder to STATICFILES_FINDERS in your

5. Add openwisp_utils.loaders.DependencyLoader

Add openwisp_utils.loaders.DependencyLoader to TEMPLATES in your

6. Inherit the AppConfig class

Please refer to the following files in the sample app of the test project:

For more information regarding the concept of AppConfig please refer to the "Applications" section in the django documentation.

7. Create your custom models

For the purpose of showing an example, we added a simple "details" field to the models of the sample app in the test project.

You can add fields in a similar way in your file.

Note: For doubts regarding how to use, extend or develop models please refer to the "Models" section in the django documentation.

8. Add swapper configurations

Add the following to your

9. Create database migrations

Create and apply database migrations:

./ makemigrations
./ migrate

For more information, refer to the "Migrations" section in the django documentation.

10. Create your custom admin

Refer to the file of the sample app.

To introduce changes to the admin, you can do it in two main ways which are described below.

Note: For more information regarding how the django admin works, or how it can be customized, please refer to "The django admin site" section in the django documentation.

1. Monkey patching

If the changes you need to add are relatively small, you can resort to monkey patching.

For example:

2. Inheriting admin classes

If you need to introduce significant changes and/or you don't want to resort to monkey patching, you can proceed as follows:

11. Create root URL configuration

Please refer to the file in the test project.

For more information about URL configuration in django, please refer to the "URL dispatcher" section in the django documentation.

12. Create root routing configuration

Please refer to the file in the test project.

For more information about URL configuration in django, please refer to the "Routing" section in the Channels documentation.

13. Create

Please refer to the file in the test project.

For more information about the usage of celery in django, please refer to the "First steps with Django" section in the celery documentation.

14. Import Celery Tasks

Add the following in your to import celery tasks from openwisp_notifications app.

15. Register Template Tags

If you need to use template tags of openwisp_notifications, you will need to register as shown in "templatetags/" of sample_notifications.

For more information about template tags in django, please refer to the "Custom template tags and filters" section in the django documentation.

16. Register Notification Types

You can register notification types as shown in the section for registering notification types.

A reference for registering a notification type is also provided in sample_notifications/ The registered notification type of sample_notifications app is used for creating notifications when an object of TestApp model is created. You can use sample_notifications/ as reference for your implementation.

17. Import the automated tests

When developing a custom application based on this module, it's a good idea to import and run the base tests too, so that you can be sure the changes you're introducing are not breaking some of the existing feature of openwisp-notifications.

In case you need to add breaking changes, you can overwrite the tests defined in the base classes to test your own behavior.

See the tests of the sample_notifications to find out how to do this.

Note: Some tests will fail if templatetags and admin/base.html are not configured properly. See preceeding sections to configure them properly.

Other base classes that can be inherited and extended

The following steps are not required and are intended for more advanced customization.

API views

The API view classes can be extended into other django applications as well. Note that it is not required for extending openwisp-notifications to your app and this change is required only if you plan to make changes to the API views.

Create a view file as done in sample_notifications/

For more information regarding Django REST Framework API views, please refer to the "Generic views" section in the Django REST Framework documentation.

Web Socket Consumers

The Web Socket Consumer classes can be extended into other django applications as well. Note that it is not required for extending openwisp-notifications to your app and this change is required only if you plan to make changes to the consumers.

Create a consumer file as done in sample_notifications/

For more information regarding Channels' Consumers, please refer to the "Consumers" section in the Channels documentation.


Please read the OpenWISP contributing guidelines.




See OpenWISP Support Channels.



Icons used are taken from Font Awesome project.



Notification sound is taken from Notification Sounds.

LICENSE: Creative Commons Attribution license