diff wiki/middleware.py @ 629:f4c043cf55ac

Wiki integration. Requests don't always have sessions. In particular this occurs when a request is made without a trailing slash. The Common middleware redirects when this happens, and the middleware process_request() processing stops before a session can get added. So just set an attribute on the request object for each operation. This seemed weird to me at first, but there are plenty of examples of this in the Django code base already.
author Brian Neal <bgneal@gmail.com>
date Tue, 13 Nov 2012 13:50:06 -0600
parents a4300639c6e7
children efac466a05d4
line wrap: on
line diff
--- a/wiki/middleware.py	Mon Nov 12 16:40:54 2012 -0600
+++ b/wiki/middleware.py	Tue Nov 13 13:50:06 2012 -0600
@@ -12,7 +12,7 @@
 import redis
 
 from core.services import get_redis_connection
-from wiki.constants import SESSION_SET_FLAG, SESSION_SET_MEMBER
+from wiki.constants import SESSION_SET_MEMBER
 
 
 logger = logging.getLogger(__name__)
@@ -100,13 +100,9 @@
 
     def process_response(self, request, response):
 
-        if request.session.get(SESSION_SET_FLAG, False):
-            del request.session[SESSION_SET_FLAG]
-
+        if hasattr(request, 'wiki_set_cookie'):
             create_wiki_session(request, response)
-
         elif hasattr(request, 'wiki_delete_cookie'):
-
             destroy_wiki_session(request.wiki_delete_cookie, response)
 
         return response