Django library that makes triggering emails easier
Project description
`pingpong` is a library to aimed at simplifying things thing that should be easy
in django.
## Installation ##
1. Install lib with pip:
`pip install pingpong`
**- OR -**
Put the "pingpong" directory somewhere in your python path
2. Add "pingpong" to your installed apps (in the settings.py file)
## A better way to fire off emails
from pingpong.email import render_to_email
def some_function():
template = "emails/muffins.email"
context = { "your_mom": "Betty Crocker", "muffin_type": "blueberry" }
recipients = ['somebody@example.com']
# send an email!
render_to_email(template, context, recipients)
And the template, `emails/my_email_template.email` would be in your main
templates folder:
Delicious muffins thanks to {{ your_mom }}
Hi friend,
I'm writing to let you know that {{ your_mom }} made some superb
{{ muffin_type }} muffins. Please tell her thank you!
Thanks,
A Robot
The first non-blank line is the subject, everything following is the message.
Subject:
Delicious muffins thanks to Betty Crocker
Message:
I'm writing to let you know that Betty Crocker made some superb
blueberry muffins. Please tell her thank you!
Thanks,
A Robot
Whitespace is stripped from the beginning and end of the message.
## Passing system events to your app
set up listeners:
# listeners.py
from pingpong.utils import pong
@pong("dailycron")
def email_admins_about_daily_activity(ping_name, args, kwargs, **kw):
...
# models.py
... your models...
import listeners
Then you trigger all functions listening to "dailycron" like so:
$ python manage.py pong dailycron
If you pass extra args to the management command they will get passed along...
$ python manage.py pong cachecleared memcache:38174
In this case we're letting the app know that memcache on port 38174 just got
cleared.
from pingpong.utils import pong
@pong("cachecleared")
def warm_up_cache(ping_name, args, kwargs, **kw):
assert ping_name == "cachecleared"
assert args[0] == "memcache:38174"
cache_type, port = args[0].split(":")
...
in django.
## Installation ##
1. Install lib with pip:
`pip install pingpong`
**- OR -**
Put the "pingpong" directory somewhere in your python path
2. Add "pingpong" to your installed apps (in the settings.py file)
## A better way to fire off emails
from pingpong.email import render_to_email
def some_function():
template = "emails/muffins.email"
context = { "your_mom": "Betty Crocker", "muffin_type": "blueberry" }
recipients = ['somebody@example.com']
# send an email!
render_to_email(template, context, recipients)
And the template, `emails/my_email_template.email` would be in your main
templates folder:
Delicious muffins thanks to {{ your_mom }}
Hi friend,
I'm writing to let you know that {{ your_mom }} made some superb
{{ muffin_type }} muffins. Please tell her thank you!
Thanks,
A Robot
The first non-blank line is the subject, everything following is the message.
Subject:
Delicious muffins thanks to Betty Crocker
Message:
I'm writing to let you know that Betty Crocker made some superb
blueberry muffins. Please tell her thank you!
Thanks,
A Robot
Whitespace is stripped from the beginning and end of the message.
## Passing system events to your app
set up listeners:
# listeners.py
from pingpong.utils import pong
@pong("dailycron")
def email_admins_about_daily_activity(ping_name, args, kwargs, **kw):
...
# models.py
... your models...
import listeners
Then you trigger all functions listening to "dailycron" like so:
$ python manage.py pong dailycron
If you pass extra args to the management command they will get passed along...
$ python manage.py pong cachecleared memcache:38174
In this case we're letting the app know that memcache on port 38174 just got
cleared.
from pingpong.utils import pong
@pong("cachecleared")
def warm_up_cache(ping_name, args, kwargs, **kw):
assert ping_name == "cachecleared"
assert args[0] == "memcache:38174"
cache_type, port = args[0].split(":")
...
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
pingpong-0.0.1.tar.gz
(3.3 kB
view details)
File details
Details for the file pingpong-0.0.1.tar.gz
.
File metadata
- Download URL: pingpong-0.0.1.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3123d85078fff1f2c318c6ca5edfec61c4eb69b13aa1711cb29f62d761d6521a |
|
MD5 | 5771f86dbb5d3566aad8c5e47e1e1ee0 |
|
BLAKE2b-256 | 1b56c2631153d8425adbc68261df789ee1e8637e44c2c512293ee736f2f4fcf0 |