{ "info": { "author": "AliLozano", "author_email": "alilozanoc@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python" ], "description": "Django Messages Extends\n==========================\n\n\n[](https://travis-ci.org/mpasternak/django-messages-extends)\n\n\nA Django app for extends Django's [messages framework](http://docs.djangoproject\n.com/en/dev/ref/contrib/messages/) (`django.contrib.messages`). framework by adding \"sticky\" and\n \"persistent\" backend message storages. This also supports the notion of sending\n persistent messages to other users in a machine-to-user process.\n\n\n## Storages ##\n\n### Sticky Storage ###\n\nA \"sticky\" message is a message where the user must hit the close button in order to get rid of\nit within that session.\n\n* For messages that are in some middleware or is only to the current request and don't need save it.\n* This is very similar to the default except that you explicitly must close the dialog to remove\nthe message.\n* This backend never save anything only simulate that do that.\n\n\n### Persistent Storage ###\n\nA \"persistent\" messages is a message where a message is retained across multiple sessions until\nthe user clicks the close button. The message is stored in the default_storage container\n(defaults to database).\n\n* Only for authenticated users, messages are stored in the database.\n* The messages has to be explicit read, and there are show while don't close it\n\nInstallation\n------------\n\nThis document assumes that you are familiar with Python and Django.\n\n1. [Download and unzip the app](https://github.com/AliLozano/django-messages-extends),\nor install using `pip`:\n\n $ pip install django-messages-extends\n\n2. Make sure `messages_extends` is on your `PYTHONPATH`.\n3. Add `messages_extends` to your `INSTALLED_APPS` setting.\n\n```python\nINSTALLED_APPS = (\n ...\n 'messages_extends',\n)\n```\n\n4. Make sure Django's `MessageMiddleware` is in your `MIDDLEWARE_CLASSES` setting (which is the\ncase by default):\n\n```python\nMIDDLEWARE_CLASSES = (\n ...\n 'django.contrib.messages.middleware.MessageMiddleware',\n)\n```\n\n5. Add the messages_extends URLs to your URL conf. For instance, in order to make messages\navailable under `http://domain.com/messages/`, add the following line to `urls.py`.\n\n```python\nurlpatterns = patterns('',\n (r'^messages/', include('messages_extends.urls')),\n ...\n)\n```\n\n6. In your settings, set the message [storage backend](http://docs.djangoproject.com/en/dev/ref/contrib/messages/#message-storage-backends)to `messages_extends.storages.FallbackStorage`:\n\n```python\nMESSAGE_STORAGE = 'messages_extends.storages.FallbackStorage'\n```\n\n7. Set up the database tables using\n\n\t $ manage.py syncdb\n\n8. If you want to use the bundled templates, add the `templates` directory to your\n`TEMPLATE_DIRS` setting:\n\n```python\nTEMPLATE_DIRS = (\n ...\n 'path/to/messages_extends/templates')\n)\n```\n\n\nUsing messages in views and templates\n-------------------------------------\n\n### Message levels ###\n\nDjango's messages framework provides a number of [message levels](http://docs.djangoproject.com/en/dev/ref/contrib/messages/#message-levels)\nfor various purposes such as success messages, warnings etc. This app provides constants with the\n same names, the difference being that messages with these levels are going to be persistent:\n\n```python\nfrom messages_extends import constants as constants_messages\n\n# default messages level\nconstants_messages.DEBUG = 10\nconstants_messages.INFO = 20\nconstants_messages.SUCCESS = 25\nconstants_messages.WARNING = 30\nconstants_messages.ERROR = 40\n\n# persistent messages level\nconstants_messages.DEBUG_PERSISTENT = 9\nconstants_messages.INFO_PERSISTENT = 19\nconstants_messages.SUCCESS_PERSISTENT = 24\nconstants_messages.WARNING_PERSISTENT = 29\nconstants_messages.ERROR_PERSISTENT = 39\n\n# sticky messages level\nconstants_messages.DEBUG_STICKY = 8\nconstants_messages.INFO_STICKY = 18\nconstants_messages.SUCCESS_STICKY = 23\nconstants_messages.WARNING_STICKY = 28\nconstants_messages.ERROR_STICKY = 38\n```\n\n### Adding a message ###\n\nSince the app is implemented as a [storage backend](http://docs.djangoproject.com/en/dev/ref/contrib/messages/#message-storage-backends)\nfor Django's [messages framework](http://docs.djangoproject.com/en/dev/ref/contrib/messages/), you\ncan still use the regular Django API to add a message:\n\n```python\nfrom django.contrib import messages\nmessages.add_message(request, messages.INFO, 'Hello world.')\n```\n\nOr use persistent messages with constants in messages_extends.constants\n\n```python\nfrom django.contrib import messages\nfrom messages_extends import constants as constants_messages\nmessages.add_message(request, constants_messages.WARNING_PERSISTENT, 'You are going to see this message until you mark it as read.')\n```\n\nOr via the shortcut method.\n\n```python\nmessages.add_persistant_error(request, 'Houston we have a problem..')\n```\n\nNote that this is only possible for logged-in users, so you are probably going to have make sure\nthat the current user is not anonymous using `request.user.is_authenticated()`. Adding a\npersistent message for anonymous users raises a `NotImplementedError`.\n\nAnd sticky messages:\n\n```python\nfrom django.contrib import messages\nfrom messages_extends import constants as constants_messages\nmessages.add_message(request, constants_messages.WARNING_STICKY, 'You will going to see this messages only in this request')\n```\n\nYou can also pass this function a `User` object if the message is supposed to be sent to a user\nother than the one who is currently authenticated. User Sally will see this message the next time\n she logs in:\n\n```python\nfrom django.contrib import messages\nfrom messages_extends import constants as constants_messages\nfrom django.contrib.auth.models import User\nsally = User.objects.get(username='Sally')\nmessages.add_message(request, constants_messages.INFO_PERSISTENT, \"Hola abc desde %s\" %request.user, user=sally)\n```\n\nTo persistent storages, there are other params like expires that is a datetime.\n\n### Displaying messages ###\n\nMessages can be displayed [as described in the Django manual](http://docs.djangoproject.com/en/dev/ref/contrib/messages/#displaying-messages).\nHowever, you are probably going to want to include links tags for closing each message (i.e.\nmarking it as read). In your template, use something like:\n\n```htmldjango\n{% for message in messages %}\n