# HG changeset patch # User Brian Neal # Date 1428456625 18000 # Node ID bd043677d527d1d1a349fd2655db704873516188 # Parent 1a832625c0476b0d4f84056cd00f91ff7f7c6881 Wiki app refactor for Django 1.7.7 upgrade. diff -r 1a832625c047 -r bd043677d527 wiki/__init__.py --- a/wiki/__init__.py Tue Apr 07 20:20:42 2015 -0500 +++ b/wiki/__init__.py Tue Apr 07 20:30:25 2015 -0500 @@ -0,0 +1,1 @@ +default_app_config = 'wiki.apps.WikiConfig' diff -r 1a832625c047 -r bd043677d527 wiki/apps.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wiki/apps.py Tue Apr 07 20:30:25 2015 -0500 @@ -0,0 +1,8 @@ +from django.apps import AppConfig + + +class WikiConfig(AppConfig): + name = 'wiki' + + def ready(self): + import wiki.receivers diff -r 1a832625c047 -r bd043677d527 wiki/models.py --- a/wiki/models.py Tue Apr 07 20:20:42 2015 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -"""The wiki application integrates an external Wiki app with our Django -application. - -The wiki application has no models. It consists of some signals and -middleware only. - -""" -import wiki.signals diff -r 1a832625c047 -r bd043677d527 wiki/receivers.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wiki/receivers.py Tue Apr 07 20:30:25 2015 -0500 @@ -0,0 +1,46 @@ +"""Signal handlers for wiki integration. + +We are interested in hearing about users logging in and out, so we can create +and destroy an external cookie to allow access to the wiki. + +""" +import logging + +from django.contrib.auth.signals import user_logged_in, user_logged_out + +from wiki.constants import SESSION_SET_MEMBER + +logger = logging.getLogger(__name__) + + +def login_callback(sender, request, user, **kwargs): + """Signal callback function for a user logging in. + + Sets a flag for the middleware to create an external cookie. + + """ + logger.info('User login: %s', user.username) + + request.wiki_set_cookie = True + + +def logout_callback(sender, request, user, **kwargs): + """Signal callback function for a user logging in. + + Sets a flag for the middleware to delete the external cookie. + + Since the user is about to logout, her session will be wiped out after + this function returns. This forces us to set an attribute on the request + object so that the response middleware can delete the wiki's cookie. + + """ + if user: + logger.info('User logout: %s', user.username) + + # Remember what Redis set member to delete by adding an attribute to the + # request object: + request.wiki_delete_cookie = request.session.get(SESSION_SET_MEMBER) + + +user_logged_in.connect(login_callback, dispatch_uid='wiki.receivers.login') +user_logged_out.connect(logout_callback, dispatch_uid='wiki.receivers.logout') diff -r 1a832625c047 -r bd043677d527 wiki/signals.py --- a/wiki/signals.py Tue Apr 07 20:20:42 2015 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -"""Signal handlers for wiki integration. - -We are interested in hearing about users logging in and out, so we can create -and destroy an external cookie to allow access to the wiki. - -""" -import logging - -from django.contrib.auth.signals import user_logged_in, user_logged_out - -from wiki.constants import SESSION_SET_MEMBER - -logger = logging.getLogger(__name__) - - -def login_callback(sender, request, user, **kwargs): - """Signal callback function for a user logging in. - - Sets a flag for the middleware to create an external cookie. - - """ - logger.info('User login: %s', user.username) - - request.wiki_set_cookie = True - - -def logout_callback(sender, request, user, **kwargs): - """Signal callback function for a user logging in. - - Sets a flag for the middleware to delete the external cookie. - - Since the user is about to logout, her session will be wiped out after - this function returns. This forces us to set an attribute on the request - object so that the response middleware can delete the wiki's cookie. - - """ - if user: - logger.info('User logout: %s', user.username) - - # Remember what Redis set member to delete by adding an attribute to the - # request object: - request.wiki_delete_cookie = request.session.get(SESSION_SET_MEMBER) - - -user_logged_in.connect(login_callback, dispatch_uid='wiki.signals.login') -user_logged_out.connect(logout_callback, dispatch_uid='wiki.signals.logout')