summaryrefslogtreecommitdiffstats
path: root/session_messages/.svn/text-base
diff options
context:
space:
mode:
authorAdolfo Fitoria <fitoria@fitoria-laptop.(none)>2010-02-09 14:12:05 -0600
committerAdolfo Fitoria <fitoria@fitoria-laptop.(none)>2010-02-09 14:12:05 -0600
commit8de2b9131ddcef647799cf8e1e79921284523073 (patch)
tree81e17d84530990e35a0accba3a7886266a601482 /session_messages/.svn/text-base
parent7e95e6481d1e81e43d4b442cbcf3fe37f20d89cc (diff)
parent9d1fb9890b97beb55461ca34f9757bc685461130 (diff)
downloadaskbot-8de2b9131ddcef647799cf8e1e79921284523073.tar.gz
askbot-8de2b9131ddcef647799cf8e1e79921284523073.tar.bz2
askbot-8de2b9131ddcef647799cf8e1e79921284523073.zip
Merge branch 'evgenyfadeev/master'
Conflicts: .gitignore INSTALL TODO cnprog.wsgi django_authopenid/urls.py django_authopenid/views.py drop-all-tables.sh forum/auth.py forum/managers.py forum/models.py forum/templatetags/extra_tags.py forum/views.py locale/es/LC_MESSAGES/django.mo locale/es/LC_MESSAGES/django.po settings.py settings_local.py.dist sql_scripts/update_2009_01_25_001.sql sql_scripts/update_2009_02_26_001.sql sql_scripts/update_2009_04_10_001.sql templates/authopenid/confirm_email.txt templates/authopenid/sendpw_email.txt templates/content/js/compress.bat templates/content/js/flot-build.bat templates/content/style/style.css templates/footer.html templates/question.html templates/user_reputation.html templates/user_stats.html templates/user_votes.html templates/users_questions.html urls.py
Diffstat (limited to 'session_messages/.svn/text-base')
-rw-r--r--session_messages/.svn/text-base/__init__.py.svn-base36
-rw-r--r--session_messages/.svn/text-base/context_processors.py.svn-base48
-rw-r--r--session_messages/.svn/text-base/models.py.svn-base3
3 files changed, 87 insertions, 0 deletions
diff --git a/session_messages/.svn/text-base/__init__.py.svn-base b/session_messages/.svn/text-base/__init__.py.svn-base
new file mode 100644
index 00000000..0136c888
--- /dev/null
+++ b/session_messages/.svn/text-base/__init__.py.svn-base
@@ -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/session_messages/.svn/text-base/context_processors.py.svn-base b/session_messages/.svn/text-base/context_processors.py.svn-base
new file mode 100644
index 00000000..df9840fd
--- /dev/null
+++ b/session_messages/.svn/text-base/context_processors.py.svn-base
@@ -0,0 +1,48 @@
+"""
+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 session_messages import get_and_delete_messages
+
+def session_messages (request):
+ """
+ Returns session messages for the current session.
+
+ """
+ return { 'session_messages': LazyMessages(request) }
+
+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/session_messages/.svn/text-base/models.py.svn-base b/session_messages/.svn/text-base/models.py.svn-base
new file mode 100644
index 00000000..b67ead6d
--- /dev/null
+++ b/session_messages/.svn/text-base/models.py.svn-base
@@ -0,0 +1,3 @@
+"""
+blank models.py
+"""