diff --git a/cjworkbench/__init__.py b/cjworkbench/__init__.py index 8b1378917..ec1eb2c27 100644 --- a/cjworkbench/__init__.py +++ b/cjworkbench/__init__.py @@ -1 +1,2 @@ - +# this line required to get ServerConfig.ready() to run +default_app_config = "cjworkbench.apps.ServerConfig" diff --git a/cjworkbench/apps.py b/cjworkbench/apps.py index 54bed4b47..d312acde4 100644 --- a/cjworkbench/apps.py +++ b/cjworkbench/apps.py @@ -6,4 +6,4 @@ class ServerConfig(AppConfig): name = "cjworkbench" def ready(self): - pass + import cjworkbench.signals diff --git a/cjworkbench/signals.py b/cjworkbench/signals.py new file mode 100644 index 000000000..4fce26359 --- /dev/null +++ b/cjworkbench/signals.py @@ -0,0 +1,8 @@ +from allauth.account.signals import user_logged_in +from django.dispatch import receiver +from cjworkbench.i18n import set_language_cookie + + +@receiver(user_logged_in) +def set_locale_cookie_after_login(sender, *, response, user, **kwargs): + set_language_cookie(response, user.user_profile.locale_id) diff --git a/cjworkbench/urls.py b/cjworkbench/urls.py index f50ff7169..7bb95a1af 100644 --- a/cjworkbench/urls.py +++ b/cjworkbench/urls.py @@ -18,12 +18,10 @@ from django.contrib import admin from django.views.generic.base import RedirectView from cjworkbench.i18n.views import set_locale -from cjworkbench.views.login import LoginView urlpatterns = [ url(r"^admin/?", admin.site.urls), url(r"^account/signup/$", SignupView.as_view(), name="account_signup"), - url(r"^account/login/$", LoginView.as_view(), name="account_login"), url( r"^xyzzy/signup/$", RedirectView.as_view(url="/account/signup/", permanent=True), diff --git a/cjworkbench/views/login.py b/cjworkbench/views/login.py deleted file mode 100644 index 86d9c3e18..000000000 --- a/cjworkbench/views/login.py +++ /dev/null @@ -1,10 +0,0 @@ -from allauth.account import views -from cjworkbench.i18n import set_language_cookie - - -class LoginView(views.LoginView): - def dispatch(self, request, *args, **kwargs): - response = super(LoginView, self).dispatch(request, *args, **kwargs) - if request.user.is_authenticated: - set_language_cookie(response, request.user.user_profile.locale_id) - return response