Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #21371 -- Added the block.super to admin bodyclass blocks.

Thanks Keryn Knight for the report.
  • Loading branch information...
commit f5123c7291e855713b59e739bad0e50a1d50d3ef 1 parent 59d9b26
julien 'pouete' Godin authored timgraham committed
2  django/contrib/admin/templates/admin/app_index.html
View
@@ -1,7 +1,7 @@
{% extends "admin/index.html" %}
{% load i18n %}
-{% block bodyclass %}app-{{ app_label }} {{ block.super }}{% endblock %}
+{% block bodyclass %}{{ block.super }} app-{{ app_label }}{% endblock %}
{% if not is_popup %}
{% block breadcrumbs %}
2  django/contrib/admin/templates/admin/auth/user/change_password.html
View
@@ -6,7 +6,7 @@
<script type="text/javascript" src="{% url 'admin:jsi18n' %}"></script>
{% endblock %}
{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/forms.css" %}" />{% endblock %}
-{% block bodyclass %}{{ opts.app_label }}-{{ opts.model_name }} change-form{% endblock %}
+{% block bodyclass %}{{ block.super }} {{ opts.app_label }}-{{ opts.model_name }} change-form{% endblock %}
{% if not is_popup %}
{% block breadcrumbs %}
<div class="breadcrumbs">
2  django/contrib/admin/templates/admin/change_form.html
View
@@ -10,7 +10,7 @@
{% block coltype %}colM{% endblock %}
-{% block bodyclass %}app-{{ opts.app_label }} model-{{ opts.model_name }} change-form{% endblock %}
+{% block bodyclass %}{{ block.super }} app-{{ opts.app_label }} model-{{ opts.model_name }} change-form{% endblock %}
{% if not is_popup %}
{% block breadcrumbs %}
2  django/contrib/admin/templates/admin/change_list.html
View
@@ -32,7 +32,7 @@
{% endif %}{% endif %}
{% endblock %}
-{% block bodyclass %}app-{{ opts.app_label }} model-{{ opts.model_name }} change-list{% endblock %}
+{% block bodyclass %}{{ block.super }} app-{{ opts.app_label }} model-{{ opts.model_name }} change-list{% endblock %}
{% if not is_popup %}
{% block breadcrumbs %}
2  django/contrib/admin/templates/admin/delete_confirmation.html
View
@@ -1,7 +1,7 @@
{% extends "admin/base_site.html" %}
{% load i18n admin_urls %}
-{% block bodyclass %}app-{{ opts.app_label }} model-{{ opts.model_name }} delete-confirmation{% endblock %}
+{% block bodyclass %}{{ block.super }} app-{{ opts.app_label }} model-{{ opts.model_name }} delete-confirmation{% endblock %}
{% block breadcrumbs %}
<div class="breadcrumbs">
2  django/contrib/admin/templates/admin/delete_selected_confirmation.html
View
@@ -1,7 +1,7 @@
{% extends "admin/base_site.html" %}
{% load i18n l10n admin_urls %}
-{% block bodyclass %}app-{{ opts.app_label }} model-{{ opts.model_name }} delete-confirmation delete-selected-confirmation{% endblock %}
+{% block bodyclass %}{{ block.super }} app-{{ opts.app_label }} model-{{ opts.model_name }} delete-confirmation delete-selected-confirmation{% endblock %}
{% block breadcrumbs %}
<div class="breadcrumbs">
2  django/contrib/admin/templates/admin/index.html
View
@@ -5,7 +5,7 @@
{% block coltype %}colMS{% endblock %}
-{% block bodyclass %}dashboard{% endblock %}
+{% block bodyclass %}{{ block.super }} dashboard{% endblock %}
{% block breadcrumbs %}{% endblock %}
2  django/contrib/admin/templates/admin/login.html
View
@@ -3,7 +3,7 @@
{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/login.css" %}" />{% endblock %}
-{% block bodyclass %}login{% endblock %}
+{% block bodyclass %}{{ block.super }} login{% endblock %}
{% block nav-global %}{% endblock %}
3  tests/admin_views/templates/admin/base_site.html
View
@@ -0,0 +1,3 @@
+{% extends "admin/base.html" %}
+
+{% block bodyclass%}bodyclass_consistency_check{% endblock %}
99 tests/admin_views/tests.py
View
@@ -58,6 +58,7 @@
ERROR_MESSAGE = "Please enter the correct username and password \
for a staff account. Note that both fields may be case-sensitive."
+ADMIN_VIEW_TEMPLATES_DIR = settings.TEMPLATE_DIRS + (os.path.join(os.path.dirname(upath(__file__)), 'templates'),)
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',),
@@ -648,6 +649,83 @@ def test_invalid_appindex_url(self):
reverse('admin:app_list', args=('admin_views2',))
+@override_settings(TEMPLATE_DIRS=ADMIN_VIEW_TEMPLATES_DIR)
+class AdminCustomTemplateTests(AdminViewBasicTestCase):
+ def test_extended_bodyclass_template_change_form(self):
+ """
+ Ensure that the admin/change_form.html template uses block.super in the
+ bodyclass block.
+ """
+ response = self.client.get('/test_admin/%s/admin_views/section/add/' % self.urlbit)
+ self.assertContains(response, 'bodyclass_consistency_check ')
+
+ def test_extended_bodyclass_template_change_password(self):
+ """
+ Ensure that the auth/user/change_password.html template uses block
+ super in the bodyclass block.
+ """
+ user = User.objects.get(username='super')
+ response = self.client.get('/test_admin/%s/auth/user/%s/password/' % (self.urlbit, user.id))
+ self.assertContains(response, 'bodyclass_consistency_check ')
+
+ def test_extended_bodyclass_template_index(self):
+ """
+ Ensure that the admin/index.html template uses block.super in the
+ bodyclass block.
+ """
+ response = self.client.get('/test_admin/%s/' % self.urlbit)
+ self.assertContains(response, 'bodyclass_consistency_check ')
+
+ def test_extended_bodyclass_change_list(self):
+ """
+ Ensure that the admin/change_list.html' template uses block.super
+ in the bodyclass block.
+ """
+ response = self.client.get('/test_admin/%s/admin_views/article/' % self.urlbit)
+ self.assertContains(response, 'bodyclass_consistency_check ')
+
+ def test_extended_bodyclass_template_login(self):
+ """
+ Ensure that the admin/login.html template uses block.super in the
+ bodyclass block.
+ """
+ self.client.logout()
+ response = self.client.get('/test_admin/%s/login/' % self.urlbit)
+ self.assertContains(response, 'bodyclass_consistency_check ')
+
+ def test_extended_bodyclass_template_delete_confirmation(self):
+ """
+ Ensure that the admin/delete_confirmation.html template uses
+ block.super in the bodyclass block.
+ """
+ group = Group.objects.create(name="foogroup")
+ response = self.client.get('/test_admin/%s/auth/group/%s/delete/' % (self.urlbit, group.id))
+ self.assertContains(response, 'bodyclass_consistency_check ')
+
+ def test_extended_bodyclass_template_delete_selected_confirmation(self):
+ """
+ Ensure that the admin/delete_selected_confirmation.html template uses
+ block.super in bodyclass block.
+ """
+ group = Group.objects.create(name="foogroup")
+ post_data = {
+ 'action': 'delete_selected',
+ 'selected_accross': '0',
+ 'index': '0',
+ '_selected_action': group.id
+ }
+ response = self.client.post('/test_admin/%s/auth/group/' % (self.urlbit), post_data)
+ self.assertContains(response, 'bodyclass_consistency_check ')
+
+ def test_filter_with_custom_template(self):
+ """
+ Ensure that one can use a custom template to render an admin filter.
+ Refs #17515.
+ """
+ response = self.client.get("/test_admin/admin/admin_views/color2/")
+ self.assertTemplateUsed(response, 'custom_filter_template.html')
+
+
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class AdminViewFormUrlTest(TestCase):
urls = "admin_views.urls"
@@ -668,17 +746,6 @@ def testChangeFormUrlHasCorrectValue(self):
self.assertTrue('form_url' in response.context, msg='form_url not present in response.context')
self.assertEqual(response.context['form_url'], 'pony')
- def test_filter_with_custom_template(self):
- """
- Ensure that one can use a custom template to render an admin filter.
- Refs #17515.
- """
- template_dirs = settings.TEMPLATE_DIRS + (
- os.path.join(os.path.dirname(upath(__file__)), 'templates'),)
- with self.settings(TEMPLATE_DIRS=template_dirs):
- response = self.client.get("/test_admin/admin/admin_views/color2/")
- self.assertTemplateUsed(response, 'custom_filter_template.html')
-
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class AdminJavaScriptTest(TestCase):
@@ -3874,7 +3941,7 @@ def testAppModelInFormBodyClass(self):
response = self.client.get('/test_admin/admin/admin_views/section/add/')
self.assertEqual(response.status_code, 200)
self.assertContains(response,
- '<body class="app-admin_views model-section ')
+ '<body class=" app-admin_views model-section ')
def testAppModelInListBodyClass(self):
"""
@@ -3883,7 +3950,7 @@ def testAppModelInListBodyClass(self):
response = self.client.get('/test_admin/admin/admin_views/section/')
self.assertEqual(response.status_code, 200)
self.assertContains(response,
- '<body class="app-admin_views model-section ')
+ '<body class=" app-admin_views model-section ')
def testAppModelInDeleteConfirmationBodyClass(self):
"""
@@ -3894,7 +3961,7 @@ def testAppModelInDeleteConfirmationBodyClass(self):
'/test_admin/admin/admin_views/section/1/delete/')
self.assertEqual(response.status_code, 200)
self.assertContains(response,
- '<body class="app-admin_views model-section ')
+ '<body class=" app-admin_views model-section ')
def testAppModelInAppIndexBodyClass(self):
"""
@@ -3902,7 +3969,7 @@ def testAppModelInAppIndexBodyClass(self):
"""
response = self.client.get('/test_admin/admin/admin_views/')
self.assertEqual(response.status_code, 200)
- self.assertContains(response, '<body class="app-admin_views ')
+ self.assertContains(response, '<body class=" dashboard app-admin_views')
def testAppModelInDeleteSelectedConfirmationBodyClass(self):
"""
@@ -3918,7 +3985,7 @@ def testAppModelInDeleteSelectedConfirmationBodyClass(self):
action_data)
self.assertEqual(response.status_code, 200)
self.assertContains(response,
- '<body class="app-admin_views model-section ')
+ '<body class=" app-admin_views model-section ')
def test_changelist_field_classes(self):
"""
Please sign in to comment.
Something went wrong with that request. Please try again.