From 053de6131af83c63ec17d38578889c71de913d24 Mon Sep 17 00:00:00 2001
From: e0ne
Date: Tue, 10 Sep 2013 16:09:55 +0300
Subject: [PATCH] Fixed #5749 -- Added field_name as a key in the _html_output
dict
Thanks SmileyChris for the suggestion.
---
django/forms/forms.py | 3 ++-
tests/forms_tests/tests/test_forms.py | 11 +++++++++++
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/django/forms/forms.py b/django/forms/forms.py
index d8d08e18fe..e04d6a0781 100644
--- a/django/forms/forms.py
+++ b/django/forms/forms.py
@@ -185,7 +185,8 @@ class BaseForm(object):
'label': force_text(label),
'field': six.text_type(bf),
'help_text': help_text,
- 'html_class_attr': html_class_attr
+ 'html_class_attr': html_class_attr,
+ 'field_name': bf.html_name,
})
if top_errors:
diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py
index 168bc1de6a..c9dbece80f 100644
--- a/tests/forms_tests/tests/test_forms.py
+++ b/tests/forms_tests/tests/test_forms.py
@@ -1950,3 +1950,14 @@ class FormsTestCase(TestCase):
boundfield = SomeForm(label_suffix='!')['field']
self.assertHTMLEqual(boundfield.label_tag(label_suffix='$'), '')
+
+ def test_field_name(self):
+ """#5749 - `field_name` may be used as a key in _html_output()."""
+ class SomeForm(Form):
+ some_field = CharField()
+
+ def as_p(self):
+ return self._html_output(u'', u'%s', '
', u' %s', True)
+
+ form = SomeForm()
+ self.assertHTMLEqual(form.as_p(), '')