GithubHelp home page GithubHelp logo

umrashrf / django-alert Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jiaaro/django-alert

0.0 2.0 0.0 191 KB

Send alerts, notifications, and messages based on events (i.e. signals) in your django application

Home Page: http://djangoalert.com

License: MIT License

Python 100.00%

django-alert's Introduction

Build Status

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)

  3. Also add "django.contrib.sites" in installed apps in case it's not there.

  4. Run ./manage.py migrate

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)

django-alert's People

Contributors

dulacp avatar jiaaro avatar umrashrf avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.