Make region sticky on Login page
The region from last login is used as the default selected region when the Login page loads. Change-Id: I3f431e8d2f89cd18ed873a54a1f4109ec95b9c11 Closes-Bug: #1392718
This commit is contained in:
parent
7c5f759473
commit
412e129b0a
|
@ -65,6 +65,9 @@ class Login(django_auth_forms.AuthenticationForm):
|
|||
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')
|
||||
|
||||
@staticmethod
|
||||
def get_region_choices():
|
||||
|
|
|
@ -92,6 +92,12 @@ def login(request, template_name=None, extra_context=None, **kwargs):
|
|||
authentication_form=form,
|
||||
extra_context=extra_context,
|
||||
**kwargs)
|
||||
# Save the region in the cookie, this is used as the default
|
||||
# selected region next time the Login form loads.
|
||||
if request.method == "POST":
|
||||
utils.set_response_cookie(res, 'login_region',
|
||||
request.POST.get('region', ''))
|
||||
|
||||
# Set the session data here because django's session key rotation
|
||||
# will erase it if we set it earlier.
|
||||
if request.user.is_authenticated():
|
||||
|
|
Loading…
Reference in New Issue