kopia lustrzana https://github.com/wagtail/wagtail
Handle None in ImageBlock.to_python
rodzic
8c0ebb74a0
commit
645630828e
|
@ -138,7 +138,7 @@ class ImageBlock(StructBlock):
|
|||
|
||||
def to_python(self, value):
|
||||
# For backward compatibility with ImageChooserBlock
|
||||
if isinstance(value, int):
|
||||
if value is None or isinstance(value, int):
|
||||
image = self.child_blocks["image"].to_python(value)
|
||||
struct_value = {"image": image, "decorative": False, "alt_text": None}
|
||||
else:
|
||||
|
|
|
@ -248,6 +248,13 @@ class TestImageBlock(TestImageChooserBlock):
|
|||
self.assertEqual(result.contextual_alt_text, "Sample text")
|
||||
self.assertFalse(result.decorative)
|
||||
|
||||
def test_to_python_with_none(self):
|
||||
# Like the test_to_python_with_int case, this can occur when a non-required
|
||||
# ImageChooserBlock has been changed to an ImageBlock
|
||||
block = ImageBlock(required=False)
|
||||
value = block.to_python(None)
|
||||
self.assertIsNone(value)
|
||||
|
||||
def test_bulk_to_python_with_empty_list(self):
|
||||
block = ImageBlock(required=False)
|
||||
result = block.bulk_to_python([])
|
||||
|
|
Ładowanie…
Reference in New Issue