| | 56 | |
| | 57 | == Potential API == |
| | 58 | django-notify is the current front-runner in terms of technical features so a sampling of the potential API is included below. Feel free to include the API(s) of other solutions as well for comparison. Discussion of the API should take place on the [http://groups.google.com/group/django-developers/browse_thread/thread/eba93088c649022b django-developers list]. |
| | 59 | |
| | 60 | === django-notify === |
| | 61 | Add the middleware to your MIDDLEWARE_CLASSES setting (after !SessionMiddleware): |
| | 62 | {{{ |
| | 63 | 'django_notify.middleware.NotificationsMiddleware', |
| | 64 | }}} |
| | 65 | |
| | 66 | Add the context processor into your TEMPLATE_CONTEXT_PROCESSORS setting: |
| | 67 | {{{ |
| | 68 | 'django_notify.context_processors.notifications', |
| | 69 | }}} |
| | 70 | |
| | 71 | Add a temporary notification message like this: |
| | 72 | {{{ |
| | 73 | request.notifications.add('Hello world.') |
| | 74 | # You can optionally provide a string containing tags (which is usually represented as HTML classes for the message). |
| | 75 | request.notifications.add('Your rating is over 9000!', 'error') |
| | 76 | }}} |
| | 77 | |
| | 78 | Use notifications in your template: |
| | 79 | {{{ |
| | 80 | {% if notifications %} |
| | 81 | <ul class="notifications"> |
| | 82 | {% for message in notifications %} |
| | 83 | <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li> |
| | 84 | {% endfor %} |
| | 85 | </ul> |
| | 86 | {% endif %} |
| | 87 | }}} |