Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
@jezdez jezdez authored
View
22 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 @@ def password_change(self, request):
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 @@ def logout(self, request):
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):
View
28 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
-------------------------------------------------
View
3  tests/regressiontests/admin_views/customadmin.py
@@ -9,7 +9,10 @@
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):
View
15 tests/regressiontests/admin_views/tests.py
@@ -286,11 +286,26 @@ def testCustomAdminSiteLoginTemplate(self):
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)
View
6 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 %}
View
6 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 %}
View
6 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 %}
Please sign in to comment.
Something went wrong with that request. Please try again.