[1.5.x] Fixed #18697 -- Made values accepted for two customizable admin templates consistent.

Thanks and at cloverfastfood dot com for the report.

b64d30405a from master.
This commit is contained in:
Ramiro Morales 2012-12-03 20:39:03 -03:00
parent b6f67bd50e
commit 6a098aa6f2
5 changed files with 28 additions and 8 deletions

View File

@ -389,9 +389,9 @@ class AdminSite(object):
'app_list': app_list, 'app_list': app_list,
} }
context.update(extra_context or {}) context.update(extra_context or {})
return TemplateResponse(request, [ return TemplateResponse(request, self.index_template or
self.index_template or 'admin/index.html', 'admin/index.html', context,
], context, current_app=self.name) current_app=self.name)
def app_index(self, request, app_label, extra_context=None): def app_index(self, request, app_label, extra_context=None):
user = request.user user = request.user

View File

@ -148,10 +148,10 @@ class UserAdmin(admin.ModelAdmin):
'save_as': False, 'save_as': False,
'show_save': True, 'show_save': True,
} }
return TemplateResponse(request, [ return TemplateResponse(request,
self.change_user_password_template or self.change_user_password_template or
'admin/auth/user/change_password.html' 'admin/auth/user/change_password.html',
], context, current_app=self.admin_site.name) context, current_app=self.admin_site.name)
def response_add(self, request, obj, **kwargs): def response_add(self, request, obj, **kwargs):
""" """

View File

@ -16,7 +16,7 @@ class Admin2(admin.AdminSite):
login_form = forms.CustomAdminAuthenticationForm login_form = forms.CustomAdminAuthenticationForm
login_template = 'custom_admin/login.html' login_template = 'custom_admin/login.html'
logout_template = 'custom_admin/logout.html' logout_template = 'custom_admin/logout.html'
index_template = 'custom_admin/index.html' index_template = ['custom_admin/index.html'] # a list, to test fix for #18697
password_change_template = 'custom_admin/password_change_form.html' password_change_template = 'custom_admin/password_change_form.html'
password_change_done_template = 'custom_admin/password_change_done.html' password_change_done_template = 'custom_admin/password_change_done.html'
@ -40,6 +40,10 @@ class UserLimitedAdmin(UserAdmin):
return qs.filter(is_superuser=False) return qs.filter(is_superuser=False)
class CustomPwdTemplateUserAdmin(UserAdmin):
change_user_password_template = ['admin/auth/user/change_password.html'] # a list, to test fix for #18697
site = Admin2(name="admin2") site = Admin2(name="admin2")
site.register(models.Article, base_admin.ArticleAdmin) site.register(models.Article, base_admin.ArticleAdmin)
@ -50,3 +54,6 @@ site.register(models.ChapterXtra1, base_admin.ChapterXtra1Admin)
site.register(User, UserLimitedAdmin) site.register(User, UserLimitedAdmin)
site.register(models.UndeletableObject, base_admin.UndeletableObjectAdmin) site.register(models.UndeletableObject, base_admin.UndeletableObjectAdmin)
site.register(models.Simple, base_admin.AttributeErrorRaisingAdmin) site.register(models.Simple, base_admin.AttributeErrorRaisingAdmin)
simple_site = Admin2(name='admin4')
simple_site.register(User, CustomPwdTemplateUserAdmin)

View File

@ -770,7 +770,10 @@ class CustomModelAdminTest(AdminViewBasicTest):
self.assertContains(response, 'Hello from a custom logout template') self.assertContains(response, 'Hello from a custom logout template')
def testCustomAdminSiteIndexViewAndTemplate(self): def testCustomAdminSiteIndexViewAndTemplate(self):
response = self.client.get('/test_admin/admin2/') try:
response = self.client.get('/test_admin/admin2/')
except TypeError:
self.fail('AdminSite.index_template should accept a list of template paths')
self.assertIsInstance(response, TemplateResponse) self.assertIsInstance(response, TemplateResponse)
self.assertTemplateUsed(response, 'custom_admin/index.html') self.assertTemplateUsed(response, 'custom_admin/index.html')
self.assertContains(response, 'Hello from a custom index template *bar*') self.assertContains(response, 'Hello from a custom index template *bar*')
@ -792,6 +795,15 @@ class CustomModelAdminTest(AdminViewBasicTest):
response = self.client.get('/test_admin/%s/my_view/' % self.urlbit) response = self.client.get('/test_admin/%s/my_view/' % self.urlbit)
self.assertEqual(response.content, b"Django is a magical pony!") self.assertEqual(response.content, b"Django is a magical pony!")
def test_pwd_change_custom_template(self):
self.client.login(username='super', password='secret')
su = User.objects.get(username='super')
try:
response = self.client.get('/test_admin/admin4/auth/user/%s/password/' % su.pk)
except TypeError:
self.fail('ModelAdmin.change_user_password_template should accept a list of template paths')
self.assertEqual(response.status_code, 200)
def get_perm(Model, perm): def get_perm(Model, perm):
"""Return the permission object, for the Model""" """Return the permission object, for the Model"""

View File

@ -11,4 +11,5 @@ urlpatterns = patterns('',
(r'^test_admin/admin/', include(admin.site.urls)), (r'^test_admin/admin/', include(admin.site.urls)),
(r'^test_admin/admin2/', include(customadmin.site.urls)), (r'^test_admin/admin2/', include(customadmin.site.urls)),
(r'^test_admin/admin3/', include(admin.site.urls), dict(form_url='pony')), (r'^test_admin/admin3/', include(admin.site.urls), dict(form_url='pony')),
(r'^test_admin/admin4/', include(customadmin.simple_site.urls)),
) )