From 17659adf93574deeaeb23b867f1c67248a7a3c80 Mon Sep 17 00:00:00 2001 From: Julien Phalip Date: Mon, 10 Oct 2011 12:35:06 +0000 Subject: [PATCH] Fixed #16371 -- Added a prefix "field-" to all CSS class names automatically generated from field names in admin forms to avoid conflicts with other common class names (e.g. "button"). This is backwards-incompatible for those who previously used plain field names as selector in custom style sheets or javascript transformations. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16953 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- .../templates/admin/edit_inline/tabular.html | 2 +- .../templates/admin/includes/fieldset.html | 2 +- docs/releases/1.4.txt | 10 +++++ tests/regressiontests/admin_views/tests.py | 37 ++++++++++++++++--- 4 files changed, 44 insertions(+), 7 deletions(-) diff --git a/django/contrib/admin/templates/admin/edit_inline/tabular.html b/django/contrib/admin/templates/admin/edit_inline/tabular.html index 71b097e9d9e..b891a76a72b 100644 --- a/django/contrib/admin/templates/admin/edit_inline/tabular.html +++ b/django/contrib/admin/templates/admin/edit_inline/tabular.html @@ -44,7 +44,7 @@ {% for fieldset in inline_admin_form %} {% for line in fieldset %} {% for field in line %} - + {% if field.is_readonly %}

{{ field.contents }}

{% else %} diff --git a/django/contrib/admin/templates/admin/includes/fieldset.html b/django/contrib/admin/templates/admin/includes/fieldset.html index 6363aeeee4f..0b71d501f9a 100644 --- a/django/contrib/admin/templates/admin/includes/fieldset.html +++ b/django/contrib/admin/templates/admin/includes/fieldset.html @@ -4,7 +4,7 @@
{{ fieldset.description|safe }}
{% endif %} {% for line in fieldset %} -
+
{% if line.fields|length_is:'1' %}{{ line.errors }}{% endif %} {% for field in line %} diff --git a/docs/releases/1.4.txt b/docs/releases/1.4.txt index c6b547dab6d..b71fd21daa7 100644 --- a/docs/releases/1.4.txt +++ b/docs/releases/1.4.txt @@ -431,6 +431,16 @@ files were removed and grouped into two sprite files, respectively: those icons to customize the admin then you will want to replace them with your own icons or retrieve them from a previous release. +CSS class names in admin forms +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +To avoid conflicts with other common CSS class names (e.g. "button"), a prefix +"field-" has been added to all CSS class names automatically generated from the +form field names in the main admin forms, stacked inline forms and tabular +inline cells. You will need to take that prefix into account in your custom +style sheets or javascript files if you previously used plain field names as +selectors for custom styles or javascript transformations. + Compatibility with old signed data ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py index b6e7b9ebbb2..b15e97af1f3 100644 --- a/tests/regressiontests/admin_views/tests.py +++ b/tests/regressiontests/admin_views/tests.py @@ -2786,11 +2786,11 @@ class ReadonlyTest(TestCase): formats.localize(datetime.date.today() - datetime.timedelta(days=7)) ) - self.assertContains(response, '
') - self.assertContains(response, '
') - self.assertContains(response, '
') - self.assertContains(response, '
') - self.assertContains(response, '
') + self.assertContains(response, '
') + self.assertContains(response, '
') + self.assertContains(response, '
') + self.assertContains(response, '
') + self.assertContains(response, '
') self.assertContains(response, '

', 3) self.assertContains(response, '

Some help text for the title (with unicode ŠĐĆŽćžšđ)

') self.assertContains(response, '

Some help text for the content (with unicode ŠĐĆŽćžšđ)

') @@ -2983,6 +2983,33 @@ class GroupAdminTest(TestCase): self.assertEqual(response.status_code, 200) +class CSSTest(TestCase): + urls = "regressiontests.admin_views.urls" + fixtures = ['admin-views-users.xml'] + + def setUp(self): + self.client.login(username='super', password='secret') + + def tearDown(self): + self.client.logout() + + def test_css_classes(self): + response = self.client.get('/test_admin/admin/admin_views/post/add/') + + # The main form + self.assertContains(response, 'class="form-row field-title"') + self.assertContains(response, 'class="form-row field-content"') + self.assertContains(response, 'class="form-row field-public"') + self.assertContains(response, 'class="form-row field-awesomeness_level"') + self.assertContains(response, 'class="form-row field-coolness"') + self.assertContains(response, 'class="form-row field-value"') + self.assertContains(response, 'class="form-row"') # The lambda function + + # The tabular inline + self.assertContains(response, '') + self.assertContains(response, '') + + try: import docutils except ImportError: