From 7e4f1d542e00b4d3121da6ae5524e95867f2371b Mon Sep 17 00:00:00 2001 From: root Date: Fri, 13 Nov 2009 20:18:55 -0500 Subject: better comments, email subscriptions, corrected view counter, some ie7 issues, wiki optional with settings.WIKI_ON, site can be mounted on arbitrary url prefix, english language improvements, added feedback form, versioned css and js files to force browser cache reload when settings.RESOURCE_REVISION is incremented , other fixes --- user_messages/__init__.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 user_messages/__init__.py (limited to 'user_messages/__init__.py') diff --git a/user_messages/__init__.py b/user_messages/__init__.py new file mode 100644 index 00000000..0136c888 --- /dev/null +++ b/user_messages/__init__.py @@ -0,0 +1,36 @@ +""" +Lightweight session-based messaging system. + +Time-stamp: <2009-03-10 19:22:29 carljm __init__.py> + +""" +VERSION = (0, 1, 'pre') + +def create_message (request, message): + """ + Create a message in the current session. + + """ + 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'." + + try: + request.session['messages'].append(message) + except KeyError: + request.session['messages'] = [message] + +def get_and_delete_messages (request, include_auth=False): + """ + Get and delete all messages for current session. + + Optionally also fetches user messages from django.contrib.auth. + + """ + 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'." + + messages = request.session.pop('messages', []) + + if include_auth and request.user.is_authenticated(): + messages.extend(request.user.get_and_delete_messages()) + + return messages + -- cgit v1.2.3-1-g7c22