Skip to main content

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

Metadata

Release files for unicef-notification 1.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for unicef-notification 1.4.1
File Size Uploaded
unicef_notification-1.4.1.tar.gz 7.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for unicef-notification 1.4.1
File Interpreter ABI Platform
unicef_notification-1.4.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 19.3 kB

Release files / unicef_notification-1.4.1.tar.gz

Download URL unicef_notification-1.4.1.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
1f430684a1ba65f9f8f97e0b17f6b40869e28415bf1c83459e824b3815e7722f
BLAKE2b-256 checksum
How to use checksums
7a4ad65ac8d59bf226244d1d7a5e5d3029441af457304b47876695775129544a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release files / unicef_notification-1.4.1-py2.py3-none-any.whl

Download URL unicef_notification-1.4.1-py2.py3-none-any.whl
Size 11.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
e378ede54db50fab2fdc7cccc40206b5b3803ba5fac907a7c42c12846be8d662
BLAKE2b-256 checksum
How to use checksums
3a2f1ff06463e209e61185b31f4407bfb66fcf709839360a85f681f4fa9b702c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release history Release notifications | RSS feed

This release

1.4.1 This release

2 release files

1.4

2 release files

1.2

2 release files

1.1

2 release files

1.0

2 release files

0.2.1

1 release file

0.2.0

1 release file

0.1.0

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