Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New ImageBlock with contextual alt text #492

Closed
wants to merge 3 commits into from

Conversation

Chiemezuo
Copy link
Contributor

This will be the modifications for the bakerydemo project to align with the changes from PR #11791.

@Chiemezuo Chiemezuo force-pushed the update/for-new-image-block branch from fd04062 to 2811418 Compare July 26, 2024 10:34
@Stormheg Stormheg self-requested a review July 29, 2024 12:10
@thibaudcolas thibaudcolas changed the title modifies BakeryDemo guide for new ImageBlock New ImageBlock with contextual alt text Aug 2, 2024
Copy link
Member

@thibaudcolas thibaudcolas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid! I’ve suggested one minor change. Note we will need for wagtail#11791 to be merged and released before we can merge this for bakerydemo, as the demo site also has to support stable versions of Wagtail.

("text", CharBlock()),
("numeric", FloatBlock()),
("rich_text", RichTextBlock()),
("image", CaptionedImageBlock()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it’d be more interesting to use ImageBlock directly so we can see it in action without caption-related fields.

Suggested change
("image", CaptionedImageBlock()),
("image", ImageBlock()),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, do you think I should remove the CaptionedImageBlock() entirely?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think CaptionedImageBlock still has a right to exist. It would allow us to test the ImageChooserBlock, something which is now not possible anymore as it has all been changed to ImageBlock.

Perhaps we can allow ImageBlock to be used directly and still have the CaptionedImageBlock somewhere else?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Storm, and I find it rather surprising that CaptionedImageBlock uses ImageBlock underneath. That means the block will have two fields that can be purposed as alt-text: the top-level CaptionedImageBlock.caption and the inner ImageBlock.alt_text.

I think it makes sense to use Wagtail's ImageBlock as-is, and rename bakerydemo's ImageBlock to CaptionedImageBlock while keeping ImageChooserBlock underneath it, and find other places to use it.

Copy link
Member

@laymonage laymonage Feb 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, I just realised that alt text and captions can have different purposes.

I'm not sure how to proceed here. For the record, we currently have three image blocks that matter:

  • base.ImageBlock: ImageChooserBlock + caption + attribution. This is not used directly, and instead is used in:
    • base.BaseStreamBlock.image_block, which is used in almost all StreamFields except RecipePage
    • recipe.RecipeStreamBlock.image_block, only used in RecipePages
  • ImageChooserBlock used in recipe.RecipeStreamBlock.typed_table_block

This PR renamed base.ImageBlock to base.CaptionedImageBlock and changed its ImageChooserBlock to use ImageBlock. With the assumption that captions and alt text serve different purposes, I think this change is OK. Note that this affects all StreamFields.

If we proceed with Thibaud's suggestion, that means we'll lose the bare ImageChooserBlock. While I agree that having bare ImageChooserBlock would help for testing, I can't think of a place to put it in bakerydemo where it would be acceptable to use instead of ImageBlock. I suppose such is the inherent reason of why we made Wagtail's ImageBlock in the first place...

Alternatively, we could proceed with Thibaud's suggestion, and then make it so that either base.BaseStreamBlock.image_block or recipe.RecipeStreamBlock.image_block uses the ImageBlock directly, while keeping ImageChooserBlock in CaptionedImageBlock. This means one of the two image_blocks will lose the attribution field, and the caption will be replaced with alt_text instead. (Also means we won't have a block with both alt_text and caption.)

Copy link
Member

@Stormheg Stormheg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work so far @Chiemezuo - makes it a lot easier to review your changes from wagtail/wagtail#11791 👍 👍

I have a comment about still using ImageChooserBlock in some places so we can continue using bakerydemo to test that separately from the new ImageBlock.

Also, we discussed updating the fixtures with initial data. Could you populate the contextual alt text fields for the pages now using ImageBlock and generate new fixtures to reflect the changes? Currently, trying to save a blog pages results in an error because there is no contextual alt text set. Updating the fixtures will resolve that.

As @thibaudcolas mentioned, we cannot merge this until ImageBlock makes it into a stable version of Wagtail. So lets keep this marked as draft for now.

("text", CharBlock()),
("numeric", FloatBlock()),
("rich_text", RichTextBlock()),
("image", CaptionedImageBlock()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think CaptionedImageBlock still has a right to exist. It would allow us to test the ImageChooserBlock, something which is now not possible anymore as it has all been changed to ImageBlock.

Perhaps we can allow ImageBlock to be used directly and still have the CaptionedImageBlock somewhere else?

@Chiemezuo
Copy link
Contributor Author

Thanks! @Stormheg
I've added the fixtures. Just to be sure if I got things right, can you help me check again on your end?

Comment on lines 12053 to 12074
{
"model": "wagtailadmin.editingsession",
"pk": 1,
"fields": {
"user": ["admin"],
"content_type": ["wagtailcore", "page"],
"object_id": "82",
"last_seen_at": "2024-08-06T01:35:42.544Z",
"is_editing": false
}
},
{
"model": "wagtailadmin.editingsession",
"pk": 2,
"fields": {
"user": ["admin"],
"content_type": ["wagtailcore", "page"],
"object_id": "82",
"last_seen_at": "2024-08-06T01:38:47.215Z",
"is_editing": false
}
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These models are new, should these be part of the fixtures? Asking @laymonage or @gasman for input.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to add new models, that should be done in a separate PR. For this PR, we should filter the fixture changes to only the ones relevant for the PR.

@Stormheg
Copy link
Member

Stormheg commented Aug 6, 2024

@Chiemezuo I see you added the fixtures, but I'm still missing initial data for the contextual alt text fields.

http://localhost:8000/admin/pages/77/edit/

Screenshot 2024-08-06 at 9 03 07 AM

Could you populate these fields and regenerate the fixtures?

@Stormheg
Copy link
Member

Stormheg commented Aug 6, 2024

Fix for the build-container workflow here: #495

@Chiemezuo
Copy link
Contributor Author

Thanks for that pointer! @Stormheg
Done!

@Stormheg
Copy link
Member

Stormheg commented Aug 28, 2024

@Chiemezuo I wanted to test drive wagtail/wagtail#11791 using this branch but I got an error importing the fixtures with manage.py load_initial_data

  File "/Users/storm/projects/open-source/wagtail/bakerydemo-chiemezuo/venv/lib/python3.12/site-packages/wagtail/blocks/stream_block.py", line 392, in get_searchable_content
    content.extend(child.block.get_searchable_content(child.value))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/storm/projects/open-source/wagtail/bakerydemo-chiemezuo/venv/lib/python3.12/site-packages/wagtail/images/blocks.py", line 77, in get_searchable_content
    return super().get_searchable_content(value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/storm/projects/open-source/wagtail/bakerydemo-chiemezuo/venv/lib/python3.12/site-packages/wagtail/blocks/struct_block.py", line 275, in get_searchable_content
    block.get_searchable_content(value.get(name, block.get_default()))
                                 ^^^^^^^^^
AttributeError: Problem installing fixture '/Users/storm/projects/open-source/wagtail/bakerydemo-chiemezuo/bakerydemo/base/fixtures/bakerydemo.json': 'Image' object has no attribute 'get'

I have this revision from wagtail/wagtail#11791 checked out and installed: wagtail/wagtail@ac86fe7

Could you have a look please? Not sure what is the cause of this.

Edit: seeing the same error when I manually save a page

@Chiemezuo
Copy link
Contributor Author

I'll look into it and give you feedback in about 2 hours or so. @Stormheg

@Chiemezuo
Copy link
Contributor Author

@Stormheg Looking at it right away, I suspect I know the problem. It's from one of the last changes I did at the last moment.
@thibaudcolas felt the get_searchable_content could be reworked and I attempted with the parent class' method. I've replicated and fixed the issue on the PR #11791.
You can check it again.

Copy link
Member

@laymonage laymonage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this! I'll rebase the PR and migrations, and see if we can find a good solution for the ImageBlock vs CaptionedImageBlock situation.

("text", CharBlock()),
("numeric", FloatBlock()),
("rich_text", RichTextBlock()),
("image", CaptionedImageBlock()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Storm, and I find it rather surprising that CaptionedImageBlock uses ImageBlock underneath. That means the block will have two fields that can be purposed as alt-text: the top-level CaptionedImageBlock.caption and the inner ImageBlock.alt_text.

I think it makes sense to use Wagtail's ImageBlock as-is, and rename bakerydemo's ImageBlock to CaptionedImageBlock while keeping ImageChooserBlock underneath it, and find other places to use it.

@laymonage laymonage force-pushed the update/for-new-image-block branch from 9983305 to 94ed7ce Compare February 11, 2025 12:39
@Stormheg
Copy link
Member

Closing in favor of #526

@Stormheg Stormheg closed this Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

4 participants