annotate wiki/receivers.py @ 964:51a2051588f5
Image uploading now expects a file.
Refactor image uploading to not expect a Django UploadedFile and use a regular
file instead. This will be needed for the future feature of being able to save
and upload images from the Internet.
author |
Brian Neal <bgneal@gmail.com> |
date |
Wed, 02 Sep 2015 20:50:08 -0500 |
parents |
bd043677d527 |
children |
|
rev |
line source |
bgneal@626
|
1 """Signal handlers for wiki integration.
|
bgneal@626
|
2
|
bgneal@629
|
3 We are interested in hearing about users logging in and out, so we can create
|
bgneal@629
|
4 and destroy an external cookie to allow access to the wiki.
|
bgneal@629
|
5
|
bgneal@626
|
6 """
|
bgneal@626
|
7 import logging
|
bgneal@626
|
8
|
bgneal@626
|
9 from django.contrib.auth.signals import user_logged_in, user_logged_out
|
bgneal@626
|
10
|
bgneal@629
|
11 from wiki.constants import SESSION_SET_MEMBER
|
bgneal@626
|
12
|
bgneal@626
|
13 logger = logging.getLogger(__name__)
|
bgneal@626
|
14
|
bgneal@626
|
15
|
bgneal@626
|
16 def login_callback(sender, request, user, **kwargs):
|
bgneal@626
|
17 """Signal callback function for a user logging in.
|
bgneal@626
|
18
|
bgneal@626
|
19 Sets a flag for the middleware to create an external cookie.
|
bgneal@626
|
20
|
bgneal@626
|
21 """
|
bgneal@626
|
22 logger.info('User login: %s', user.username)
|
bgneal@626
|
23
|
bgneal@629
|
24 request.wiki_set_cookie = True
|
bgneal@626
|
25
|
bgneal@626
|
26
|
bgneal@626
|
27 def logout_callback(sender, request, user, **kwargs):
|
bgneal@626
|
28 """Signal callback function for a user logging in.
|
bgneal@626
|
29
|
bgneal@626
|
30 Sets a flag for the middleware to delete the external cookie.
|
bgneal@626
|
31
|
bgneal@627
|
32 Since the user is about to logout, her session will be wiped out after
|
bgneal@627
|
33 this function returns. This forces us to set an attribute on the request
|
bgneal@627
|
34 object so that the response middleware can delete the wiki's cookie.
|
bgneal@627
|
35
|
bgneal@626
|
36 """
|
bgneal@630
|
37 if user:
|
bgneal@630
|
38 logger.info('User logout: %s', user.username)
|
bgneal@626
|
39
|
bgneal@630
|
40 # Remember what Redis set member to delete by adding an attribute to the
|
bgneal@630
|
41 # request object:
|
bgneal@630
|
42 request.wiki_delete_cookie = request.session.get(SESSION_SET_MEMBER)
|
bgneal@626
|
43
|
bgneal@626
|
44
|
bgneal@923
|
45 user_logged_in.connect(login_callback, dispatch_uid='wiki.receivers.login')
|
bgneal@923
|
46 user_logged_out.connect(logout_callback, dispatch_uid='wiki.receivers.logout')
|