Fixed #13629 -- Added CSS classes to the `<body>` tag of some admin templates to allow style customizations per app or per model.

This commit is contained in:
Thomas Sorrel 2013-07-21 11:02:36 +02:00 committed by Julien Phalip
parent 11b7b9ad00
commit bb145e2c47
9 changed files with 67 additions and 2 deletions

View File

@ -544,6 +544,7 @@ answer newbie questions, and generally made Django that much better:
George Song <george@damacy.net> George Song <george@damacy.net>
sopel sopel
Leo Soto <leo.soto@gmail.com> Leo Soto <leo.soto@gmail.com>
Thomas Sorrel
Wiliam Alves de Souza <wiliamsouza83@gmail.com> Wiliam Alves de Souza <wiliamsouza83@gmail.com>
Don Spaulding <donspauldingii@gmail.com> Don Spaulding <donspauldingii@gmail.com>
Calvin Spealman <ironfroggy@gmail.com> Calvin Spealman <ironfroggy@gmail.com>

View File

@ -439,6 +439,7 @@ class AdminSite(object):
context = { context = {
'title': _('%s administration') % capfirst(app_label), 'title': _('%s administration') % capfirst(app_label),
'app_list': [app_dict], 'app_list': [app_dict],
'app_label': app_label,
} }
context.update(extra_context or {}) context.update(extra_context or {})

View File

@ -1,6 +1,8 @@
{% extends "admin/index.html" %} {% extends "admin/index.html" %}
{% load i18n %} {% load i18n %}
{% block bodyclass %}app-{{ app_label }} {{ block.super }}{% endblock %}
{% if not is_popup %} {% if not is_popup %}
{% block breadcrumbs %} {% block breadcrumbs %}
<div class="breadcrumbs"> <div class="breadcrumbs">

View File

@ -10,7 +10,7 @@
{% block coltype %}colM{% endblock %} {% 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 %} {% if not is_popup %}
{% block breadcrumbs %} {% block breadcrumbs %}

View File

@ -32,7 +32,7 @@
{% endif %}{% endif %} {% endif %}{% endif %}
{% endblock %} {% endblock %}
{% block bodyclass %}change-list{% endblock %} {% block bodyclass %}app-{{ opts.app_label }} model-{{ opts.object_name.lower }} change-list{% endblock %}
{% if not is_popup %} {% if not is_popup %}
{% block breadcrumbs %} {% block breadcrumbs %}

View File

@ -1,6 +1,8 @@
{% extends "admin/base_site.html" %} {% extends "admin/base_site.html" %}
{% load i18n admin_urls %} {% load i18n admin_urls %}
{% block bodyclass %}app-{{ opts.app_label }} model-{{ opts.object_name.lower }} delete-confirmation{% endblock %}
{% block breadcrumbs %} {% block breadcrumbs %}
<div class="breadcrumbs"> <div class="breadcrumbs">
<a href="{% url 'admin:index' %}">{% trans 'Home' %}</a> <a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>

View File

@ -1,6 +1,8 @@
{% extends "admin/base_site.html" %} {% extends "admin/base_site.html" %}
{% load i18n l10n admin_urls %} {% load i18n l10n admin_urls %}
{% block bodyclass %}app-{{ opts.app_label }} model-{{ opts.object_name.lower }} delete-confirmation delete-selected-confirmation{% endblock %}
{% block breadcrumbs %} {% block breadcrumbs %}
<div class="breadcrumbs"> <div class="breadcrumbs">
<a href="{% url 'admin:index' %}">{% trans 'Home' %}</a> <a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>

View File

@ -199,6 +199,10 @@ Minor features
* The admin list columns have a ``column-<field_name>`` class in the HTML * 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. 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 * The :ref:`isolation level<database-isolation-level>` can be customized under
PostgreSQL. PostgreSQL.

View File

@ -3824,6 +3824,59 @@ class CSSTest(TestCase):
self.assertContains(response, '<tr class="model-actor">') self.assertContains(response, '<tr class="model-actor">')
self.assertContains(response, '<tr class="model-album">') 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: try:
import docutils import docutils
except ImportError: except ImportError: