diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py index d3ce7f181d..6989dcf55e 100644 --- a/django/contrib/admin/sites.py +++ b/django/contrib/admin/sites.py @@ -37,8 +37,11 @@ class AdminSite(object): """ index_template = None - login_template = None app_index_template = None + login_template = None + logout_template = None + password_change_template = None + password_change_done_template = None def __init__(self, name=None, app_name='admin'): self._registry = {} # model_class class -> admin_class instance @@ -248,14 +251,22 @@ class AdminSite(object): url = '%spassword_change/done/' % self.root_path else: url = reverse('admin:password_change_done', current_app=self.name) - return password_change(request, post_change_redirect=url) + defaults = { + 'post_change_redirect': url + } + if self.password_change_template is not None: + defaults['template_name'] = self.password_change_template + return password_change(request, **defaults) def password_change_done(self, request): """ Displays the "success" page after a password change. """ from django.contrib.auth.views import password_change_done - return password_change_done(request) + defaults = {} + if self.password_change_done_template is not None: + defaults['template_name'] = self.password_change_done_template + return password_change_done(request, **defaults) def i18n_javascript(self, request): """ @@ -277,7 +288,10 @@ class AdminSite(object): This should *not* assume the user is already logged in. """ from django.contrib.auth.views import logout - return logout(request) + defaults = {} + if self.logout_template is not None: + defaults['template_name'] = self.logout_template + return logout(request, **defaults) logout = never_cache(logout) def login(self, request): diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt index fce694d6ac..761c501b04 100644 --- a/docs/ref/contrib/admin/index.txt +++ b/docs/ref/contrib/admin/index.txt @@ -1343,9 +1343,10 @@ and 500 pages. Root and login templates ------------------------ -If you wish to change the index or login templates, you are better off creating -your own ``AdminSite`` instance (see below), and changing the :attr:`AdminSite.index_template` -or :attr:`AdminSite.login_template` properties. +If you wish to change the index, login or logout templates, you are better off +creating your own ``AdminSite`` instance (see below), and changing the +:attr:`AdminSite.index_template` , :attr:`AdminSite.login_template` or +:attr:`AdminSite.logout_template` properties. ``AdminSite`` objects ===================== @@ -1375,17 +1376,30 @@ provided, a default instance name of ``admin`` will be used. ``AdminSite`` attributes ------------------------ +Templates can override or extend base admin templates as described in +`Overriding Admin Templates`_. + .. attribute:: AdminSite.index_template Path to a custom template that will be used by the admin site main index view. -Templates can override or extend base admin templates as described in -`Overriding Admin Templates`_. .. attribute:: AdminSite.login_template Path to a custom template that will be used by the admin site login view. -Templates can override or extend base admin templates as described in -`Overriding Admin Templates`_. + +.. attribute:: AdminSite.logout_template + +Path to a custom template that will be used by the admin site logout view. + +.. attribute:: AdminSite.password_change_template + +Path to a custom template that will be used by the admin site password change +view. + +.. attribute:: AdminSite.password_change_done_template + +Path to a custom template that will be used by the admin site password change +done view. Hooking ``AdminSite`` instances into your URLconf ------------------------------------------------- diff --git a/tests/regressiontests/admin_views/customadmin.py b/tests/regressiontests/admin_views/customadmin.py index 80570ea51d..34e39ef0ca 100644 --- a/tests/regressiontests/admin_views/customadmin.py +++ b/tests/regressiontests/admin_views/customadmin.py @@ -9,7 +9,10 @@ import models class Admin2(admin.AdminSite): login_template = 'custom_admin/login.html' + logout_template = 'custom_admin/logout.html' index_template = 'custom_admin/index.html' + password_change_template = 'custom_admin/password_change_form.html' + password_change_done_template = 'custom_admin/password_change_done.html' # A custom index view. def index(self, request, extra_context=None): diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py index 4d6e1d5139..7a20aaacd5 100644 --- a/tests/regressiontests/admin_views/tests.py +++ b/tests/regressiontests/admin_views/tests.py @@ -286,11 +286,26 @@ class CustomModelAdminTest(AdminViewBasicTest): self.assertTemplateUsed(request, 'custom_admin/login.html') self.assert_('Hello from a custom login template' in request.content) + def testCustomAdminSiteLogoutTemplate(self): + request = self.client.get('/test_admin/admin2/logout/') + self.assertTemplateUsed(request, 'custom_admin/logout.html') + self.assert_('Hello from a custom logout template' in request.content) + def testCustomAdminSiteIndexViewAndTemplate(self): request = self.client.get('/test_admin/admin2/') self.assertTemplateUsed(request, 'custom_admin/index.html') self.assert_('Hello from a custom index template *bar*' in request.content) + def testCustomAdminSitePasswordChangeTemplate(self): + request = self.client.get('/test_admin/admin2/password_change/') + self.assertTemplateUsed(request, 'custom_admin/password_change_form.html') + self.assert_('Hello from a custom password change form template' in request.content) + + def testCustomAdminSitePasswordChangeDoneTemplate(self): + request = self.client.get('/test_admin/admin2/password_change/done/') + self.assertTemplateUsed(request, 'custom_admin/password_change_done.html') + self.assert_('Hello from a custom password change done template' in request.content) + def testCustomAdminSiteView(self): self.client.login(username='super', password='secret') response = self.client.get('/test_admin/%s/my_view/' % self.urlbit) diff --git a/tests/templates/custom_admin/logout.html b/tests/templates/custom_admin/logout.html new file mode 100644 index 0000000000..3a9301b6c6 --- /dev/null +++ b/tests/templates/custom_admin/logout.html @@ -0,0 +1,6 @@ +{% extends "registration/logged_out.html" %} + +{% block content %} +Hello from a custom logout template +{{ block.super }} +{% endblock %} diff --git a/tests/templates/custom_admin/password_change_done.html b/tests/templates/custom_admin/password_change_done.html new file mode 100644 index 0000000000..0e4a7f25ec --- /dev/null +++ b/tests/templates/custom_admin/password_change_done.html @@ -0,0 +1,6 @@ +{% extends "registration/password_change_done.html" %} + +{% block content %} +Hello from a custom password change done template +{{ block.super }} +{% endblock %} diff --git a/tests/templates/custom_admin/password_change_form.html b/tests/templates/custom_admin/password_change_form.html new file mode 100644 index 0000000000..1c424934e4 --- /dev/null +++ b/tests/templates/custom_admin/password_change_form.html @@ -0,0 +1,6 @@ +{% extends "registration/password_change_form.html" %} + +{% block content %} +Hello from a custom password change form template +{{ block.super }} +{% endblock %}