<!--*-markdown-*-->

# `django-attention`

`django-attention` is a small session-based flash notice system for Django. It can be used to send messages to the next (or any future) page, with an optional ‘level’ indicating the urgency or purpose of the message.

## Installation

*   Install `django-attention` from PyPI:
    
        $ easy_install django-attention # OR 
        $ pip install django-attention

*   Add `djattn` to your `INSTALLED_APPS` setting. You’ll also need to have
    `django.contrib.sessions` installed.

*   Add `'djattn.AttentionMiddleware'` to your `MIDDLEWARE_CLASSES` setting,
    making sure it comes after the session middleware.

*   If you want to access the notices from your templates, just add
    `'django.core.context_processors.request'` to your
    `TEMPLATE_CONTEXT_PROCESSORS` setting.

## Usage

### Quickstart

From view code:

    def some_view(request):
        # ...process the request...
        request.attn.info('Something has happened!')
        # ...return a response...

From the template:

    <ul id="notices">
      {% for notice in request.attn %}
        <li class="notice.level">{{ notice.message|escape }}</li>
      {% endfor %}
    </ul>

### `request.attn`

The `AttentionMiddleware` adds an `attn` attribute to each request. This is an
instance of `djattn.AttentionHandler`, and it implements all the methods needed
for setting/getting notices.

You can customize the attribute it’s set to with the `ATTENTION_REQUEST_ATTR`
setting.

`request.attn` also supports iteration (as you can see from
`{% for notice in request.attn %}` above). Iteration removes the notices from
the session as it yields them.

Note that you can also control the session key where the messages are stored
with the `ATTENTION_SESSION_KEY` setting. This defaults to `'_attn'`.

## (Un)license

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
software, either in source code form or as a compiled binary, for any purpose,
commercial or non-commercial, and by any means.

In jurisdictions that recognize copyright laws, the author or authors of this
software dedicate any and all copyright interest in the software to the public
domain. We make this dedication for the benefit of the public at large and to
the detriment of our heirs and successors. We intend this dedication to be an
overt act of relinquishment in perpetuity of all present and future rights to
this software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org/>