summaryrefslogtreecommitdiffstats
path: root/user_messages
diff options
context:
space:
mode:
authorroot <root@u15356270.onlinehome-server.com>2009-11-13 20:18:31 -0500
committerroot <root@u15356270.onlinehome-server.com>2009-11-13 20:31:16 -0500
commit40b5c06085fe3d079094e8ef779a7b119586f9e8 (patch)
tree5a3edfb81cc137dbc877f75f9bde80e9720b3ba0 /user_messages
parent2022b772a01f36fa74de002b5370dd70b6c051ba (diff)
downloadaskbot-40b5c06085fe3d079094e8ef779a7b119586f9e8.tar.gz
askbot-40b5c06085fe3d079094e8ef779a7b119586f9e8.tar.bz2
askbot-40b5c06085fe3d079094e8ef779a7b119586f9e8.zip
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
Diffstat (limited to 'user_messages')
-rw-r--r--user_messages/__init__.py36
-rw-r--r--user_messages/context_processors.py52
-rw-r--r--user_messages/models.py3
3 files changed, 91 insertions, 0 deletions
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
+
diff --git a/user_messages/context_processors.py b/user_messages/context_processors.py
new file mode 100644
index 00000000..894f5801
--- /dev/null
+++ b/user_messages/context_processors.py
@@ -0,0 +1,52 @@
+"""
+Context processor for lightweight session messages.
+
+Time-stamp: <2008-07-19 23:16:19 carljm context_processors.py>
+
+"""
+from django.utils.encoding import StrAndUnicode
+
+from user_messages import get_and_delete_messages
+
+def user_messages (request):
+ """
+ Returns session messages for the current session.
+
+ """
+ messages = request.user.get_and_delete_messages()
+ #if request.user.is_authenticated():
+ #else:
+ # messages = LazyMessages(request)
+ return { 'user_messages': messages }
+
+class LazyMessages (StrAndUnicode):
+ """
+ Lazy message container, so messages aren't actually retrieved from
+ session and deleted until the template asks for them.
+
+ """
+ def __init__(self, request):
+ self.request = request
+
+ def __iter__(self):
+ return iter(self.messages)
+
+ def __len__(self):
+ return len(self.messages)
+
+ def __nonzero__(self):
+ return bool(self.messages)
+
+ def __unicode__(self):
+ return unicode(self.messages)
+
+ def __getitem__(self, *args, **kwargs):
+ return self.messages.__getitem__(*args, **kwargs)
+
+ def _get_messages(self):
+ if hasattr(self, '_messages'):
+ return self._messages
+ self._messages = get_and_delete_messages(self.request)
+ return self._messages
+ messages = property(_get_messages)
+
diff --git a/user_messages/models.py b/user_messages/models.py
new file mode 100644
index 00000000..b67ead6d
--- /dev/null
+++ b/user_messages/models.py
@@ -0,0 +1,3 @@
+"""
+blank models.py
+"""