Django library for separating the message content from transmission method
Project description
# django-herald
[![Build Status](https://travis-ci.org/worthwhile/django-herald.svg?branch=master)](https://travis-ci.org/worthwhile/django-herald)
Django library for separating the message content from transmission method
# Installation
1. `pip install django-herald`
2. Add `herald` to `INSTALLED_APPS`.
3. Add herald's URLS:
if settings.DEBUG:
urlpatterns = [
url(r'^herald/', include('herald.urls')),
] + urlpatterns
# Usage
1. Create a `notifications.py` file in any django app. This is where your notification classes will live. Add a class like this:
from herald import registry
from herald.base import EmailNotification
class WelcomeEmail(EmailNotification): # extend from EmailNotification for emails
template_name = 'welcome_email' # name of template, without extension
subject = 'Welcome' # subject of email
def __init__(self, user): # optionally customize the initialization
self.context = {'user': user} # set context for the template rendering
self.to_emails = [user.email] # set list of emails to send to
@staticmethod
def get_demo_args(): # define a static method to return list of args needed to initialize class for testing
from users.models import User
return [User.objects.order_by('?')[0]]
registry.register(WelcomeEmail) # finally, register your notification class
2. Create templates for rendering the email using this file structure:
templates/
herald/
text/
welcome_email.txt
html/
welcome_email.html
3. Test how your email looks by navigating to `/herald/`.
4. Send your email wherever you need in your code:
WelcomeEmail(user).send()
5. View the sent emails in django admin and even be able to resend it.
[![Build Status](https://travis-ci.org/worthwhile/django-herald.svg?branch=master)](https://travis-ci.org/worthwhile/django-herald)
Django library for separating the message content from transmission method
# Installation
1. `pip install django-herald`
2. Add `herald` to `INSTALLED_APPS`.
3. Add herald's URLS:
if settings.DEBUG:
urlpatterns = [
url(r'^herald/', include('herald.urls')),
] + urlpatterns
# Usage
1. Create a `notifications.py` file in any django app. This is where your notification classes will live. Add a class like this:
from herald import registry
from herald.base import EmailNotification
class WelcomeEmail(EmailNotification): # extend from EmailNotification for emails
template_name = 'welcome_email' # name of template, without extension
subject = 'Welcome' # subject of email
def __init__(self, user): # optionally customize the initialization
self.context = {'user': user} # set context for the template rendering
self.to_emails = [user.email] # set list of emails to send to
@staticmethod
def get_demo_args(): # define a static method to return list of args needed to initialize class for testing
from users.models import User
return [User.objects.order_by('?')[0]]
registry.register(WelcomeEmail) # finally, register your notification class
2. Create templates for rendering the email using this file structure:
templates/
herald/
text/
welcome_email.txt
html/
welcome_email.html
3. Test how your email looks by navigating to `/herald/`.
4. Send your email wherever you need in your code:
WelcomeEmail(user).send()
5. View the sent emails in django admin and even be able to resend it.
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
django-herald-0.1.1.tar.gz
(9.2 kB
view hashes)
Built Distribution
Close
Hashes for django_herald-0.1.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d28b48111cb2c3d49f01dd9c931c700168e23d5fa0ace5f5a1bc826521eaa597 |
|
MD5 | fb086cd61dafd1ecb10394ad869926e3 |
|
BLAKE2b-256 | dcce3639deae651b3bbb8cbe2188d0fea80b603fcb1be19f603be2d744403d5f |