Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #17050 -- Added some CSS class names to the admin index pages t…

…o facilitate per-app or per-model style customizations. Thanks to scytale for the report and to H0ff1 and thiderman for their work on the patch.
  • Loading branch information...
commit 2e2c4968f6b9b57354af7229687d179941ed74c5 1 parent 90d3af3
@jphalip jphalip authored
View
4 django/contrib/admin/sites.py
@@ -354,6 +354,7 @@ def index(self, request, extra_context=None):
info = (app_label, model._meta.module_name)
model_dict = {
'name': capfirst(model._meta.verbose_name_plural),
+ 'object_name': model._meta.object_name,
'perms': perms,
}
if perms.get('change', False):
@@ -371,6 +372,7 @@ def index(self, request, extra_context=None):
else:
app_dict[app_label] = {
'name': app_label.title(),
+ 'app_label': app_label,
'app_url': reverse('admin:app_list', kwargs={'app_label': app_label}, current_app=self.name),
'has_module_perms': has_module_perms,
'models': [model_dict],
@@ -408,6 +410,7 @@ def app_index(self, request, app_label, extra_context=None):
info = (app_label, model._meta.module_name)
model_dict = {
'name': capfirst(model._meta.verbose_name_plural),
+ 'object_name': model._meta.object_name,
'perms': perms,
}
if perms.get('change', False):
@@ -428,6 +431,7 @@ def app_index(self, request, app_label, extra_context=None):
# information.
app_dict = {
'name': app_label.title(),
+ 'app_label': app_label,
'app_url': '',
'has_module_perms': has_module_perms,
'models': [model_dict],
View
4 django/contrib/admin/templates/admin/index.html
@@ -14,7 +14,7 @@
{% if app_list %}
{% for app in app_list %}
- <div class="module">
+ <div class="app-{{ app.app_label }} module">
<table>
<caption>
<a href="{{ app.app_url }}" class="section" title="{% blocktrans with name=app.name %}Models in the {{ name }} application{% endblocktrans %}">
@@ -22,7 +22,7 @@
</a>
</caption>
{% for model in app.models %}
- <tr>
+ <tr class="model-{{ model.object_name|lower }}">
{% if model.admin_url %}
<th scope="row"><a href="{{ model.admin_url }}">{{ model.name }}</a></th>
{% else %}
View
23 tests/regressiontests/admin_views/tests.py
@@ -3391,7 +3391,11 @@ def setUp(self):
def tearDown(self):
self.client.logout()
- def test_css_classes(self):
+ def test_field_prefix_css_classes(self):
+ """
+ Ensure that fields have a CSS class name with a 'field-' prefix.
+ Refs #16371.
+ """
response = self.client.get('/test_admin/admin/admin_views/post/add/')
# The main form
@@ -3407,6 +3411,23 @@ def test_css_classes(self):
self.assertContains(response, '<td class="field-url">')
self.assertContains(response, '<td class="field-posted">')
+ def test_index_css_classes(self):
+ """
+ Ensure that CSS class names are used for each app and model on the
+ admin index pages.
+ Refs #17050.
+ """
+ # General index page
+ response = self.client.get("/test_admin/admin/")
+ self.assertContains(response, '<div class="app-admin_views module">')
+ self.assertContains(response, '<tr class="model-actor">')
+ self.assertContains(response, '<tr class="model-album">')
+
+ # App index page
+ response = self.client.get("/test_admin/admin/admin_views/")
+ self.assertContains(response, '<div class="app-admin_views module">')
+ self.assertContains(response, '<tr class="model-actor">')
+ self.assertContains(response, '<tr class="model-album">')
try:
import docutils
Please sign in to comment.
Something went wrong with that request. Please try again.