summaryrefslogtreecommitdiffstats
path: root/middleware
diff options
context:
space:
mode:
authorroot <root@u15356270.onlinehome-server.com>2009-11-13 20:18:55 -0500
committerroot <root@u15356270.onlinehome-server.com>2009-11-13 20:31:40 -0500
commitebb0f636ae8f7db4e7a2e7470e449af3d96b15c0 (patch)
tree5a3edfb81cc137dbc877f75f9bde80e9720b3ba0 /middleware
parent6ada6c5003b78d143052d33be432a9fabd75ba6d (diff)
downloadaskbot-ebb0f636ae8f7db4e7a2e7470e449af3d96b15c0.tar.gz
askbot-ebb0f636ae8f7db4e7a2e7470e449af3d96b15c0.tar.bz2
askbot-ebb0f636ae8f7db4e7a2e7470e449af3d96b15c0.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 'middleware')
-rw-r--r--middleware/anon_user.py26
-rw-r--r--middleware/cancel.py15
-rw-r--r--middleware/pagesize.py6
3 files changed, 46 insertions, 1 deletions
diff --git a/middleware/anon_user.py b/middleware/anon_user.py
new file mode 100644
index 00000000..c7ff05bc
--- /dev/null
+++ b/middleware/anon_user.py
@@ -0,0 +1,26 @@
+from django.http import HttpResponseRedirect
+from django_authopenid.util import get_next_url
+from user_messages import create_message, get_and_delete_messages
+import logging
+
+class AnonymousMessageManager(object):
+ def __init__(self,request):
+ self.request = request
+ def create(self,message=''):
+ create_message(self.request,message)
+ def get_and_delete(self):
+ messages = get_and_delete_messages(self.request)
+ return messages
+
+def dummy_deepcopy(*arg):
+ """this is necessary to prevent deepcopy() on anonymous user object
+ that now contains reference to request, which cannot be deepcopied
+ """
+ return None
+
+class ConnectToSessionMessagesMiddleware(object):
+ def process_request(self, request):
+ if not request.user.is_authenticated():
+ request.user.__deepcopy__ = dummy_deepcopy #plug on deepcopy which may be called by django db "driver"
+ request.user.message_set = AnonymousMessageManager(request) #here request is linked to anon user
+ request.user.get_and_delete_messages = request.user.message_set.get_and_delete
diff --git a/middleware/cancel.py b/middleware/cancel.py
new file mode 100644
index 00000000..f03ff35e
--- /dev/null
+++ b/middleware/cancel.py
@@ -0,0 +1,15 @@
+from django.http import HttpResponseRedirect
+from django_authopenid.util import get_next_url
+import logging
+class CancelActionMiddleware(object):
+ def process_view(self, request, view_func, view_args, view_kwargs):
+ if 'cancel' in request.REQUEST:
+ #todo use session messages for the anonymous users
+ try:
+ msg = getattr(view_func,'CANCEL_MESSAGE')
+ except AttributeError:
+ msg = 'action canceled'
+ request.user.message_set.create(message=msg)
+ return HttpResponseRedirect(get_next_url(request))
+ else:
+ return None
diff --git a/middleware/pagesize.py b/middleware/pagesize.py
index bb6c7aa3..f6e6fcfd 100644
--- a/middleware/pagesize.py
+++ b/middleware/pagesize.py
@@ -26,4 +26,8 @@ class QuestionsPageSizeMiddleware(object):
user.questions_per_page = pagesize
user.save()
# put pagesize into session
- request.session["pagesize"] = pagesize \ No newline at end of file
+ request.session["pagesize"] = pagesize
+
+ def process_exception(self,request,exception):
+ import logging
+ logging.debug('have exception %s' % str(exception))