Mercurial > public > sg101
comparison wiki/signals.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 | 63603e931503 |
comparison
equal
deleted
inserted
replaced
628:c6292e46e617 | 629:f4c043cf55ac |
---|---|
1 """Signal handlers for wiki integration. | 1 """Signal handlers for wiki integration. |
2 | |
3 We are interested in hearing about users logging in and out, so we can create | |
4 and destroy an external cookie to allow access to the wiki. | |
2 | 5 |
3 """ | 6 """ |
4 import logging | 7 import logging |
5 | 8 |
6 from django.contrib.auth.signals import user_logged_in, user_logged_out | 9 from django.contrib.auth.signals import user_logged_in, user_logged_out |
7 | 10 |
8 from wiki.constants import SESSION_SET_FLAG, SESSION_SET_MEMBER | 11 from wiki.constants import SESSION_SET_MEMBER |
9 | 12 |
10 logger = logging.getLogger(__name__) | 13 logger = logging.getLogger(__name__) |
11 | 14 |
12 | 15 |
13 def login_callback(sender, request, user, **kwargs): | 16 def login_callback(sender, request, user, **kwargs): |
16 Sets a flag for the middleware to create an external cookie. | 19 Sets a flag for the middleware to create an external cookie. |
17 | 20 |
18 """ | 21 """ |
19 logger.info('User login: %s', user.username) | 22 logger.info('User login: %s', user.username) |
20 | 23 |
21 request.session[SESSION_SET_FLAG] = True | 24 request.wiki_set_cookie = True |
22 | 25 |
23 | 26 |
24 def logout_callback(sender, request, user, **kwargs): | 27 def logout_callback(sender, request, user, **kwargs): |
25 """Signal callback function for a user logging in. | 28 """Signal callback function for a user logging in. |
26 | 29 |