Mercurial > public > sg101
comparison 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 |
comparison
equal
deleted
inserted
replaced
628:c6292e46e617 | 629:f4c043cf55ac |
---|---|
10 | 10 |
11 from django.conf import settings | 11 from django.conf import settings |
12 import redis | 12 import redis |
13 | 13 |
14 from core.services import get_redis_connection | 14 from core.services import get_redis_connection |
15 from wiki.constants import SESSION_SET_FLAG, SESSION_SET_MEMBER | 15 from wiki.constants import SESSION_SET_MEMBER |
16 | 16 |
17 | 17 |
18 logger = logging.getLogger(__name__) | 18 logger = logging.getLogger(__name__) |
19 | 19 |
20 | 20 |
98 | 98 |
99 """ | 99 """ |
100 | 100 |
101 def process_response(self, request, response): | 101 def process_response(self, request, response): |
102 | 102 |
103 if request.session.get(SESSION_SET_FLAG, False): | 103 if hasattr(request, 'wiki_set_cookie'): |
104 del request.session[SESSION_SET_FLAG] | |
105 | |
106 create_wiki_session(request, response) | 104 create_wiki_session(request, response) |
107 | |
108 elif hasattr(request, 'wiki_delete_cookie'): | 105 elif hasattr(request, 'wiki_delete_cookie'): |
109 | |
110 destroy_wiki_session(request.wiki_delete_cookie, response) | 106 destroy_wiki_session(request.wiki_delete_cookie, response) |
111 | 107 |
112 return response | 108 return response |