mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
users: Help set language cookie when user profile is edited
This patch only ensures that response object is send along with set_language() call. In later changes, response object can be used by set_language() to set the language cookie. Tests: - Relevant functional tests pass. - Edit current user's language. The language is immediately set. - Edit another user's language. The language of the current session is not changed. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
79e5edb097
commit
45b5769ce6
@ -19,7 +19,6 @@ from plinth import actions
|
|||||||
from plinth.errors import ActionError
|
from plinth.errors import ActionError
|
||||||
from plinth.modules import first_boot
|
from plinth.modules import first_boot
|
||||||
from plinth.modules.security import set_restricted_access
|
from plinth.modules.security import set_restricted_access
|
||||||
from plinth.translation import set_language
|
|
||||||
from plinth.utils import is_user_admin
|
from plinth.utils import is_user_admin
|
||||||
|
|
||||||
from . import get_last_admin_user
|
from . import get_last_admin_user
|
||||||
@ -244,10 +243,6 @@ class UserUpdateForm(ValidNewUsernameCheckMixin, PasswordConfirmForm,
|
|||||||
auth_username = self.request.user.username
|
auth_username = self.request.user.username
|
||||||
confirm_password = self.cleaned_data['confirm_password']
|
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:
|
if commit:
|
||||||
user.save()
|
user.save()
|
||||||
self.save_m2m()
|
self.save_m2m()
|
||||||
|
|||||||
@ -13,7 +13,7 @@ from django.utils.translation import gettext_lazy
|
|||||||
from django.views.generic.edit import (CreateView, DeleteView, FormView,
|
from django.views.generic.edit import (CreateView, DeleteView, FormView,
|
||||||
UpdateView)
|
UpdateView)
|
||||||
|
|
||||||
from plinth import actions
|
from plinth import actions, translation
|
||||||
from plinth.errors import ActionError
|
from plinth.errors import ActionError
|
||||||
from plinth.modules import first_boot
|
from plinth.modules import first_boot
|
||||||
from plinth.utils import is_user_admin
|
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 the URL to redirect to in case of successful updation."""
|
||||||
return reverse('users:edit', kwargs={'slug': self.object.username})
|
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):
|
class UserDelete(ContextMixin, DeleteView):
|
||||||
"""Handle deleting users, showing a confirmation dialog first.
|
"""Handle deleting users, showing a confirmation dialog first.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user