<!--*-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'`.
