Package: django-messages-extends
Django Messages ExtendsA Django app for extends Django'smessages frameworkby adding "sticky" and "persistent" backend message storages. This also supports the notion of sending
persistent messages to other users in a machine-to-user process.StoragesSticky StorageA "sticky" message is a message where the user must hit the close button in order to get rid of
it within that session.For messages that are in some middleware or is only to the current request and don't need save it.This is very similar to the default except that you explicitly must close the dialog to remove
the message.This backend never save anything only simulate that do that.Persistent StorageA "persistent" messages is a message where a message is retained across multiple sessions until
the user clicks the close button.  The message is stored in the default_storage container
(defaults to database).Only for authenticated users, messages are stored in the database.The messages has to be explicit read, and there are show while don't close itInstallationThis document assumes that you are familiar with Python and Django.Download and unzip the app,
or install usingpip:$ pip install django-messages-extendsMake suremessages_extendsis on yourPYTHONPATH.Addmessages_extendsto yourINSTALLED_APPSsetting.INSTALLED_APPS=(...'messages_extends',)Make sure Django'sMessageMiddlewareis in yourMIDDLEWARE_CLASSESsetting (which is the
case by default):MIDDLEWARE_CLASSES=(...'django.contrib.messages.middleware.MessageMiddleware',)Add the messages_extends URLs to your URL conf. For instance, in order to make messages
available underhttp://domain.com/messages/, add the following line tourls.py.urlpatterns=patterns('',(r'^messages/',include('messages_extends.urls')),...)In your settings, set the messagestorage backendtomessages_extends.storages.FallbackStorage:MESSAGE_STORAGE='messages_extends.storages.FallbackStorage'Set up the database tables using$ manage.py makemigratations
 $ manage.py migrateIf you want to use the bundled templates, add thetemplatesdirectory to yourTEMPLATE_DIRSsetting:TEMPLATE_DIRS=(...'path/to/messages_extends/templates'))Using messages in views and templatesMessage levelsDjango's messages framework provides a number ofmessage levelsfor various purposes such as success messages, warnings etc. This app provides constants with the
same names, the difference being that messages with these levels are going to be persistent:frommessages_extendsimportconstantsasconstants_messages# default messages levelconstants_messages.DEBUG=10constants_messages.INFO=20constants_messages.SUCCESS=25constants_messages.WARNING=30constants_messages.ERROR=40# persistent messages levelconstants_messages.DEBUG_PERSISTENT=9constants_messages.INFO_PERSISTENT=19constants_messages.SUCCESS_PERSISTENT=24constants_messages.WARNING_PERSISTENT=29constants_messages.ERROR_PERSISTENT=39# sticky messages levelconstants_messages.DEBUG_STICKY=8constants_messages.INFO_STICKY=18constants_messages.SUCCESS_STICKY=23constants_messages.WARNING_STICKY=28constants_messages.ERROR_STICKY=38Adding a messageSince the app is implemented as astorage backendfor Django'smessages framework, you
can still use the regular Django API to add a message:fromdjango.contribimportmessagesmessages.add_message(request,messages.INFO,'Hello world.')Or use persistent messages with constants in messages_extends.constantsfromdjango.contribimportmessagesfrommessages_extendsimportconstantsasconstants_messagesmessages.add_message(request,constants_messages.WARNING_PERSISTENT,'You are going to see this message until you mark it as read.')Or via the shortcut method.messages.add_persistant_error(request,'Houston we have a problem..')Note that this is only possible for logged-in users, so you are probably going to have make sure
that the current user is not anonymous usingrequest.user.is_authenticated(). Adding a
persistent message for anonymous users raises aNotImplementedError.And sticky messages:fromdjango.contribimportmessagesfrommessages_extendsimportconstantsasconstants_messagesmessages.add_message(request,constants_messages.WARNING_STICKY,'You will going to see this messages only in this request')You can also pass this function aUserobject if the message is supposed to be sent to a user
other than the one who is currently authenticated. User Sally will see this message the next time
she logs in:fromdjango.contribimportmessagesfrommessages_extendsimportconstantsasconstants_messagesfromdjango.contrib.auth.modelsimportUsersally=User.objects.get(username='Sally')messages.add_message(request,constants_messages.INFO_PERSISTENT,"Hola abc desde%s"%request.user,user=sally)To persistent storages, there are other params like expires that is a datetime.Displaying messagesMessages can be displayedas described in the Django manual.
However, you are probably going to want to include links tags for closing each message (i.e.
marking it as read). In your template, use something like:{%formessageinmessages%}<divclass="alert{%ifmessage.tags%}alert-{{message.tags}}{%endif%}">{# close-href is used because href is used by bootstrap to closing other divs #}<aclass="close"data-dismiss="alert"{%ifmessage.pk%}close-href="{%urlmessage_mark_readmessage.pk%}"{%endif%}>×</a>{{message}}</div>{%endfor%}You can also use the bundled templates instead. The following line replaces the code above. It
allows the user to remove messages usingbootstrap styling(you need use bootstrap.css and boostrap.js){%include"messages_extends/includes/alerts_bootstrap.html"%}For use Ajax to mark them as read you can add the following code that works with jquery:$("a.close[close-href]").click(function(e){e.preventDefault();$.post($(this).attr("close-href"),"",function(){});});Or use:<scriptsrc="{%static"close-alerts.js"%}"></script>DON'T FORGET: If you have CSRF enabled, you have to add csrf code by js,see django DocumentationIf you don't want see close button in sticky alerts, you can use css for hide them:.alert.sticky.close{display:none;}Other BackendsYou can use other backends, by default use:MESSAGES_STORAGES=('messages_extends.storages.StickyStorage','messages_extends.storages.PersistentStorage','django.contrib.messages.storage.cookie.CookieStorage','django.contrib.messages.storage.session.SessionStorage'))But you can add or remove other backends in your settings in order that you need execute that,
remember that session storagge save all messages, then you have to put it at final.RememberRemember that this module is only for messages from application, to messages between users you can
usepostmanu other framework and to messages for
activity stream you can usedjango-activity-streamLicenseDjango Messages Extends is provided underThe MIT License (MIT).CreditsDjango Messages Extends is a project byAli Lozano.  Additional credit
goes to:Steven KlassInspired and based indjango-persistent-messages