]> git.openstreetmap.org Git - osqa.git/blob - forum/user_messages/__init__.py
Don't check minimum length of question, when body turned of, even on django 1.1.1.
[osqa.git] / forum / user_messages / __init__.py
1 """
2 Lightweight session-based messaging system.
3
4 Time-stamp: <2009-03-10 19:22:29 carljm __init__.py>
5
6 """
7 VERSION = (0, 1, 'pre')
8
9 def create_message (request, message):
10     """
11     Create a message in the current session.
12
13     """
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'."
15     
16     try:
17         request.session['messages'].append(message)
18     except KeyError:
19         request.session['messages'] = [message]
20
21 def get_and_delete_messages (request, include_auth=False):
22     """
23     Get and delete all messages for current session.
24
25     Optionally also fetches user messages from django.contrib.auth.
26
27     """
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'."
29
30     messages = request.session.pop('messages', [])
31
32     if include_auth and request.user.is_authenticated():
33         messages.extend(request.user.get_and_delete_messages())
34     
35     return messages
36