summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZoltan Gyarmati <mr.zoltan.gyarmati@gmail.com>2017-02-07 10:17:36 +0100
committerTim Graham <timograham@gmail.com>2017-02-07 08:54:21 -0500
commit41ba27fefdd313333d94408802afff36a9eedb83 (patch)
tree46a9790184dad74e15e70edc8627b078d3f4ccf6
parent10c47f7b47c3b58eda579918d8381a066d43e788 (diff)
Fixed #27815 -- Made LoginView pass the request kwarg to AuthenticationForm.
-rw-r--r--django/contrib/auth/views.py5
-rw-r--r--tests/auth_tests/test_views.py11
2 files changed, 11 insertions, 5 deletions
diff --git a/django/contrib/auth/views.py b/django/contrib/auth/views.py
index b2c37ebdb7..e24af5d9b0 100644
--- a/django/contrib/auth/views.py
+++ b/django/contrib/auth/views.py
@@ -100,6 +100,11 @@ class LoginView(SuccessURLAllowedHostsMixin, FormView):
context.update(self.extra_context)
return context
+ def get_form_kwargs(self):
+ kwargs = super().get_form_kwargs()
+ kwargs['request'] = self.request
+ return kwargs
+
def login(request, *args, **kwargs):
warnings.warn(
diff --git a/tests/auth_tests/test_views.py b/tests/auth_tests/test_views.py
index 7436473635..8f946a9a38 100644
--- a/tests/auth_tests/test_views.py
+++ b/tests/auth_tests/test_views.py
@@ -594,13 +594,14 @@ class LoginTest(AuthViewsTestCase):
self.assertEqual(response.url, settings.LOGIN_REDIRECT_URL)
def test_login_form_contains_request(self):
- # 15198
- self.client.post('/custom_requestauth_login/', {
+ # The custom authentication form for this login requires a request to
+ # initialize it.
+ response = self.client.post('/custom_request_auth_login/', {
'username': 'testclient',
'password': 'password',
- }, follow=True)
- # the custom authentication form used by this login asserts
- # that a request is passed to the form successfully.
+ })
+ # The login was successful.
+ self.assertRedirects(response, settings.LOGIN_REDIRECT_URL, fetch_redirect_response=False)
def test_login_csrf_rotate(self):
"""