Skip to content

Commit

Permalink
Fixed #25032 -- Removed double redirect in admin login.
Browse files Browse the repository at this point in the history
  • Loading branch information
adelton authored and timgraham committed Jul 3, 2015
1 parent 0e3193a commit 3353684
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion django/contrib/admin/sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ def login(self, request, extra_context=None):
)
if (REDIRECT_FIELD_NAME not in request.GET and
REDIRECT_FIELD_NAME not in request.POST):
context[REDIRECT_FIELD_NAME] = request.get_full_path()
context[REDIRECT_FIELD_NAME] = reverse('admin:index', current_app=self.name)
context.update(extra_context or {})

defaults = {
Expand Down
11 changes: 10 additions & 1 deletion tests/admin_views/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,7 @@ def test_login(self):
login_url = '%s?next=%s' % (reverse('admin:login'), reverse('admin:index'))
# Super User
response = self.client.get(self.index_url)
self.assertEqual(response.status_code, 302)
self.assertRedirects(response, login_url)
login = self.client.post(login_url, self.super_login)
self.assertRedirects(login, self.index_url)
self.assertFalse(login.context)
Expand Down Expand Up @@ -1480,6 +1480,15 @@ def test_login(self):
form = login.context[0].get('form')
self.assertEqual(form.errors['username'][0], 'This field is required.')

def test_login_redirect_for_direct_get(self):
"""
Login redirect should be to the admin index page when going directly to
/admin/login/.
"""
response = self.client.get(reverse('admin:login'))
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context[REDIRECT_FIELD_NAME], reverse('admin:index'))

def test_login_has_permission(self):
# Regular User should not be able to login.
response = self.client.get(reverse('has_permission_admin:index'))
Expand Down

0 comments on commit 3353684

Please sign in to comment.