Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #18697 -- Made values accepted for two customizable admin templ…

…ates consistent.

Thanks and at cloverfastfood dot com for the report.
  • Loading branch information...
commit b64d30405a3d5468dc8c6232747d45bbeee4f7bb 1 parent 88e1715
Ramiro Morales authored
6  django/contrib/admin/sites.py
@@ -391,9 +391,9 @@ def index(self, request, extra_context=None):
391 391
             'app_list': app_list,
392 392
         }
393 393
         context.update(extra_context or {})
394  
-        return TemplateResponse(request, [
395  
-            self.index_template or 'admin/index.html',
396  
-        ], context, current_app=self.name)
  394
+        return TemplateResponse(request, self.index_template or
  395
+                                'admin/index.html', context,
  396
+                                current_app=self.name)
397 397
 
398 398
     def app_index(self, request, app_label, extra_context=None):
399 399
         user = request.user
6  django/contrib/auth/admin.py
@@ -148,10 +148,10 @@ def user_change_password(self, request, id, form_url=''):
148 148
             'save_as': False,
149 149
             'show_save': True,
150 150
         }
151  
-        return TemplateResponse(request, [
  151
+        return TemplateResponse(request,
152 152
             self.change_user_password_template or
153  
-            'admin/auth/user/change_password.html'
154  
-        ], context, current_app=self.admin_site.name)
  153
+            'admin/auth/user/change_password.html',
  154
+            context, current_app=self.admin_site.name)
155 155
 
156 156
     def response_add(self, request, obj, **kwargs):
157 157
         """
9  tests/regressiontests/admin_views/customadmin.py
@@ -16,7 +16,7 @@ class Admin2(admin.AdminSite):
16 16
     login_form = forms.CustomAdminAuthenticationForm
17 17
     login_template = 'custom_admin/login.html'
18 18
     logout_template = 'custom_admin/logout.html'
19  
-    index_template = 'custom_admin/index.html'
  19
+    index_template = ['custom_admin/index.html'] # a list, to test fix for #18697
20 20
     password_change_template = 'custom_admin/password_change_form.html'
21 21
     password_change_done_template = 'custom_admin/password_change_done.html'
22 22
 
@@ -40,6 +40,10 @@ def queryset(self, request):
40 40
         return qs.filter(is_superuser=False)
41 41
 
42 42
 
  43
+class CustomPwdTemplateUserAdmin(UserAdmin):
  44
+    change_user_password_template = ['admin/auth/user/change_password.html'] # a list, to test fix for #18697
  45
+
  46
+
43 47
 site = Admin2(name="admin2")
44 48
 
45 49
 site.register(models.Article, base_admin.ArticleAdmin)
@@ -50,3 +54,6 @@ def queryset(self, request):
50 54
 site.register(User, UserLimitedAdmin)
51 55
 site.register(models.UndeletableObject, base_admin.UndeletableObjectAdmin)
52 56
 site.register(models.Simple, base_admin.AttributeErrorRaisingAdmin)
  57
+
  58
+simple_site = Admin2(name='admin4')
  59
+simple_site.register(User, CustomPwdTemplateUserAdmin)
14  tests/regressiontests/admin_views/tests.py
@@ -770,7 +770,10 @@ def testCustomAdminSiteLogoutTemplate(self):
770 770
         self.assertContains(response, 'Hello from a custom logout template')
771 771
 
772 772
     def testCustomAdminSiteIndexViewAndTemplate(self):
773  
-        response = self.client.get('/test_admin/admin2/')
  773
+        try:
  774
+            response = self.client.get('/test_admin/admin2/')
  775
+        except TypeError:
  776
+            self.fail('AdminSite.index_template should accept a list of template paths')
774 777
         self.assertIsInstance(response, TemplateResponse)
775 778
         self.assertTemplateUsed(response, 'custom_admin/index.html')
776 779
         self.assertContains(response, 'Hello from a custom index template *bar*')
@@ -792,6 +795,15 @@ def testCustomAdminSiteView(self):
792 795
         response = self.client.get('/test_admin/%s/my_view/' % self.urlbit)
793 796
         self.assertEqual(response.content, b"Django is a magical pony!")
794 797
 
  798
+    def test_pwd_change_custom_template(self):
  799
+        self.client.login(username='super', password='secret')
  800
+        su = User.objects.get(username='super')
  801
+        try:
  802
+            response = self.client.get('/test_admin/admin4/auth/user/%s/password/' % su.pk)
  803
+        except TypeError:
  804
+            self.fail('ModelAdmin.change_user_password_template should accept a list of template paths')
  805
+        self.assertEqual(response.status_code, 200)
  806
+
795 807
 
796 808
 def get_perm(Model, perm):
797 809
     """Return the permission object, for the Model"""
1  tests/regressiontests/admin_views/urls.py
@@ -11,4 +11,5 @@
11 11
     (r'^test_admin/admin/', include(admin.site.urls)),
12 12
     (r'^test_admin/admin2/', include(customadmin.site.urls)),
13 13
     (r'^test_admin/admin3/', include(admin.site.urls), dict(form_url='pony')),
  14
+    (r'^test_admin/admin4/', include(customadmin.simple_site.urls)),
14 15
 )

0 notes on commit b64d304

Please sign in to comment.
Something went wrong with that request. Please try again.