Skip to main content

A notifications library for Djangonauts that support email, sms and push.

Project description

Django Magic Notifier

travis django-magic-notifier coverage django-magic-notifier Pypi current version Documentation PRs welcome Python versions Django versions

Why Django Magic Notifier

Sending notifications in Django has always been a complex subject. Django Magic Notifier solves this by providing only one function notify(). The library [will] support sending notifications via email, sms and push notifications.

Features

  • Send emails
  • Send sms, TWILIO support
  • Send push notifications
  • Support templates
  • Simple API
  • Support files
  • Support multiple gateways
  • Extensible

Installation

$pip install --upgrade django-magic-notifier

Usage

1. Configure settings

If you have already configured SMTP EMAIL SETTINGS in django settings then can ignore this step. Else add a NOTIFIER dict in your settings like this

NOTIFIER = {
    "EMAIL": {
        "default": {
            "HOST": "localhost",
            "PORT": 587,
            "USE_TLS": True,
            "USE_SSL": False,
            "USER": "root@localhost",
            "FROM": "Root <root@localhost>",
            "PASSWORD": "********",
            "CLIENT": "magic_notifier.email_clients.django_email.DjangoEmailClient",
        }
    },
}
2. Create templates

Create a folder named notifier in one of app's templates dir. In this folder create another folder named base then created your base templates in this folder. Example

app_name/templates/notifier/base/email.html

    {% extends "base_notifier/email.html" %}

app_name/templates/notifier/base/email.txt

    {% extends "base_notifier/email.txt" %}

app_name/templates/notifier/hello/email.html

    {% extends "notifier/base/email.html" %}
    {% block content %}
    <tr>
        <td><p>Hello {{ user.email }}
        </td>
    </tr>
    {% endblock %}

app_name/templates/notifier/hello/email.txt

    {% extends "notifier/hello/email.txt" %}
    {% block content %}
    >Hello {{ user.email }}
    {% endblock %}

As you can see, the user to whom the notification goes is automatically added in the template's context. To avoid any clash to don't send the key 'user' in the context of the notifiy() function presented below.

Note that it is DMN (Django Magic Notifier) that has the base_notifier template.

3. Send notifications

To send a notification via email do

    from magic_notifier.notifier import notify

    # send an email from direct string
    user = User(email="testuser@localhost", username="testuser")
    subject = "Test magic notifier"
    notify(["email"], subject, [user], final_message="Nice if you get this")

    # send an email from a template
    user = User(email="testuser@localhost", username="testuser")
    subject = "Test magic notifier"
    notify(["email"], subject, [user], template='hello')

    # send a sms from a template
    user = User(email="testuser@localhost", username="testuser")
    subject = "Test magic notifier"
    notify(["sms"], subject, [user], template='hello')

    # send a notification via email and sms from a template
    user = User(email="testuser@localhost", username="testuser")
    subject = "Test magic notifier"
    notify(["email", "sms"], subject, [user], template='hello')

Docs and support

Coming

Roadmap

  • Send sms :tw-2705:
  • Send push notifications
  • Generate full documentation
  • Translate documentation

Contributing

Contribution are welcome.

License

As per the license, feel free to use the library as you want.

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-magic-notifier-0.1.0.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

django_magic_notifier-0.1.0-py2.py3-none-any.whl (33.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-magic-notifier-0.1.0.tar.gz.

File metadata

  • Download URL: django-magic-notifier-0.1.0.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.6.15

File hashes

Hashes for django-magic-notifier-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e00f075db7e022252dd5306a73ea9b25bce862076e558bb5d90d7b12a3b3f385
MD5 573acd4bd9b10a7985746e707a97bef5
BLAKE2b-256 6ef9085661667d6d37ada9ce34eb06bb0093ce626655ddb5c0f729c852c4ca92

See more details on using hashes here.

File details

Details for the file django_magic_notifier-0.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: django_magic_notifier-0.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 33.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.6.15

File hashes

Hashes for django_magic_notifier-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4b96de41da1375d5af0e2d12c6239a0bd8f2550de5f06d08d680297c4c62993a
MD5 57174afc9602c02d8650cffa5496430f
BLAKE2b-256 e1f978fbdd1e966e0a69beb2d65d066b55e87026fe203b572022e58c3fda5703

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