From 1884bf8e8e9fb3f9f44a9ec216aca96f63974268 Mon Sep 17 00:00:00 2001
From: Markus Amalthea Magnuson
Date: Fri, 5 Jun 2015 22:33:22 +0100
Subject: [PATCH] Fixed #12437 -- Added css_classes to Form._html_output()
---
django/forms/forms.py | 2 ++
tests/forms_tests/tests/test_forms.py | 48 ++++++++++++++++++++++++++-
2 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/django/forms/forms.py b/django/forms/forms.py
index 30d717588e..4ee79d13ce 100644
--- a/django/forms/forms.py
+++ b/django/forms/forms.py
@@ -227,6 +227,7 @@ class BaseForm(object):
'field': six.text_type(bf),
'help_text': help_text,
'html_class_attr': html_class_attr,
+ 'css_classes': css_classes,
'field_name': bf.html_name,
})
@@ -250,6 +251,7 @@ class BaseForm(object):
'field': '',
'help_text': '',
'html_class_attr': html_class_attr,
+ 'css_classes': '',
'field_name': '',
})
output.append(last_row)
diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py
index e07fae22d1..07de828334 100644
--- a/tests/forms_tests/tests/test_forms.py
+++ b/tests/forms_tests/tests/test_forms.py
@@ -2274,11 +2274,57 @@ class FormsTestCase(SimpleTestCase):
some_field = CharField()
def as_p(self):
- return self._html_output('', '%s', '
', ' %s', True)
+ return self._html_output(
+ normal_row='',
+ error_row='%s',
+ row_ender='',
+ help_text_html=' %s',
+ errors_on_separate_row=True,
+ )
form = SomeForm()
self.assertHTMLEqual(form.as_p(), '')
+ def test_field_without_css_classes(self):
+ """
+ `css_classes` may be used as a key in _html_output() (empty classes).
+ """
+ class SomeForm(Form):
+ some_field = CharField()
+
+ def as_p(self):
+ return self._html_output(
+ normal_row='',
+ error_row='%s',
+ row_ender='',
+ help_text_html=' %s',
+ errors_on_separate_row=True,
+ )
+
+ form = SomeForm()
+ self.assertHTMLEqual(form.as_p(), '')
+
+ def test_field_with_css_class(self):
+ """
+ `css_classes` may be used as a key in _html_output() (class comes
+ from required_css_class in this case).
+ """
+ class SomeForm(Form):
+ some_field = CharField()
+ required_css_class = 'foo'
+
+ def as_p(self):
+ return self._html_output(
+ normal_row='',
+ error_row='%s',
+ row_ender='',
+ help_text_html=' %s',
+ errors_on_separate_row=True,
+ )
+
+ form = SomeForm()
+ self.assertHTMLEqual(form.as_p(), '')
+
def test_field_name_with_hidden_input(self):
"""
BaseForm._html_output() should merge all the hidden input fields and