Skip to content

Commit c8fd1dc

Browse files
author
Kevin Renskers
committed
0.1.2: December 1, 2011
- The DjangoMessagesNotificationBackend can now use the subject as well as the text - Easier to subclass BaseNotification and set your own default properties - Changed documentation to reStructuredText, in preparation of move to PyPi
1 parent 1461604 commit c8fd1dc

File tree

12 files changed

+110
-59
lines changed

12 files changed

+110
-59
lines changed

CHANGELOG

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
0.1.0: Never published
2+
- Initial version
3+
4+
0.1.1: Never published
5+
- Bugfixes
6+
7+
0.1.2: December 1, 2011
8+
- The DjangoMessagesNotificationBackend can now use the subject as well as the text
9+
- Easier to subclass BaseNotification and set your own default properties
10+
- Changed documentation to reStructuredText, in preparation of move to PyPi

INSTALL

Lines changed: 0 additions & 4 deletions
This file was deleted.

INSTALL.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Install
2+
=======
3+
4+
1. Get the code: ``pip install django-generic-notifications``
5+
2. Add 'notifications' to your INSTALLED_APPS
6+
3. Sync the database (south migrations are provided)

MANIFEST.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
include AUTHORS
22
include LICENSE
3+
include CHANGELOG
4+
include INSTALL.rst
5+
include README.rst
6+
include USAGE.rst

README.md

Lines changed: 0 additions & 42 deletions
This file was deleted.

README.rst

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
========
2+
Overview
3+
========
4+
5+
**A Django app that can handle multiple ways of showing different notification types. It's all based on multiple input
6+
types and output backends.**
7+
8+
9+
Notifications
10+
=============
11+
A notification could be anything:
12+
13+
- there was an error in your form submission
14+
- your account has been created
15+
- your account has been activated
16+
- you have received a private message on a forum
17+
- there is a new comment on your blog
18+
- someone liked your profile
19+
- a message from the administrator
20+
21+
As far as this project is concerned, a notification is nothing more but an (optional) subject, text body, and a level
22+
(info, success, error, warning).
23+
24+
Backends
25+
========
26+
There are multiple output backends. Some possible examples are:
27+
28+
- email
29+
- a popup in your webbrowser
30+
- sms message
31+
- iPhone push notification
32+
- Django's messages app
33+
34+
Some backends can process notifications in real time (Django's messages app for example), and others should run in the
35+
background (sending email, sending push messages to iPhones). Each backend specifies what its mode of operation is.
36+
37+
Notification types
38+
==================
39+
A notification type is the glue between a message (input) and one or more possible backends (output). For example, you
40+
might want to send all account related messages to email only, but notifications about new private messages could go to
41+
email, iPhone push messages, Django's own messages app, you name it.
42+
43+
Each notification type can specify its allowed backend, and each user can specify his preferred output backend(s).
44+
Each notification will then figure out what backend to use based on this information.
45+
46+
Settings
47+
========
48+
Some backends will need extra information from the user, for example a phone number, email address or iPhone device id.
49+
50+
This project doesn't provide a settings app where users can configure these. Instead, this is left to an exercise to the
51+
reader (at least for now). Each output backend can accept a variable number of keyword arguments, so building a custom
52+
backend that needs a new setting isn't a problem.
53+
54+
Queue
55+
=====
56+
Some notification backends can't process in real time, instead adding them to a queue. At this moment, this is based on
57+
a simple database model and a manage.py script which can be used from your cron.
58+
59+
In the future celery tasks should be added too.
60+
61+
Installation
62+
============
63+
See `INSTALL.rst`
64+
65+
Usage
66+
=====
67+
See `USAGE.rst` for examples

Usage.md renamed to USAGE.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# Usage
2-
Simple example of use cases:
1+
Usage
2+
=====
3+
Simple example of use cases::
34

45
from notifications.type.default import DefaultNotification
56
DefaultNotification('Subject', 'This is a notification!', request=request).do('add')
@@ -8,8 +9,10 @@ Simple example of use cases:
89
AccountNotification('Account created', 'Your account has been created!', user=request.user).do('add')
910
AccountNotification('Account created', 'Your account has been created!', email='hello@example.com').do('add')
1011

11-
## Cron
12-
There is a command to process notifications that have been added to the queue:
12+
13+
Cron
14+
====
15+
There is a command to process notifications that have been added to the queue::
1316

1417
./manage.py process_notifications
1518

notifications/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.1.1'
1+
__version__ = '0.1.2'

notifications/backend/django_messages.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ def validate(self):
3131
return False
3232
raise BackendConfigError('You need to add django.contrib.messages.context_processors.messages to TEMPLATE_CONTEXT_PROCESSORS')
3333

34+
self.text = self.notification.text or self.notification.subject
35+
3436
return True
3537

3638
def process(self):
@@ -44,4 +46,4 @@ def process(self):
4446

4547
level = levels.get(self.notification.level, messages.INFO)
4648

47-
return messages.add_message(self.notification.request, level, self.notification.text)
49+
return messages.add_message(self.notification.request, level, self.text)

notifications/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class NotificationQueue(models.Model):
1616
"""
1717
user = models.ForeignKey(User, blank=True, null=True, related_name='notifications')
1818
subject = models.CharField(max_length=255, blank=True)
19-
text = models.TextField()
19+
text = models.TextField(blank=True)
2020
level = models.CharField(max_length=40)
2121
extra_context = JSONField()
2222
tries = models.PositiveIntegerField(default=0)

0 commit comments

Comments
 (0)