diff --git a/plinth/modules/users/forms.py b/plinth/modules/users/forms.py index 6da76ec07..aa310ab44 100644 --- a/plinth/modules/users/forms.py +++ b/plinth/modules/users/forms.py @@ -19,7 +19,6 @@ from plinth import actions from plinth.errors import ActionError from plinth.modules import first_boot from plinth.modules.security import set_restricted_access -from plinth.translation import set_language from plinth.utils import is_user_admin from . import get_last_admin_user @@ -244,10 +243,6 @@ class UserUpdateForm(ValidNewUsernameCheckMixin, PasswordConfirmForm, auth_username = self.request.user.username confirm_password = self.cleaned_data['confirm_password'] - # If user is updating their own profile then only translate the pages - if self.username == auth_username: - set_language(self.request, None, user.userprofile.language) - if commit: user.save() self.save_m2m() diff --git a/plinth/modules/users/views.py b/plinth/modules/users/views.py index c7cb8bfc0..c0ea7986e 100644 --- a/plinth/modules/users/views.py +++ b/plinth/modules/users/views.py @@ -13,7 +13,7 @@ from django.utils.translation import gettext_lazy from django.views.generic.edit import (CreateView, DeleteView, FormView, UpdateView) -from plinth import actions +from plinth import actions, translation from plinth.errors import ActionError from plinth.modules import first_boot from plinth.utils import is_user_admin @@ -108,6 +108,18 @@ class UserUpdate(ContextMixin, SuccessMessageMixin, UpdateView): """Return the URL to redirect to in case of successful updation.""" return reverse('users:edit', kwargs={'slug': self.object.username}) + def form_valid(self, form): + """Set the user language if necessary.""" + response = super().form_valid(form) + + # If user is updating their own profile then set the language for + # current session too. + if self.object.username == self.request.user.username: + translation.set_language(self.request, response, + self.request.user.userprofile.language) + + return response + class UserDelete(ContextMixin, DeleteView): """Handle deleting users, showing a confirmation dialog first.