mirror of
				https://github.com/django/django.git
				synced 2025-11-04 05:35:37 +00:00 
			
		
		
		
	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
This commit is contained in:
		
							parent
							
								
									31f3a8c1ad
								
							
						
					
					
						commit
						a205691979
					
				
					 7 changed files with 75 additions and 11 deletions
				
			
		| 
						 | 
					@ -37,8 +37,11 @@ class AdminSite(object):
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    index_template = None
 | 
					    index_template = None
 | 
				
			||||||
    login_template = None
 | 
					 | 
				
			||||||
    app_index_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'):
 | 
					    def __init__(self, name=None, app_name='admin'):
 | 
				
			||||||
        self._registry = {} # model_class class -> admin_class instance
 | 
					        self._registry = {} # model_class class -> admin_class instance
 | 
				
			||||||
| 
						 | 
					@ -248,14 +251,22 @@ class AdminSite(object):
 | 
				
			||||||
            url = '%spassword_change/done/' % self.root_path
 | 
					            url = '%spassword_change/done/' % self.root_path
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            url = reverse('admin:password_change_done', current_app=self.name)
 | 
					            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):
 | 
					    def password_change_done(self, request):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        Displays the "success" page after a password change.
 | 
					        Displays the "success" page after a password change.
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        from django.contrib.auth.views import password_change_done
 | 
					        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):
 | 
					    def i18n_javascript(self, request):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
| 
						 | 
					@ -277,7 +288,10 @@ class AdminSite(object):
 | 
				
			||||||
        This should *not* assume the user is already logged in.
 | 
					        This should *not* assume the user is already logged in.
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        from django.contrib.auth.views import logout
 | 
					        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)
 | 
					    logout = never_cache(logout)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def login(self, request):
 | 
					    def login(self, request):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1343,9 +1343,10 @@ and 500 pages.
 | 
				
			||||||
Root and login templates
 | 
					Root and login templates
 | 
				
			||||||
------------------------
 | 
					------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
If you wish to change the index or login templates, you are better off creating
 | 
					If you wish to change the index, login or logout templates, you are better off
 | 
				
			||||||
your own ``AdminSite`` instance (see below), and changing the :attr:`AdminSite.index_template`
 | 
					creating your own ``AdminSite`` instance (see below), and changing the
 | 
				
			||||||
or :attr:`AdminSite.login_template` properties.
 | 
					:attr:`AdminSite.index_template` , :attr:`AdminSite.login_template` or
 | 
				
			||||||
 | 
					:attr:`AdminSite.logout_template` properties.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
``AdminSite`` objects
 | 
					``AdminSite`` objects
 | 
				
			||||||
=====================
 | 
					=====================
 | 
				
			||||||
| 
						 | 
					@ -1375,17 +1376,30 @@ provided, a default instance name of ``admin`` will be used.
 | 
				
			||||||
``AdminSite`` attributes
 | 
					``AdminSite`` attributes
 | 
				
			||||||
------------------------
 | 
					------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Templates can override or extend base admin templates as described in
 | 
				
			||||||
 | 
					`Overriding Admin Templates`_.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.. attribute:: AdminSite.index_template
 | 
					.. attribute:: AdminSite.index_template
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Path to a custom template that will be used by the admin site main index view.
 | 
					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
 | 
					.. attribute:: AdminSite.login_template
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Path to a custom template that will be used by the admin site login view.
 | 
					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
 | 
					Hooking ``AdminSite`` instances into your URLconf
 | 
				
			||||||
-------------------------------------------------
 | 
					-------------------------------------------------
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -9,7 +9,10 @@ import models
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Admin2(admin.AdminSite):
 | 
					class Admin2(admin.AdminSite):
 | 
				
			||||||
    login_template = 'custom_admin/login.html'
 | 
					    login_template = 'custom_admin/login.html'
 | 
				
			||||||
 | 
					    logout_template = 'custom_admin/logout.html'
 | 
				
			||||||
    index_template = 'custom_admin/index.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.
 | 
					    # A custom index view.
 | 
				
			||||||
    def index(self, request, extra_context=None):
 | 
					    def index(self, request, extra_context=None):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -286,11 +286,26 @@ class CustomModelAdminTest(AdminViewBasicTest):
 | 
				
			||||||
        self.assertTemplateUsed(request, 'custom_admin/login.html')
 | 
					        self.assertTemplateUsed(request, 'custom_admin/login.html')
 | 
				
			||||||
        self.assert_('Hello from a custom login template' in request.content)
 | 
					        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):
 | 
					    def testCustomAdminSiteIndexViewAndTemplate(self):
 | 
				
			||||||
        request = self.client.get('/test_admin/admin2/')
 | 
					        request = self.client.get('/test_admin/admin2/')
 | 
				
			||||||
        self.assertTemplateUsed(request, 'custom_admin/index.html')
 | 
					        self.assertTemplateUsed(request, 'custom_admin/index.html')
 | 
				
			||||||
        self.assert_('Hello from a custom index template *bar*' in request.content)
 | 
					        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):
 | 
					    def testCustomAdminSiteView(self):
 | 
				
			||||||
        self.client.login(username='super', password='secret')
 | 
					        self.client.login(username='super', password='secret')
 | 
				
			||||||
        response = self.client.get('/test_admin/%s/my_view/' % self.urlbit)
 | 
					        response = self.client.get('/test_admin/%s/my_view/' % self.urlbit)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										6
									
								
								tests/templates/custom_admin/logout.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								tests/templates/custom_admin/logout.html
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,6 @@
 | 
				
			||||||
 | 
					{% extends "registration/logged_out.html" %}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					{% block content %}
 | 
				
			||||||
 | 
					Hello from a custom logout template
 | 
				
			||||||
 | 
					{{ block.super }}
 | 
				
			||||||
 | 
					{% endblock %}
 | 
				
			||||||
							
								
								
									
										6
									
								
								tests/templates/custom_admin/password_change_done.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								tests/templates/custom_admin/password_change_done.html
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,6 @@
 | 
				
			||||||
 | 
					{% extends "registration/password_change_done.html" %}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					{% block content %}
 | 
				
			||||||
 | 
					Hello from a custom password change done template
 | 
				
			||||||
 | 
					{{ block.super }}
 | 
				
			||||||
 | 
					{% endblock %}
 | 
				
			||||||
							
								
								
									
										6
									
								
								tests/templates/custom_admin/password_change_form.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								tests/templates/custom_admin/password_change_form.html
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,6 @@
 | 
				
			||||||
 | 
					{% extends "registration/password_change_form.html" %}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					{% block content %}
 | 
				
			||||||
 | 
					Hello from a custom password change form template
 | 
				
			||||||
 | 
					{{ block.super }}
 | 
				
			||||||
 | 
					{% endblock %}
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue