Skip to main content
Documentation Status https://badge.fury.io/py/django-nyt.svg https://codecov.io/github/django-wiki/django-nyt/coverage.svg?branch=main

Concept

django-nyt is a notification framework for Django. It does this:

from django_nyt.utils import notify

EVENT_KEY = "my_key"
notify(_("OMG! Something happened"), EVENT_KEY)

All users subscribing to "my_key" will have a notification created when notify() is called. How the notification is handled depends on the user’s settings.

If you have emails enabled, subscribers receive a summary of notifications immediately or at an interval of their choice.

Data can be accessed easily from Django models or from the included JSON views.

By using generic object relations, custom URLs, and custom email templates, you can expand your notification logic to create email messages that both marks the notification as read when clicking a link and at the same time redirects users to a final destination:

from django_nyt.utils import notify

product = product
EVENT_KEY = "product_is_in_stock"
notify(
    _(f"{product.name} is in stock"),
    EVENT_KEY,
    url=f"/products/{product.id}/",
    target_object=product
)

Roadmap

This project makes sense if people start using it and maturing it to their use-cases.

Here are some aspects that aren’t covered but are most welcome:

  • Support for async

  • Support for notifications through django-channels 4+

  • Support for HTML emails (and user setting)

Docs

https://django-nyt.readthedocs.io/en/latest/

Why should you do this?

Users need a cleverly sifted stream of events that’s highly customizable as well. By using django-nyt, your users can subscribe to global events or specific events pertaining specific objects.

Instead of inventing your own notification system, use this and you won’t have to design your own models, and you will have a nice guide that goes through the various steps of implementing notifications for your project.

Let’s try to summarize the reasons you want to be using django-nyt:

  • Simple API: call notify() where-ever you want.

  • CLI for sending emails (as cron job, daemon or Celery task)

  • Support for django-channels and Web Sockets (optional, fallback for JSON-based polling)

  • Basic JavaScript / HTML example code

  • Multi-lingual

  • Individual subscription settings for each type of event, for instance: - Event type A spawns instant email notifications, but Event B only gets emailed weekly.

  • Customizable intervals for which users can receive notifications

  • Optional URL for action target for each notification

  • Avoid clutter: Notifications don’t get repeated, instead a counter is incremented.

This project exists with django.contrib.messages in mind, to serve a simple, best-practice, scalable solution for notifications. There are loads of other notification apps for Django, some focus on integration of specific communication protocols

What do you need to do?

django-nyt does everything it can to meet as many needs as possible and have sane defaults.

But you need to do a lot! Firstly, you need to write some JavaScript that will fetch the latest notifications and display them in some area of the screen. Upon clicking that icon, the latest notifications are displayed, and clicking an individual notification will redirect the user through a page that marks the notification as read.

Something like this:

Javascript drop-down

JavaScript drop-down: Some examples are provided in the docs, but there is no real easy way to place this nifty little thing at the top of your site, you’re going to have to work it out on your own.

Other items for your TODO list:

  • Provide your users with options to customize their subscriptions and notification preferences. Create your own Form inheriting from django_nyt.forms.SettingsForm.

  • Customize contents of notification emails by overwriting templates in django_nyt/emails/notification_email_message.txt and django_nyt/emails/notification_email_subject.txt.

  • You can also have separate email templates per notification key. This includes using glob patterns. For instance, you can add this in your settings:

    NYT_EMAIL_TEMPLATE_NAMES = OrderedDict({
       "ADMIN_*": "myapp/notifications/email/admins.txt"
       "*": "myapp/notifications/email/default.txt"
    })
    NYT_EMAIL_TEMPLATE_SUBJECT_NAMES = OrderedDict({
       "ADMIN_*": "myapp/notifications/email/admins_subject.txt"
       "*": "myapp/notifications/email/default_subject.txt"
    })
  • Make the mail notification daemon script run either constantly python manage.py notifymail --daemon or with some interval by invoking python manage.py notifymail --cron as a cronjob. You can also call it from a Celery task or similar with call_command('notifymail', cron=True).

Development / demo project

In your Git fork, run pip install -r requirements.txt to install the requirements.

Install pre-commit hooks to verify your commits:

pip install pre-commit
pre-commit install

The folder test-project/ contains a pre-configured django project and an SQlite database. Login for django admin is admin:admin:

cd test-project
python manage.py runserver

After this, navigate to http://localhost:8000

Community

As many django-wiki users are also familiar with Django, please visit the channel #django-wiki on Libera. Click here for a web client <https://web.libera.chat/?channel=#django-wiki>`__).

Otherwise, use the Discussions tab on GitHub.

Metadata

Release files for django-nyt 1.6.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 django-nyt 1.6.0
File Size Uploaded
django_nyt-1.6.0.tar.gz 29.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-nyt 1.6.0
File Interpreter ABI Platform
django_nyt-1.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 72.5 kB

Release files / django_nyt-1.6.0.tar.gz

Download URL django_nyt-1.6.0.tar.gz
Size 29.7 kB
Tags Source
SHA-256 checksum
How to use checksums
8e3ca3d4bf6d91d6adfe10df6b0dc37b48e24cacd790fa93583c01c714cf931b
BLAKE2b-256 checksum
How to use checksums
e7cf1870466517ba4dba8c633d14c2419df30fddc7e89dbf8f765df9cae9b252
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.27.2

Release files / django_nyt-1.6.0-py3-none-any.whl

Download URL django_nyt-1.6.0-py3-none-any.whl
Size 42.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
530b7af9b2aafc17dc7da5aa82addaaf2793f2ec6a55a86913c6b9e69b8c1dc5
BLAKE2b-256 checksum
How to use checksums
6f85134f631b4ed3668c42609ce5505bd7ee729fda96c30cbf8c4e6b58204eff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.27.2

Release history Release notifications | RSS feed

This release

1.6.0 This release

2 release files

1.5.0

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4

2 release files

1.3

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2

2 release files

1.1.6

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1

2 release files

1.0

2 release files

0.9.9

2 release files

0.9.8

1 release file

0.9.7.1

0.9.7

1 release file

0.9.6

0.9.5

1 release file

0.9.4

1 release file

0.9.3

1 release file

0.9.2

1 release file

0.9.1

1 release file

0.9

1 release file

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