mirror of https://github.com/django/django.git
Fixed #28058 -- Restored empty BoundFields evaluating to True.
Regression in b52c73008a
This commit is contained in:
parent
e5dce7b0fb
commit
c09bf8d767
|
@ -53,6 +53,10 @@ class BoundField:
|
||||||
for widget in self.field.widget.subwidgets(self.html_name, self.value(), attrs=attrs)
|
for widget in self.field.widget.subwidgets(self.html_name, self.value(), attrs=attrs)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def __bool__(self):
|
||||||
|
# BoundField evaluates to True even if it doesn't have subwidgets.
|
||||||
|
return True
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return iter(self.subwidgets)
|
return iter(self.subwidgets)
|
||||||
|
|
||||||
|
|
|
@ -24,3 +24,6 @@ Bugfixes
|
||||||
|
|
||||||
* Fixed empty POST data table appearing instead of "No POST data" in HTML debug
|
* Fixed empty POST data table appearing instead of "No POST data" in HTML debug
|
||||||
page (:ticket:`28079`).
|
page (:ticket:`28079`).
|
||||||
|
|
||||||
|
* Restored ``BoundField``\s without any ``choices`` evaluating to ``True``
|
||||||
|
(:ticket:`28058`).
|
||||||
|
|
|
@ -746,6 +746,13 @@ Java</label></li>
|
||||||
[str(bf[1]), str(bf[2]), str(bf[3])],
|
[str(bf[1]), str(bf[2]), str(bf[3])],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_boundfield_bool(self):
|
||||||
|
"""BoundField without any choices (subwidgets) evaluates to True."""
|
||||||
|
class TestForm(Form):
|
||||||
|
name = ChoiceField(choices=[])
|
||||||
|
|
||||||
|
self.assertIs(bool(TestForm()['name']), True)
|
||||||
|
|
||||||
def test_forms_with_multiple_choice(self):
|
def test_forms_with_multiple_choice(self):
|
||||||
# MultipleChoiceField is a special case, as its data is required to be a list:
|
# MultipleChoiceField is a special case, as its data is required to be a list:
|
||||||
class SongForm(Form):
|
class SongForm(Form):
|
||||||
|
|
Loading…
Reference in New Issue