Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #13629 -- Added CSS classes to the `<body>` tag of some admin t…

…emplates to allow style customizations per app or per model.
  • Loading branch information...
commit bb145e2c47d71b7f68280c00ced727442d2effa2 1 parent 11b7b9a
@tcsorrel tcsorrel authored jphalip committed
View
1  AUTHORS
@@ -544,6 +544,7 @@ answer newbie questions, and generally made Django that much better:
George Song <george@damacy.net>
sopel
Leo Soto <leo.soto@gmail.com>
+ Thomas Sorrel
Wiliam Alves de Souza <wiliamsouza83@gmail.com>
Don Spaulding <donspauldingii@gmail.com>
Calvin Spealman <ironfroggy@gmail.com>
View
1  django/contrib/admin/sites.py
@@ -439,6 +439,7 @@ def app_index(self, request, app_label, extra_context=None):
context = {
'title': _('%s administration') % capfirst(app_label),
'app_list': [app_dict],
+ 'app_label': app_label,
}
context.update(extra_context or {})
View
2  django/contrib/admin/templates/admin/app_index.html
@@ -1,6 +1,8 @@
{% extends "admin/index.html" %}
{% load i18n %}
+{% block bodyclass %}app-{{ app_label }} {{ block.super }}{% endblock %}
+
{% if not is_popup %}
{% block breadcrumbs %}
<div class="breadcrumbs">
View
2  django/contrib/admin/templates/admin/change_form.html
@@ -10,7 +10,7 @@
{% block coltype %}colM{% endblock %}
-{% block bodyclass %}{{ opts.app_label }}-{{ opts.object_name.lower }} change-form{% endblock %}
+{% block bodyclass %}app-{{ opts.app_label }} model-{{ opts.object_name.lower }} change-form{% endblock %}
{% if not is_popup %}
{% block breadcrumbs %}
View
2  django/contrib/admin/templates/admin/change_list.html
@@ -32,7 +32,7 @@
{% endif %}{% endif %}
{% endblock %}
-{% block bodyclass %}change-list{% endblock %}
+{% block bodyclass %}app-{{ opts.app_label }} model-{{ opts.object_name.lower }} change-list{% endblock %}
{% if not is_popup %}
{% block breadcrumbs %}
View
2  django/contrib/admin/templates/admin/delete_confirmation.html
@@ -1,6 +1,8 @@
{% extends "admin/base_site.html" %}
{% load i18n admin_urls %}
+{% block bodyclass %}app-{{ opts.app_label }} model-{{ opts.object_name.lower }} delete-confirmation{% endblock %}
+
{% block breadcrumbs %}
<div class="breadcrumbs">
<a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
View
2  django/contrib/admin/templates/admin/delete_selected_confirmation.html
@@ -1,6 +1,8 @@
{% extends "admin/base_site.html" %}
{% load i18n l10n admin_urls %}
+{% block bodyclass %}app-{{ opts.app_label }} model-{{ opts.object_name.lower }} delete-confirmation delete-selected-confirmation{% endblock %}
+
{% block breadcrumbs %}
<div class="breadcrumbs">
<a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
View
4 docs/releases/1.6.txt
@@ -199,6 +199,10 @@ Minor features
* The admin list columns have a ``column-<field_name>`` class in the HTML
so the columns header can be styled with CSS, e.g. to set a column width.
+* Some admin templates now have ``app-<app_name>`` and ``model-<model_name>``
+ classes in their ``<body>`` tag to allow customizing the CSS per app or per
+ model.
+
* The :ref:`isolation level<database-isolation-level>` can be customized under
PostgreSQL.
View
53 tests/admin_views/tests.py
@@ -3824,6 +3824,59 @@ def test_index_css_classes(self):
self.assertContains(response, '<tr class="model-actor">')
self.assertContains(response, '<tr class="model-album">')
+ def testAppModelInFormBodyClass(self):
+ """
+ Ensure app and model tag are correcly read by change_form template
+ """
+ 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 ')
+
+ def testAppModelInListBodyClass(self):
+ """
+ Ensure app and model tag are correcly read by change_list template
+ """
+ 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 ')
+
+ def testAppModelInDeleteConfirmationBodyClass(self):
+ """
+ Ensure app and model tag are correcly read by delete_confirmation
+ template
+ """
+ response = self.client.get(
+ '/test_admin/admin/admin_views/section/1/delete/')
+ self.assertEqual(response.status_code, 200)
+ self.assertContains(response,
+ '<body class="app-admin_views model-section ')
+
+ def testAppModelInAppIndexBodyClass(self):
+ """
+ Ensure app and model tag are correcly read by app_index template
+ """
+ response = self.client.get('/test_admin/admin/admin_views/')
+ self.assertEqual(response.status_code, 200)
+ self.assertContains(response, '<body class="app-admin_views ')
+
+ def testAppModelInDeleteSelectedConfirmationBodyClass(self):
+ """
+ Ensure app and model tag are correcly read by
+ delete_selected_confirmation template
+ """
+ action_data = {
+ ACTION_CHECKBOX_NAME: [1],
+ 'action': 'delete_selected',
+ 'index': 0,
+ }
+ response = self.client.post('/test_admin/admin/admin_views/section/',
+ action_data)
+ self.assertEqual(response.status_code, 200)
+ self.assertContains(response,
+ '<body class="app-admin_views model-section ')
+
try:
import docutils
except ImportError:
Please sign in to comment.
Something went wrong with that request. Please try again.