A notifications library for Djangonauts that support email, sms and push.
Project description
Django Magic Notifier
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.
Documentation
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",
}
},
"USER_FROM_WS_TOKEN_FUNCTION": 'magic_notifier.utils.get_user_from_ws_token'
}
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
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-magic-notifier-0.2.0.tar.gz
.
File metadata
- Download URL: django-magic-notifier-0.2.0.tar.gz
- Upload date:
- Size: 29.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 027ede1b9ab3dbd29799aa603213eb15fec17d90e557b79f43ef0acf9c10882f |
|
MD5 | ad77a073dde50d020524aafbda16692f |
|
BLAKE2b-256 | 277c3602cec516857d2ccb1868c852bf9fb872cb1e0991f750d979433094365d |
File details
Details for the file django_magic_notifier-0.2.0-py2.py3-none-any.whl
.
File metadata
- Download URL: django_magic_notifier-0.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 24.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96fd7d191a2f7f4f16f42b073923c997d84b3c3e67f0e22c7cc16865771de197 |
|
MD5 | 56ccb9661b491701a2250fd66475bd2d |
|
BLAKE2b-256 | 7b7c68142da9c0b947b87bf5cf350b0590a4336ad4b1133562414d3c88735bcc |