diff --git a/wagtail/images/blocks.py b/wagtail/images/blocks.py index 58e307aa04..810b3a8cf2 100644 --- a/wagtail/images/blocks.py +++ b/wagtail/images/blocks.py @@ -140,7 +140,11 @@ class ImageBlock(StructBlock): # For backward compatibility with ImageChooserBlock 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} + struct_value = { + "image": image, + "decorative": False, + "alt_text": (image.default_alt_text if image else ""), + } else: struct_value = super().to_python(value) return self._struct_value_to_image(struct_value) @@ -157,7 +161,7 @@ class ImageBlock(StructBlock): { "image": image, "decorative": False, - "alt_text": None, + "alt_text": (image.default_alt_text if image else ""), } for image in image_values ] diff --git a/wagtail/images/rich_text/contentstate.py b/wagtail/images/rich_text/contentstate.py index a7d99d19c8..2c51b8b381 100644 --- a/wagtail/images/rich_text/contentstate.py +++ b/wagtail/images/rich_text/contentstate.py @@ -1,6 +1,7 @@ """ Draftail / contentstate conversion """ + from draftjs_exporter.dom import DOM from wagtail.admin.rich_text.converters.contentstate_models import Entity diff --git a/wagtail/images/rich_text/editor_html.py b/wagtail/images/rich_text/editor_html.py index cd47cc24d1..153478c300 100644 --- a/wagtail/images/rich_text/editor_html.py +++ b/wagtail/images/rich_text/editor_html.py @@ -1,6 +1,7 @@ """ editor-html conversion for contenteditable editors """ + from wagtail.admin.rich_text.converters import editor_html from wagtail.images import get_image_model from wagtail.images.formats import get_image_format diff --git a/wagtail/images/tests/test_blocks.py b/wagtail/images/tests/test_blocks.py index 3787e2828b..d085ffb60e 100644 --- a/wagtail/images/tests/test_blocks.py +++ b/wagtail/images/tests/test_blocks.py @@ -236,7 +236,7 @@ class TestImageBlock(TestImageChooserBlock): value = block.to_python(self.image.id) self.assertEqual(value.id, self.image.id) - self.assertEqual(value.contextual_alt_text, None) + self.assertEqual(value.contextual_alt_text, "Test image") # Defaulted to title self.assertFalse(value.decorative) def test_to_python_with_dict(self): @@ -267,8 +267,9 @@ class TestImageBlock(TestImageChooserBlock): def test_bulk_to_python_with_list_of_ints(self): block = ImageBlock(required=False) + single_image = block.to_python(self.image.id) result = block.bulk_to_python([None, self.image.id, self.image.id]) - self.assertEqual(result, [None, self.image, self.image]) + self.assertEqual(result, [None, single_image, single_image]) def test_bulk_to_python_with_list_of_dicts(self): block = ImageBlock(required=False)