Debian Codegraph @

django_notification.egg-info/PKG-INFO

raw
1 Metadata-Version: 1.1
2 Name: django-notification
3 Version: 1.2.0
4 Summary: User notification management for the Django web framework
5 Home-page: https://github.com/pinax/django-notification
6 Author: James Tauber
7 Author-email: [email protected]
8 License: UNKNOWN
9 Description: .. _usage:
10
11 Usage
12 =====
13
14 Integrating notification support into your app is a simple three-step process.
15
16 * create your notice types
17 * create your notice templates
18 * send notifications
19
20 Creating Notice Types
21 ---------------------
22
23 You need to call ``create_notice_type(label, display, description)`` once to
24 create the notice types for your application in the database. ``label`` is just
25 the internal shortname that will be used for the type, ``display`` is what the
26 user will see as the name of the notification type and `description` is a
27 short description.
28
29 For example::
30
31 notification.create_notice_type("friends_invite", "Invitation Received", "you have received an invitation")
32
33 One good way to automatically do this notice type creation is in a
34 ``management.py`` file for your app, attached to the syncdb signal.
35 Here is an example::
36
37 from django.conf import settings
38 from django.db.models import signals
39 from django.utils.translation import ugettext_noop as _
40
41 if "notification" in settings.INSTALLED_APPS:
42 from notification import models as notification
43
44 def create_notice_types(app, created_models, verbosity, **kwargs):
45 notification.create_notice_type("friends_invite", _("Invitation Received"), _("you have received an invitation"))
46 notification.create_notice_type("friends_accept", _("Acceptance Received"), _("an invitation you sent has been accepted"))
47
48 signals.post_syncdb.connect(create_notice_types, sender=notification)
49 else:
50 print "Skipping creation of NoticeTypes as notification app not found"
51
52 Notice that the code is wrapped in a conditional clause so if
53 django-notification is not installed, your app will proceed anyway.
54
55 Note that the display and description arguments are marked for translation by
56 using ugettext_noop. That will enable you to use Django's makemessages
57 management command and use django-notification's i18n capabilities.
58
59 Notification templates
60 ----------------------
61
62 There are four different templates that can be written to for the actual content of the notices:
63
64 * ``short.txt`` is a very short, text-only version of the notice (suitable for things like email subjects)
65 * ``full.txt`` is a longer, text-only version of the notice (suitable for things like email bodies)
66 * ``notice.html`` is a short, html version of the notice, displayed in a user's notice list on the website
67 * ``full.html`` is a long, html version of the notice (not currently used for anything)
68
69 Each of these should be put in a directory on the template path called ``notification/<notice_type_label>/<template_name>``.
70 If any of these are missing, a default would be used. In practice, ``notice.html`` and ``full.txt`` should be provided at a minimum.
71
72 For example, ``notification/friends_invite/notice.html`` might contain::
73
74 {% load i18n %}{% url invitations as invitation_page %}{% url profile_detail username=invitation.from_user.username as user_url %}
75 {% blocktrans with invitation.from_user as invitation_from_user %}<a href="{{ user_url }}">{{ invitation_from_user }}</a> has requested to add you as a friend (see <a href="{{ invitation_page }}">invitations</a>){% endblocktrans %}
76
77 and ``notification/friends/full.txt`` might contain::
78
79 {% load i18n %}{% url invitations as invitation_page %}{% blocktrans with invitation.from_user as invitation_from_user %}{{ invitation_from_user }} has requested to add you as a friend. You can accept their invitation at:
80
81 http://{{ current_site }}{{ invitation_page }}
82 {% endblocktrans %}
83
84 The context variables are provided when sending the notification.
85
86
87 Sending Notification
88 ====================
89
90 There are two different ways of sending out notifications. We have support
91 for blocking and non-blocking methods of sending notifications. The most
92 simple way to send out a notification, for example::
93
94 notification.send([to_user], "friends_invite", {"from_user": from_user})
95
96 One thing to note is that ``send`` is a proxy around either ``send_now`` or
97 ``queue``. They all have the same signature::
98
99 send(users, label, extra_context)
100
101 The parameters are:
102
103 * ``users`` is an iterable of ``User`` objects to send the notification to.
104 * ``label`` is the label you used in the previous step to identify the notice
105 type.
106 * ``extra_content`` is a dictionary to add custom context entries to the
107 template used to render to notification. This is optional.
108
109 ``send_now`` vs. ``queue`` vs. ``send``
110 ---------------------------------------
111
112 Lets first break down what each does.
113
114 ``send_now``
115 ~~~~~~~~~~~~
116
117 This is a blocking call that will check each user for elgibility of the
118 notice and actually peform the send.
119
120 ``queue``
121 ~~~~~~~~~
122
123 This is a non-blocking call that will queue the call to ``send_now`` to
124 be executed at a later time. To later execute the call you need to use
125 the ``emit_notices`` management command.
126
127 ``send``
128 ~~~~~~~~
129
130 A proxy around ``send_now`` and ``queue``. It gets its behavior from a global
131 setting named ``NOTIFICATION_QUEUE_ALL``. By default it is ``False``. This
132 setting is meant to help control whether you want to queue any call to
133 ``send``.
134
135 ``send`` also accepts ``now`` and ``queue`` keyword arguments. By default
136 each option is set to ``False`` to honor the global setting which is ``False``.
137 This enables you to override on a per call basis whether it should call
138 ``send_now`` or ``queue``.
139
140 Optional notification support
141 -----------------------------
142
143 In case you want to use django-notification in your reusable app, you can
144 wrap the import of django-notification in a conditional clause that tests
145 if it's installed before sending a notice. As a result your app or
146 project still functions without notification.
147
148 For example::
149
150 from django.conf import settings
151
152 if "notification" in settings.INSTALLED_APPS:
153 from notification import models as notification
154 else:
155 notification = None
156
157 and then, later::
158
159 if notification:
160 notification.send([to_user], "friends_invite", {"from_user": from_user})
161
162 Platform: UNKNOWN
163 Classifier: Development Status :: 5 - Production/Stable
164 Classifier: Environment :: Web Environment
165 Classifier: Intended Audience :: Developers
166 Classifier: License :: OSI Approved :: MIT License
167 Classifier: Operating System :: OS Independent
168 Classifier: Programming Language :: Python :: 2.7
169 Classifier: Programming Language :: Python :: 3.3
170 Classifier: Framework :: Django