diff --git a/babybuddy/templates/babybuddy/user_settings_form.html b/babybuddy/templates/babybuddy/user_settings_form.html index b459d511..e3b3d7b6 100644 --- a/babybuddy/templates/babybuddy/user_settings_form.html +++ b/babybuddy/templates/babybuddy/user_settings_form.html @@ -65,6 +65,7 @@ + diff --git a/babybuddy/tests/tests_forms.py b/babybuddy/tests/tests_forms.py index 3f42b8d4..e46fa638 100644 --- a/babybuddy/tests/tests_forms.py +++ b/babybuddy/tests/tests_forms.py @@ -30,7 +30,8 @@ class FormsTestCase(TestCase): 'last_name': 'Name', 'email': 'user@user.user', 'dashboard_refresh_rate': '', - 'language': 'en' + 'language': 'en', + 'next': '/user/settings/' } def test_change_password(self): diff --git a/babybuddy/tests/tests_translations.py b/babybuddy/tests/tests_translations.py deleted file mode 100644 index 358537ea..00000000 --- a/babybuddy/tests/tests_translations.py +++ /dev/null @@ -1,45 +0,0 @@ -# -*- coding: utf-8 -*- -from django.test import TestCase -from django.test import Client as HttpClient -from django.contrib.auth.models import User -from django.core.management import call_command - -from faker import Factory - - -class TranslationTestCase(TestCase): - @classmethod - def setUpClass(cls): - super(TranslationTestCase, cls).setUpClass() - fake = Factory.create() - call_command('migrate', verbosity=0) - - cls.c = HttpClient() - - fake_user = fake.simple_profile() - cls.credentials = { - 'username': fake_user['username'], - 'password': fake.password() - } - cls.user = User.objects.create_user( - is_superuser=True, **cls.credentials) - - cls.params_template = { - 'first_name': 'User', - 'last_name': 'Name', - 'email': 'user@user.user', - 'dashboard_refresh_rate': '', - 'language': 'en' - } - - cls.c.login(**cls.credentials) - - def test_translation_fr(self): - params = self.params_template.copy() - params['language'] = 'fr' - - page = self.c.post('/user/settings/', data=params, follow=True) - self.assertContains(page, 'Paramètres Utilisateur') - - page = self.c.get('/welcome/') - self.assertContains(page, 'Bienvenue à Baby Buddy!') diff --git a/babybuddy/views.py b/babybuddy/views.py index 691832a8..66209cc0 100644 --- a/babybuddy/views.py +++ b/babybuddy/views.py @@ -8,11 +8,11 @@ from django.contrib.messages.views import SuccessMessageMixin from django.shortcuts import redirect, render from django.urls import reverse, reverse_lazy from django.utils.text import format_lazy -from django.utils.translation import gettext as _, gettext_lazy +from django.utils.translation import activate, gettext as _, gettext_lazy from django.views.generic import View from django.views.generic.base import TemplateView, RedirectView from django.views.generic.edit import CreateView, UpdateView, DeleteView -from django.views.i18n import set_language +from django.views.i18n import set_language, LANGUAGE_QUERY_PARAMETER from django_filters.views import FilterView @@ -140,9 +140,9 @@ class UserSettings(LoginRequiredMixin, View): user_settings = form_settings.save(commit=False) user.settings = user_settings user.save() - set_language(request) + activate(request.POST.get(LANGUAGE_QUERY_PARAMETER)) messages.success(request, _('Settings saved!')) - return redirect('babybuddy:user-settings') + return set_language(request) return render(request, self.template_name, { 'user_form': form_user, 'settings_form': form_settings