Package: django3-stored-messages
Django contrib.messages on steroidsThe app integrates smoothly with Django’smessages framework(django.contrib.messages), but users can decide which messages have to be stored on the database
backend and kept available over sessions.FeaturesSeamless integration withdjango.contrib.messagesAll the features are in a mixin you can attach to your existing storageStored messages are archived in the database or in a Redis instanceUsers can configure which message levels have to be persistedREST api to retrieve and mark messages as read (needsdjangorestframework)Signalling api to perform actions in response to messages activityCompatibility tablePython 2.7, 3.4, 3.5Django 1.8, 1.9Django Rest Framework >= 3.3 (only if you want to use REST endpoints)Do you use an earlier version of Django or Django Rest Framework? Anold version of stored_messagesis available even
if it’snot supported anymore. Anyway, plan a migration to a newer version.DocumentationThe full documentation is athttp://django-stored-messages.rtfd.org. It includesmigration instructionsif you’re
migrating from an earlier version ofstored_messages.QuickstartFollow instruction for firing updjango.contrib.messages,
then install the app:$ pip install django-stored-messagesAdd it to the installed apps:INSTALLED_APPS=(# ...'stored_messages',)In the settings, tell Django which is the message storage:MESSAGE_STORAGE='stored_messages.storage.PersistentStorage'As last step, don’t forget to run Django migrations:$ python manage.py migrateThen use it in a project through the django.contrib.messages api. The app provides for convenience
some message levels which are persisted by default:importstored_messagesfromdjango.contribimportmessages# standard messagemessages.add_message(request,messages.INFO,'Hello world.')# this will be persisted and marked as 'unread'messages.add_message(request,stored_messages.STORED_INFO,'Hello world, to the database!')stored_messages expose the same api as well, so one can do:importstored_messagesstored_messages.add_message(request,stored_messages.INFO,'Hello!')If you want to use standard message levels but persist the messages, just add something like this
to the settings:fromdjango.contribimportmessagesSTORED_MESSAGES={# persist standard infos and standard errors'STORE_LEVELS':(messages.INFO,messages.ERROR,),}Iterating the messages will automatically mark them as read (but still persisted):storage=messages.get_messages(request)forunread_messageinstorage:# unread_message could be a stored message or a "standard" Django messagedo_something_with(unread_message)…unless you mark the storage as not used:storage.used=FalseYou can mark a stored message as read at any time:stored_messages.mark_read(request.user,message)Want to store your messages on Redis instead of your database? Here you go:STORED_MESSAGES={'STORAGE_BACKEND':'stored_messages.backends.RedisBackend','REDIS_URL':'redis://localhost:6379/0',}ExamplesGitHub-like notifications with Stored Messages and AngularJSHistory1.0.1 (2014-04-17)Major bug fixed oninbox_get()backend apiFixed InboxSerializer for redis backend messagesEnhanced testsuiteAdded MessageDoesNotExist descriptions and return 4041.0.0 (2014-04-01)New backend architecture with Redis supportSupport for broadcast messages0.2.1 (2013-12-23)Addedstored_messages_counttemplate tag and tests0.2.0 (2013-10-22)Addedstored_messages_archivetemplate tagExtended REST api0.1.2 (2013-10-13)Added specific template tags for stored messages0.1.1 (2013-10-10)Fixed setup.py0.1.0 (2013-10-08)First release on PyPI.