mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Stopped unconditionally reversing admin model add/change URLs.
Starting with [16857] this could cause HTTP 500 errors when `ModelAdmin.get_urls()` has been customized to the point it doesn't provide these standard URLs. Fixes #17333. Refs #15294. git-svn-id: http://code.djangoproject.com/svn/django/trunk@17237 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -38,7 +38,8 @@ from .models import (Article, BarAccount, CustomArticle, EmptyModel, FooAccount,
|
||||
Book, Promo, WorkHour, Employee, Question, Answer, Inquisition, Actor,
|
||||
FoodDelivery, RowLevelChangePermissionModel, Paper, CoverLetter, Story,
|
||||
OtherStory, ComplexSortedPerson, Parent, Child, AdminOrderedField,
|
||||
AdminOrderedModelMethod, AdminOrderedAdminMethod, AdminOrderedCallable)
|
||||
AdminOrderedModelMethod, AdminOrderedAdminMethod, AdminOrderedCallable,
|
||||
Report)
|
||||
|
||||
|
||||
ERROR_MESSAGE = "Please enter the correct username and password \
|
||||
@@ -1090,6 +1091,37 @@ class AdminViewPermissionsTest(TestCase):
|
||||
self.assertContains(response, 'id="login-form"')
|
||||
|
||||
|
||||
class AdminViewsNoUrlTest(TestCase):
|
||||
"""Regression test for #17333"""
|
||||
|
||||
urls = "regressiontests.admin_views.urls"
|
||||
fixtures = ['admin-views-users.xml']
|
||||
|
||||
def setUp(self):
|
||||
opts = Report._meta
|
||||
# User who can change Reports
|
||||
change_user = User.objects.get(username='changeuser')
|
||||
change_user.user_permissions.add(get_perm(Report,
|
||||
opts.get_change_permission()))
|
||||
|
||||
# login POST dict
|
||||
self.changeuser_login = {
|
||||
REDIRECT_FIELD_NAME: '/test_admin/admin/',
|
||||
LOGIN_FORM_KEY: 1,
|
||||
'username': 'changeuser',
|
||||
'password': 'secret',
|
||||
}
|
||||
|
||||
def test_no_standard_modeladmin_urls(self):
|
||||
"""Admin index views don't break when user's ModelAdmin removes standard urls"""
|
||||
self.client.get('/test_admin/admin/')
|
||||
self.client.post('/test_admin/admin/', self.changeuser_login)
|
||||
r = self.client.get('/test_admin/admin/')
|
||||
# we shouldn' get an 500 error caused by a NoReverseMatch
|
||||
self.assertEqual(r.status_code, 200)
|
||||
self.client.get('/test_admin/admin/logout/')
|
||||
|
||||
|
||||
class AdminViewDeletedObjectsTest(TestCase):
|
||||
urls = "regressiontests.admin_views.urls"
|
||||
fixtures = ['admin-views-users.xml', 'deleted-objects.xml']
|
||||
|
||||
Reference in New Issue
Block a user