Skip to content
Snippets Groups Projects
Commit 55257269 authored by Julia Hansbrough's avatar Julia Hansbrough
Browse files

Added middleware for handling language changes

parent 7d81a510
No related merge requests found
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment