annotate wiki/signals.py @ 917:0365fdbb4d78

Fix app conflict with messages. Django's messages app label conflicts with our messages app. We can't easily rename our label as that will make us rename database tables. Since our app came first we'll just customize Django messages label. For Django 1.7.7 upgrade.
author Brian Neal <bgneal@gmail.com>
date Mon, 06 Apr 2015 20:02:25 -0500
parents 63603e931503
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@626 45 user_logged_in.connect(login_callback, dispatch_uid='wiki.signals.login')
bgneal@626 46 user_logged_out.connect(logout_callback, dispatch_uid='wiki.signals.logout')