Fix getting defaults from cookie for region field in password form

Since the normal form doesn't have a request attribute, we have to
pass the initial value for the region from the view.

Change-Id: Icea647ad13718b74528922f362ad665be1392e9b
Closes-bug: #1957926
This commit is contained in:
Radomir Dopieralski
2022-02-04 18:01:17 +01:00
parent a629893a10
commit 88dd887ad3
2 changed files with 4 additions and 4 deletions

View File

@@ -209,9 +209,6 @@ class Password(forms.Form):
if len(self.fields['region'].choices) == 1:
self.fields['region'].initial = self.fields['region'].choices[0][0]
self.fields['region'].widget = forms.widgets.HiddenInput()
elif len(self.fields['region'].choices) > 1:
self.fields['region'].initial = self.request.COOKIES.get(
'login_region')
@sensitive_variables('password', 'confirm_password', 'original_password')
def clean(self):

View File

@@ -460,7 +460,10 @@ class PasswordView(edit_views.FormView):
success_url = settings.LOGIN_URL
def get_initial(self):
return {'user_id': self.kwargs['user_id']}
return {
'user_id': self.kwargs['user_id'],
'region': self.request.COOKIES.get('login_region'),
}
def form_valid(self, form):
# We have no session here, so regular messages don't work.