Fixed #27642 -- Made forms.utils.flatatt() omit 'None' values from attrs.
This commit is contained in:
parent
3e5c5e6754
commit
4a51ba228b
|
@ -40,7 +40,7 @@ def flatatt(attrs):
|
||||||
if isinstance(value, bool):
|
if isinstance(value, bool):
|
||||||
if value:
|
if value:
|
||||||
boolean_attrs.append((attr,))
|
boolean_attrs.append((attr,))
|
||||||
else:
|
elif value is not None:
|
||||||
key_value_attrs.append((attr, value))
|
key_value_attrs.append((attr, value))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -34,6 +34,7 @@ class FormsUtilsTestCase(SimpleTestCase):
|
||||||
flatatt({'class': "news", 'title': "Read this", 'required': False}),
|
flatatt({'class': "news", 'title': "Read this", 'required': False}),
|
||||||
' class="news" title="Read this"'
|
' class="news" title="Read this"'
|
||||||
)
|
)
|
||||||
|
self.assertEqual(flatatt({'class': None}), '')
|
||||||
self.assertEqual(flatatt({}), '')
|
self.assertEqual(flatatt({}), '')
|
||||||
|
|
||||||
def test_flatatt_no_side_effects(self):
|
def test_flatatt_no_side_effects(self):
|
||||||
|
|
Loading…
Reference in New Issue