Skip to main content

A Django app to handle basic notifications.

Project description

Django Dans Notifications

Lint Test Types codecov

Python Versions Django Versions PyPI Version Downloads GitHub stars License Codacy grade Code style

Description

A Django app to handle notifications.

Support for basic notifications, push notifications, and email notifications.

Available on PyPi

Quick start

  1. Install the package via pip:
pip install django-dans-notifications
  1. Add "django_dans_notifications" to your INSTALLED_APPS setting like this:
INSTALLED_APPS = [
	...
	'django_dans_notifications',
]
  1. Include the URL configs in your project urls.py for the REST API endpoints like this:
path("api/notifications/", include("django_dans_notifications.urls")),
  1. Run python manage.py migrate to update your database schema.

  2. Use the API endpoints, in code or your Django admin portal.

Requirements

  • Python 3.8 or higher
  • Django 3.1 or higher
  • Django Rest Framework
    • NOTE: not only must you have this installed, you must have set DEFAULT_AUTHENTICATION_CLASSES and DEFAULT_PAGINATION_CLASS in your settings.py to work with the APIs properly. An example config would be:
REST_FRAMEWORK = {
    "DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination",
    "PAGE_SIZE": 20,
    "DEFAULT_AUTHENTICATION_CLASSES": (
        "rest_framework.authentication.TokenAuthentication",
    ),
}

Available Settings

Currently all available settings are optional:

  • TEAM_NAME - Default team name to use for emails, can be added to message context manually as well still.
  • IN_TEST - Whether running in tests or not. Used to determine whether to actually send email.

Add these to your settings.py file to customize the app's behavior like so:

TEAM_NAME = "My Team"
IN_TEST = True

Features

Models

  • NotificationEmail: Handles email notifications.
  • NotificationBasic: Handles basic notifications.
  • NotificationPush: Handles push notifications.

Managers

  • NotificationEmailManager: Handles sending and managing email notifications.
  • NotificationBasicManager: Handles basic notifications.
  • NotificationPushManager: Handles push notifications.

API ViewSets

  • NotificationEmailViewSet: API endpoints for email notifications.
  • NotificationBasicViewSet: API endpoints for basic notifications.
  • NotificationPushViewSet: API endpoints for push notifications.

Utility Classes

  • NotificationManager: Exposes common functionality and maintains object permissions.
    • Methods: get_notifications_push/email/basic/all, mark_notification_basic_read.

Usage

The main way to interact with this app is to create and use the appropriate models and their managers' methods as needed.

Also included is the NotificationManager class to expose some common functionality and maintain object permissions.

Some of its methods currently are:

  • get_notifications_push/email/basic/all
    • Enforce object ownership and notification 'direction'
  • mark_notification_basic_read

You can also interact directly, so for example to send an email notification:

from django_dans_notifications.models.notifications import NotificationEmail

email_notification = NotificationEmail.objects.send_email(
    subject="Hello",
    template="django-dans-emails/default.html",
    sender="sender@example.com",
    recipients=["recipient@example.com"],
    context={"user": "John Doe"},
    file_attachment=None
)

Docs

Model docs.

API docs.

Email Template docs.


https://danielnazarian.com
Copyright 2024 © Daniel Nazarian.

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-dans-notifications-1.2.1.tar.gz (26.6 kB view details)

Uploaded Source

Built Distribution

django_dans_notifications-1.2.1-py3-none-any.whl (38.6 kB view details)

Uploaded Python 3

File details

Details for the file django-dans-notifications-1.2.1.tar.gz.

File metadata

File hashes

Hashes for django-dans-notifications-1.2.1.tar.gz
Algorithm Hash digest
SHA256 b5ef6a232458e165658b407b9a26a324a0f6559a4c6fa20222dea1c98a44b62f
MD5 dc2d22fdd6fc9772a7b23904d19bef81
BLAKE2b-256 23d85ed3392cca6cecbc9f1bc5b3d35f16742982da90d7b22ca16ac8fc1ddd48

See more details on using hashes here.

File details

Details for the file django_dans_notifications-1.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_dans_notifications-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1b376764eeab98415c55db5fde1dc1a518e1a11afa244efa7cf630b2824e6cdd
MD5 688c0e58a95c473a3c3cba2cab95739a
BLAKE2b-256 aee5029c8fbd293e23738bc819de9b29b68dc43613c39b2d4ea095d619eb7c9c

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