Skip to main content

Django package that handles sending of notifications

Project description

UNICEF Notification

Notification is a library that provides handles sending of notifications.

Installation

pip install unicef-notification

Setup

Add unicef_notification to INSTALLED_APPS in settings:

INSTALLED_APPS = [
    ...
    'post_office',
    'unicef_notification',
]

Add POST_OFFICE configuration to settings:

POST_OFFICE = {
    'DEFAULT_PRIORITY': 'now',
    'BACKENDS': {
        'default': 'djcelery_email.backends.CeleryEmailBackend'
        }
}

Update TEMPLATES in settings by adding EmailTemplateLoader and marking APP_DIRS as False:

TEMPLATES = [
    ...
    'APP_DIRS': False,  # False because we set loaders manually below
    'OPTIONS': {
    'loaders': [
        'django.template.loaders.app_directories.Loader',
        'unicef_notification.loaders.EmailTemplateLoader',
    ],
    ...
    ]

Optional

If you want to override the notification template directory to be used:

UNICEF_NOTIFICATION_TEMPLATE_DIR = 'notifications'

This is the directory where notifcation templates are to be placed in your applications. These are loaded with the upload_notifications management command.

If you want to override the email template prefix:

UNICEF_NOTIFICATION_EMAIL_TEMPLATE_PREFIX = 'email-templates/'

Usage

Create notification template in defined UNICEF_NOTIFICATION_TEMPLATE_DIR from setup:

name = "<unique name for notification">
defaults = {
    "description": "Sample notification",
    "subject": "Subject of notification",
    "content": "Content of notification",
    "html_content": "Notificaton content in HTML format",
}

Update the notifications:

python manage.py update_notifications

Send notification with template:

from unicef_notification.utils import send_notification_with_template

context = {}
send_notification_with_template(
    ["to@example.com"],
    "<name-of-template>",
    context,
)

Send notification without a template:

from unicef_notification.utils import send_notification

send_notification(
    ["to@example.com"],
    subject="Subject of notification",
    content="Content of notification",
    html_content="Notification content in HTML format",
)

Contributing

Environment Setup

To install the necessary libraries:

$ make install

Coding Standards

See PEP 8 Style Guide for Python Code for complete details on the coding standards.

To run checks on the code to ensure code is in compliance:

$ make lint

Testing

Testing is important and tests are located in tests/ directory and can be run with:

$ make test

Coverage report is viewable in build/coverage directory, and can be generated with

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

unicef_notification-1.1.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

unicef_notification-1.1-py2.py3-none-any.whl (11.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file unicef_notification-1.1.tar.gz.

File metadata

  • Download URL: unicef_notification-1.1.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for unicef_notification-1.1.tar.gz
Algorithm Hash digest
SHA256 bb697a9f60cb9b26fd5fa7205a1c94ce8d20dbc472f251b8c5d4dd17bd52b948
MD5 fe61a5c8163610a3527c3f371d1588b8
BLAKE2b-256 75f70b0eb1c27de114a28730125caadf2da59714711d34bfb67605b655dec62a

See more details on using hashes here.

File details

Details for the file unicef_notification-1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: unicef_notification-1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for unicef_notification-1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5517a2d9f662f9e953df44369b80b1f532eaca471ab7bbef4a6cabc23ae24882
MD5 2c40922e986313c13d0add922a5bee72
BLAKE2b-256 328f64e166808734ecc668d1dd5c76e4aee5d69e78077d2e137f704ff04d4272

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