Commit 1cb7b321 authored by Sunil Mohan Adapa's avatar Sunil Mohan Adapa Committed by James Valleroy

locale: Decouple language setting from login views

Use the user_logged_in signal provided by Django to log the user in. This keeps
the login code simple and uncluttered.
Signed-off-by: Sunil Mohan Adapa's avatarSunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy's avatarJames Valleroy <jvalleroy@mailbox.org>
parent cfec96a9
......@@ -25,7 +25,6 @@ import urllib
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.views import LoginView, LogoutView
from django.http import HttpResponseRedirect
from django.utils import translation
from axes.decorators import axes_form_invalid
from axes.utils import reset
......@@ -66,7 +65,6 @@ class SSOLoginView(LoginView):
def dispatch(self, request, *args, **kwargs):
response = super(SSOLoginView, self).dispatch(request, *args, **kwargs)
if request.user.is_authenticated:
request.session[translation.LANGUAGE_SESSION_KEY] = request.user.userprofile.preferred_language
return set_ticket_cookie(request.user, response)
else:
return response
......
......@@ -71,3 +71,9 @@ def set_language(request, response, language_code):
path=settings.LANGUAGE_COOKIE_PATH,
domain=settings.LANGUAGE_COOKIE_DOMAIN,
)
@receiver(user_logged_in)
def _on_user_logged_in(sender, request, user, **kwargs):
"""When the user logs in, set the current language."""
set_language(request, None, user.userprofile.language)
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