Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #8933 - Allow more admin templates to be overridden.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12217 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit a2056919799e48f053fa16b65569fc1e8f57ebe1 1 parent 31f3a8c
Jannis Leidel authored
22  django/contrib/admin/sites.py
@@ -37,8 +37,11 @@ class AdminSite(object):
37 37
     """
38 38
 
39 39
     index_template = None
40  
-    login_template = None
41 40
     app_index_template = None
  41
+    login_template = None
  42
+    logout_template = None
  43
+    password_change_template = None
  44
+    password_change_done_template = None
42 45
 
43 46
     def __init__(self, name=None, app_name='admin'):
44 47
         self._registry = {} # model_class class -> admin_class instance
@@ -248,14 +251,22 @@ def password_change(self, request):
248 251
             url = '%spassword_change/done/' % self.root_path
249 252
         else:
250 253
             url = reverse('admin:password_change_done', current_app=self.name)
251  
-        return password_change(request, post_change_redirect=url)
  254
+        defaults = {
  255
+            'post_change_redirect': url
  256
+        }
  257
+        if self.password_change_template is not None:
  258
+            defaults['template_name'] = self.password_change_template
  259
+        return password_change(request, **defaults)
252 260
 
253 261
     def password_change_done(self, request):
254 262
         """
255 263
         Displays the "success" page after a password change.
256 264
         """
257 265
         from django.contrib.auth.views import password_change_done
258  
-        return password_change_done(request)
  266
+        defaults = {}
  267
+        if self.password_change_done_template is not None:
  268
+            defaults['template_name'] = self.password_change_done_template
  269
+        return password_change_done(request, **defaults)
259 270
 
260 271
     def i18n_javascript(self, request):
261 272
         """
@@ -277,7 +288,10 @@ def logout(self, request):
277 288
         This should *not* assume the user is already logged in.
278 289
         """
279 290
         from django.contrib.auth.views import logout
280  
-        return logout(request)
  291
+        defaults = {}
  292
+        if self.logout_template is not None:
  293
+            defaults['template_name'] = self.logout_template
  294
+        return logout(request, **defaults)
281 295
     logout = never_cache(logout)
282 296
 
283 297
     def login(self, request):
28  docs/ref/contrib/admin/index.txt
@@ -1343,9 +1343,10 @@ and 500 pages.
1343 1343
 Root and login templates
1344 1344
 ------------------------
1345 1345
 
1346  
-If you wish to change the index or login templates, you are better off creating
1347  
-your own ``AdminSite`` instance (see below), and changing the :attr:`AdminSite.index_template`
1348  
-or :attr:`AdminSite.login_template` properties.
  1346
+If you wish to change the index, login or logout templates, you are better off
  1347
+creating your own ``AdminSite`` instance (see below), and changing the
  1348
+:attr:`AdminSite.index_template` , :attr:`AdminSite.login_template` or
  1349
+:attr:`AdminSite.logout_template` properties.
1349 1350
 
1350 1351
 ``AdminSite`` objects
1351 1352
 =====================
@@ -1375,17 +1376,30 @@ provided, a default instance name of ``admin`` will be used.
1375 1376
 ``AdminSite`` attributes
1376 1377
 ------------------------
1377 1378
 
  1379
+Templates can override or extend base admin templates as described in
  1380
+`Overriding Admin Templates`_.
  1381
+
1378 1382
 .. attribute:: AdminSite.index_template
1379 1383
 
1380 1384
 Path to a custom template that will be used by the admin site main index view.
1381  
-Templates can override or extend base admin templates as described in
1382  
-`Overriding Admin Templates`_.
1383 1385
 
1384 1386
 .. attribute:: AdminSite.login_template
1385 1387
 
1386 1388
 Path to a custom template that will be used by the admin site login view.
1387  
-Templates can override or extend base admin templates as described in
1388  
-`Overriding Admin Templates`_.
  1389
+
  1390
+.. attribute:: AdminSite.logout_template
  1391
+
  1392
+Path to a custom template that will be used by the admin site logout view.
  1393
+
  1394
+.. attribute:: AdminSite.password_change_template
  1395
+
  1396
+Path to a custom template that will be used by the admin site password change
  1397
+view.
  1398
+
  1399
+.. attribute:: AdminSite.password_change_done_template
  1400
+
  1401
+Path to a custom template that will be used by the admin site password change
  1402
+done view.
1389 1403
 
1390 1404
 Hooking ``AdminSite`` instances into your URLconf
1391 1405
 -------------------------------------------------
3  tests/regressiontests/admin_views/customadmin.py
@@ -9,7 +9,10 @@
9 9
 
10 10
 class Admin2(admin.AdminSite):
11 11
     login_template = 'custom_admin/login.html'
  12
+    logout_template = 'custom_admin/logout.html'
12 13
     index_template = 'custom_admin/index.html'
  14
+    password_change_template = 'custom_admin/password_change_form.html'
  15
+    password_change_done_template = 'custom_admin/password_change_done.html'
13 16
 
14 17
     # A custom index view.
15 18
     def index(self, request, extra_context=None):
15  tests/regressiontests/admin_views/tests.py
@@ -286,11 +286,26 @@ def testCustomAdminSiteLoginTemplate(self):
286 286
         self.assertTemplateUsed(request, 'custom_admin/login.html')
287 287
         self.assert_('Hello from a custom login template' in request.content)
288 288
 
  289
+    def testCustomAdminSiteLogoutTemplate(self):
  290
+        request = self.client.get('/test_admin/admin2/logout/')
  291
+        self.assertTemplateUsed(request, 'custom_admin/logout.html')
  292
+        self.assert_('Hello from a custom logout template' in request.content)
  293
+
289 294
     def testCustomAdminSiteIndexViewAndTemplate(self):
290 295
         request = self.client.get('/test_admin/admin2/')
291 296
         self.assertTemplateUsed(request, 'custom_admin/index.html')
292 297
         self.assert_('Hello from a custom index template *bar*' in request.content)
293 298
 
  299
+    def testCustomAdminSitePasswordChangeTemplate(self):
  300
+        request = self.client.get('/test_admin/admin2/password_change/')
  301
+        self.assertTemplateUsed(request, 'custom_admin/password_change_form.html')
  302
+        self.assert_('Hello from a custom password change form template' in request.content)
  303
+
  304
+    def testCustomAdminSitePasswordChangeDoneTemplate(self):
  305
+        request = self.client.get('/test_admin/admin2/password_change/done/')
  306
+        self.assertTemplateUsed(request, 'custom_admin/password_change_done.html')
  307
+        self.assert_('Hello from a custom password change done template' in request.content)
  308
+
294 309
     def testCustomAdminSiteView(self):
295 310
         self.client.login(username='super', password='secret')
296 311
         response = self.client.get('/test_admin/%s/my_view/' % self.urlbit)
6  tests/templates/custom_admin/logout.html
... ...
@@ -0,0 +1,6 @@
  1
+{% extends "registration/logged_out.html" %}
  2
+
  3
+{% block content %}
  4
+Hello from a custom logout template
  5
+{{ block.super }}
  6
+{% endblock %}
6  tests/templates/custom_admin/password_change_done.html
... ...
@@ -0,0 +1,6 @@
  1
+{% extends "registration/password_change_done.html" %}
  2
+
  3
+{% block content %}
  4
+Hello from a custom password change done template
  5
+{{ block.super }}
  6
+{% endblock %}
6  tests/templates/custom_admin/password_change_form.html
... ...
@@ -0,0 +1,6 @@
  1
+{% extends "registration/password_change_form.html" %}
  2
+
  3
+{% block content %}
  4
+Hello from a custom password change form template
  5
+{{ block.super }}
  6
+{% endblock %}

0 notes on commit a205691

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