Package: django-noticebox
This project is archived. It is no longer updated or maintained.Django-noticebox is a reusable Django application which provides functionality
for sending notices to site users. The notices can be displayed when user
signs in, sent by email or both.This application is inspired by James Tauber’sdjango-notificationbut
it is designed to be much more lightweight.InstallationThe django-noticebox application can be installed using standard setuptoolssetup.pyscript:$ python setup.py installInstallation usingeasy_installorpipis also possible. Alternatively
you can simply put the library anywhere to yourPYTHONPATH.UsageNotice creationIn thenoticebox.handlersmodule are defined following callables for
a notice creation:save_notice(users, preset=None, **kwargs)Creates a notice model instance and saves it in the database.mail_notice(users, preset=None, **kwargs)Creates an email messages with the notice and sends it.user_notice(users, preset=None, **kwargs)Saves notice in the database and sends email. Effectively calls
bothsave_noticeandmail_notice.All the handlers follow same signature. The first argument should be
a user instance, a user list or a user queryset. The subject and body strings
should be given as keyword arguments:user_notice(user, subject="Hello!", body="Hello,\nhow are you?")Thesave_noticeandmail_noticehandlers are actually class instances so
they can be customized if necessary.Notice templatesThe actual subjects and bodies are rendered using Django template
system:notices/default/email_subject.txtRenders an email subject. By default returns given subject unchanged.
This template can be customized if (for example) a common prefix should
be added.notices/default/email_body.txtRenders an email body. By default returns given body unchanged.
This template can be customized if (for example) a common footer should
be added.notices/default/web_subject.htmlRenders a notice subject to be displayed on the website.
By default returns the given subject HTML escaped.notices/default/web_body.htmlRenders a notice body to be displayed on the website.
By default returns the given subject HTML escaped and new lines
replaced by HTML paragraphs (usinglinebreakstemplate filter).Presets (alternative templates)The handlers do not actually require any specific keyword arguments
(neithersubjectnorbody). The given keyword arguments are simply passed
to the template in the context.Non-default templates will be used if apresetargument is specified.
For example following call will render tamplates in thenotices/welcome/directory with theusernamevariable in the context:user_notice(user, preset="welcome", username="alice")Notice display (views)Notices in a database can be displayed on the web site when user logs in.
Two class based views are defined in thenoticebox.viewsmodule:NoticeListViewDisplays paginated list of notices for the authenticated user.NoticeDetailViewDisplay notice detail and marks it as read.Both views  are included in thenoticebox.urlsurlpatterns which means that if
no customization is needed then they can be simply included in the url
configuration:urlpatterns = patterns('',
    # ...
    (r'^notices/', include('noticebox.urls')),
    # ...
)Simple templates for the views are present but it may be better to override
them for real projects.Context processorThe application provides a context processor which makes count of unread
messages available in the template:TEMPLATE_CONTEXT_PROCESSORS = (
    # ...
    'noticebox.context_processors.notices',
    # ...
)The unread notice count is available in thenotice_unread_countvariable. No database queries are executed until it is necessary.TestingAll tests can be discovered and run the Django test runner. For simplicity
minimal Django settings are provided so all the tests can be run using
Django admin utility like this:django-admin.py test noticebox \
    --settings=noticebox.tests.settings --pythonpath=$PWD