1
0
mirror of https://github.com/django/django.git synced 2025-07-04 09:49:12 +00:00

newforms-admin: custom URL handling in admin now redirects to add trailing slash if needed - this fixes several bugs that occurred when you navigated to an admin page and omitted the trailing slash.

git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@7825 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Simon Willison 2008-07-02 08:32:55 +00:00
parent 2e5cc7413f
commit f918f9180f
2 changed files with 15 additions and 0 deletions

View File

@ -100,6 +100,9 @@ class AdminSite(object):
`url` is the remainder of the URL -- e.g. 'comments/comment/'. `url` is the remainder of the URL -- e.g. 'comments/comment/'.
""" """
if request.method == 'GET' and not request.path.endswith('/'):
return http.HttpResponseRedirect(request.path + '/')
# Figure out the admin base URL path and stash it for later use # Figure out the admin base URL path and stash it for later use
self.root_path = re.sub(re.escape(url) + '$', '', request.path) self.root_path = re.sub(re.escape(url) + '$', '', request.path)

View File

@ -74,6 +74,18 @@ class AdminViewPermissionsTest(TestCase):
'username': 'joepublic', 'username': 'joepublic',
'password': 'secret'} 'password': 'secret'}
def testTrailingSlashRequired(self):
"""
If you leave off the trailing slash, app should redirect and add it.
"""
self.client.post('/test_admin/admin/', self.super_login)
request = self.client.get(
'/test_admin/admin/admin_views/article/add'
)
self.assertRedirects(request,
'/test_admin/admin/admin_views/article/add/'
)
def testLogin(self): def testLogin(self):
""" """