Commit 55257269 by Julia Hansbrough

Added middleware for handling language changes

parent 7d81a510
......@@ -462,6 +462,7 @@ INSTALLED_APPS = (
# User preferences
'user_api',
'django_openid_auth',
)
......
"""
Middleware for UserPreferences
"""
from django.utils.translation.trans_real import parse_accept_lang_header
from user_api.models import UserPreference, LANGUAGE_KEY
class UserPreferenceMiddleware(object):
"""
Middleware for user preferences.
Ensures that, once set, a user's preferences are reflected in the page
whenever they are logged in.
"""
def process_request(self, request):
"""
If a user's UserPreference contains a language preference,
stick that preference in the session.
"""
query = UserPreference.objects.filter(user=request.user, key=LANGUAGE_KEY)
if query.exists():
# there should only be one result for query
request.session['django_language'] = query[0].value
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment