Code

Ticket #16371: 16371.admin-field-css-classes.diff

File 16371.admin-field-css-classes.diff, 4.4 KB (added by julien, 3 years ago)
Line 
1diff --git a/django/contrib/admin/templates/admin/edit_inline/tabular.html b/django/contrib/admin/templates/admin/edit_inline/tabular.html
2index 71b097e..b891a76 100644
3--- a/django/contrib/admin/templates/admin/edit_inline/tabular.html
4+++ b/django/contrib/admin/templates/admin/edit_inline/tabular.html
5@@ -44,7 +44,7 @@
6         {% for fieldset in inline_admin_form %}
7           {% for line in fieldset %}
8             {% for field in line %}
9-              <td class="{{ field.field.name }}">
10+              <td{% if field.field.name %} class="field-{{ field.field.name }}"{% endif %}>
11               {% if field.is_readonly %}
12                   <p>{{ field.contents }}</p>
13               {% else %}
14diff --git a/django/contrib/admin/templates/admin/includes/fieldset.html b/django/contrib/admin/templates/admin/includes/fieldset.html
15index 6363aee..0b71d50 100644
16--- a/django/contrib/admin/templates/admin/includes/fieldset.html
17+++ b/django/contrib/admin/templates/admin/includes/fieldset.html
18@@ -4,7 +4,7 @@
19         <div class="description">{{ fieldset.description|safe }}</div>
20     {% endif %}
21     {% for line in fieldset %}
22-        <div class="form-row{% if line.fields|length_is:'1' and line.errors %} errors{% endif %}{% for field in line %} {{ field.field.name }}{% endfor %}">
23+        <div class="form-row{% if line.fields|length_is:'1' and line.errors %} errors{% endif %}{% for field in line %}{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% endfor %}">
24             {% if line.fields|length_is:'1' %}{{ line.errors }}{% endif %}
25             {% for field in line %}
26                 <div{% if not line.fields|length_is:'1' %} class="field-box{% if not field.is_readonly and field.errors %} errors{% endif %}"{% endif %}>
27diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
28index b6e7b9e..b15e97a 100644
29--- a/tests/regressiontests/admin_views/tests.py
30+++ b/tests/regressiontests/admin_views/tests.py
31@@ -2786,11 +2786,11 @@ class ReadonlyTest(TestCase):
32             formats.localize(datetime.date.today() - datetime.timedelta(days=7))
33         )
34 
35-        self.assertContains(response, '<div class="form-row coolness">')
36-        self.assertContains(response, '<div class="form-row awesomeness_level">')
37-        self.assertContains(response, '<div class="form-row posted">')
38-        self.assertContains(response, '<div class="form-row value">')
39-        self.assertContains(response, '<div class="form-row ">')
40+        self.assertContains(response, '<div class="form-row field-coolness">')
41+        self.assertContains(response, '<div class="form-row field-awesomeness_level">')
42+        self.assertContains(response, '<div class="form-row field-posted">')
43+        self.assertContains(response, '<div class="form-row field-value">')
44+        self.assertContains(response, '<div class="form-row">')
45         self.assertContains(response, '<p class="help">', 3)
46         self.assertContains(response, '<p class="help">Some help text for the title (with unicode ŠĐĆŽćžšđ)</p>')
47         self.assertContains(response, '<p class="help">Some help text for the content (with unicode ŠĐĆŽćžšđ)</p>')
48@@ -2983,6 +2983,33 @@ class GroupAdminTest(TestCase):
49             self.assertEqual(response.status_code, 200)
50 
51 
52+class CSSTest(TestCase):
53+    urls = "regressiontests.admin_views.urls"
54+    fixtures = ['admin-views-users.xml']
55+
56+    def setUp(self):
57+        self.client.login(username='super', password='secret')
58+
59+    def tearDown(self):
60+        self.client.logout()
61+
62+    def test_css_classes(self):
63+        response = self.client.get('/test_admin/admin/admin_views/post/add/')
64+
65+        # The main form
66+        self.assertContains(response, 'class="form-row field-title"')
67+        self.assertContains(response, 'class="form-row field-content"')
68+        self.assertContains(response, 'class="form-row field-public"')
69+        self.assertContains(response, 'class="form-row field-awesomeness_level"')
70+        self.assertContains(response, 'class="form-row field-coolness"')
71+        self.assertContains(response, 'class="form-row field-value"')
72+        self.assertContains(response, 'class="form-row"') # The lambda function
73+
74+        # The tabular inline
75+        self.assertContains(response, '<td class="field-url">')
76+        self.assertContains(response, '<td class="field-posted">')
77+
78+
79 try:
80     import docutils
81 except ImportError: