Send alerts, notifications, and messages based on events in your django application
Project description
[![Build Status](https://travis-ci.org/jiaaro/django-alert.png?branch=master)](https://travis-ci.org/jiaaro/django-alert)
## Installation ##
1. Install lib with pip:
`pip install django-alert`
**- OR -**
Put the "alert" directory somewhere in your python path
2. Add "alert" to your installed apps (in the settings.py file)
## Making Alerts ##
Create an "alerts.py" file and import it at the bottom of your
models.py file. This is where you will define your alert class. Every
alert is subclassed from "alert.utils.BaseAlert"
Here is an example alert that is sent to users when they first sign up:
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from alert.utils import BaseAlert
class WelcomeAlert(BaseAlert):
title = 'Welcome new users'
description = 'When a new user signs up, send them a welcome email'
signal = post_save
sender = User
default = False
def before(self, created, **kwargs):
return created
def get_applicable_users(self, instance, **kwargs):
return [instance]
## Writing Alert Backends ##
Alert includes an Email Backend by default. But you can write a backend
for *any* messaging medium!
Alert Backends just need to subclass BaseAlertBackend and implement a
`send()` method that accepts an alert instance
You can copy and paste the following code to get started:
from alert.utils import BaseAlertBackend
class MyAlertBackend(BaseAlertBackend):
def send()
## Signals ##
When an alert is sent, a signal is fired (found in alert.signals). The
"sender" keyword argument is the Alert you defined (WelcomeAlert in
this case).
example:
from alert.signals import alert_sent
def do_something_after_welcome_alert_is_sent(sender, alert, **kwargs):
pass
alert_sent.connect(do_something_after_welcome_alert_is_sent,
sender=WelcomeAlert)
## Installation ##
1. Install lib with pip:
`pip install django-alert`
**- OR -**
Put the "alert" directory somewhere in your python path
2. Add "alert" to your installed apps (in the settings.py file)
## Making Alerts ##
Create an "alerts.py" file and import it at the bottom of your
models.py file. This is where you will define your alert class. Every
alert is subclassed from "alert.utils.BaseAlert"
Here is an example alert that is sent to users when they first sign up:
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from alert.utils import BaseAlert
class WelcomeAlert(BaseAlert):
title = 'Welcome new users'
description = 'When a new user signs up, send them a welcome email'
signal = post_save
sender = User
default = False
def before(self, created, **kwargs):
return created
def get_applicable_users(self, instance, **kwargs):
return [instance]
## Writing Alert Backends ##
Alert includes an Email Backend by default. But you can write a backend
for *any* messaging medium!
Alert Backends just need to subclass BaseAlertBackend and implement a
`send()` method that accepts an alert instance
You can copy and paste the following code to get started:
from alert.utils import BaseAlertBackend
class MyAlertBackend(BaseAlertBackend):
def send()
## Signals ##
When an alert is sent, a signal is fired (found in alert.signals). The
"sender" keyword argument is the Alert you defined (WelcomeAlert in
this case).
example:
from alert.signals import alert_sent
def do_something_after_welcome_alert_is_sent(sender, alert, **kwargs):
pass
alert_sent.connect(do_something_after_welcome_alert_is_sent,
sender=WelcomeAlert)
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-alert-0.7.2.tar.gz
(17.1 kB
view details)
Built Distribution
File details
Details for the file django-alert-0.7.2.tar.gz
.
File metadata
- Download URL: django-alert-0.7.2.tar.gz
- Upload date:
- Size: 17.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8cc6a3dc873991d6cd6ca438926a1ddb546ab061db71ad86ade6eb95bb7dc753 |
|
MD5 | 8ed4ec682d7a31840515da1ac185d58c |
|
BLAKE2b-256 | 070ac67f9e57d8eebc147832641c4afe1b311c402247803373ff0b2e0d33c29c |
File details
Details for the file django_alert-0.7.2-py2.py3-none-any.whl
.
File metadata
- Download URL: django_alert-0.7.2-py2.py3-none-any.whl
- Upload date:
- Size: 22.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 675fc08c09792df66b664079a8ad67f0b788b7afeefba669f7ca975923b9ae9a |
|
MD5 | 8e628569e714d4a9c5b8b297f2848f23 |
|
BLAKE2b-256 | bdd966a2f1ebe68f7ac158c349316ec6d2c0b3e3175d75913953752a0229d2ac |