django-flash
------------

    http://github.com/danielfm/django-flash/tree

django-flash adds a Rails-like flash context support to Django.


Installation
------------

The easiest way to install django-flash is via EasyInstall[1]. Follow these[2]
instructions to install EasyInstall if you don't have it already.

Then, execute the following command line to install the latest stable version
of django-flash:

    $ sudo easy_install django-flash

If you use Git and want to get the latest *development* version:

    $ git clone git://github.com/danielfm/django-flash.git
    $ cd django-flash
    $ sudo python setup.py install

Or get the latest *development* version as a tarball:

    $ wget http://github.com/danielfm/django-flash/tarball/master
    $ tar zxf danielfm-django-flash-XXXXXXXXXXXXXXXX.tar.gz
    $ cd danielfm-django-flash-XXXXXXXXXXXXXXXX
    $ sudo python setup.py install


Using django-flash
------------------

The first thing to do is plug django-flash to your Django project. To do this,
open your project's 'settings.py' file and do the following changes:

    TEMPLATE_CONTEXT_PROCESSORS = (
        'djangoflash.context_processors.flash',
    )

    MIDDLEWARE_CLASSES = (
        'django.contrib.sessions.middleware.SessionMiddleware',
        'djangoflash.middleware.FlashMiddleware',
    )

After doing that all HttpRequest objects received by your views will have an
extra attribute called 'flash'.

Here goes an example on how to actually use the the flash context:

    def my_view(request):
        #
        # It's like a dictionary...
        #
        
        # Add a string to the flash context
        request.flash['key'] = 'value'
        request.flash.put(another_key='another value')
        
        # Check if a value is available at the flash context
        print 'key' in request.flash
        
        # Get an object from the flash context
        print request.flash['key']
        print request.flash.get('key', 'default value')
        
        # Remove an object from the flash scope
        del request.flash['key']
        
        
        #
        # ...but it's not only a dictionary!
        #
        
        # Keep an object in the flash context for one more request
        request.flash.keep('key')
        
        # Keep all objects in the flash context for one more request
        request.flash.keep()
        
        # Add an object to the flash context, but make it available for use
        # at THIS request
        request.flash.now(key='value')
        
        return HttpResponseRedirect('/some/url/')

To access the flash context from a HTML template:

    <html>
        <head>...</head>
        <body>
            {% if flash.key %}
                <div id="flash_message_panel">
                    {{ flash.key }}
                </div>
            {% endif %}
        </body>
    </html>


Links
-----

[1] EasyInstall - http://peak.telecommunity.com/DevCenter/EasyInstall
[2] Setuptools  - http://pypi.python.org/pypi/setuptools


Authors
-------

Name:    Daniel Fernandes Martins <daniel.tritone@gmail.com>
Company: Destaquenet Technology Solutions <http://www.destaquenet.com/>


--EOF
