2 Lightweight session-based messaging system.
4 Time-stamp: <2009-03-10 19:22:29 carljm __init__.py>
7 VERSION = (0, 1, 'pre')
9 def create_message (request, message):
11 Create a message in the current session.
14 assert hasattr(request, 'session'), "django-session-messages requires session middleware to be installed. Edit your MIDDLEWARE_CLASSES setting to insert 'django.contrib.sessions.middleware.SessionMiddleware'."
17 request.session['messages'].append(message)
19 request.session['messages'] = [message]
21 def get_and_delete_messages (request, include_auth=False):
23 Get and delete all messages for current session.
25 Optionally also fetches user messages from django.contrib.auth.
28 assert hasattr(request, 'session'), "django-session-messages requires session middleware to be installed. Edit your MIDDLEWARE_CLASSES setting to insert 'django.contrib.sessions.middleware.SessionMiddleware'."
30 messages = request.session.pop('messages', [])
32 if include_auth and request.user.is_authenticated():
33 messages.extend(request.user.get_and_delete_messages())