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

Update blocks in RecipeStreamBlock to use ImageBlock #526

Merged
merged 5 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bakerydemo/base/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from wagtail.images.blocks import ImageChooserBlock


class ImageBlock(StructBlock):
class CaptionedImageBlock(StructBlock):
"""
Custom `StructBlock` for utilizing images with associated caption and
attribution data
Expand All @@ -36,7 +36,7 @@ def get_preview_value(self):

class Meta:
icon = "image"
template = "blocks/image_block.html"
template = "blocks/captioned_image_block.html"
preview_value = {"attribution": "The Wagtail Bakery"}
description = "An image with optional caption and attribution"

Expand Down Expand Up @@ -108,7 +108,7 @@ class BaseStreamBlock(StreamBlock):
),
description="A rich text paragraph",
)
image_block = ImageBlock()
image_block = CaptionedImageBlock()
block_quote = BlockQuote()
embed_block = EmbedBlock(
help_text="Insert an embed URL e.g https://www.youtube.com/watch?v=SGJFWirQ3ks",
Expand Down
254 changes: 186 additions & 68 deletions bakerydemo/base/fixtures/bakerydemo.json

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions bakerydemo/recipes/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
from wagtail.contrib.table_block.blocks import TableBlock
from wagtail.contrib.typed_table_block.blocks import TypedTableBlock
from wagtail.embeds.blocks import EmbedBlock
from wagtail.images.blocks import ImageChooserBlock
from wagtail.images.blocks import ImageBlock

from bakerydemo.base.blocks import BlockQuote, HeadingBlock, ImageBlock
from bakerydemo.base.blocks import BlockQuote, HeadingBlock


class RecipeStepBlock(StructBlock):
Expand Down Expand Up @@ -57,7 +57,7 @@ class RecipeStreamBlock(StreamBlock):
("text", CharBlock()),
("numeric", FloatBlock()),
("rich_text", RichTextBlock()),
("image", ImageChooserBlock()),
("image", ImageBlock()),
],
group="Content",
description=(
Expand Down
146 changes: 146 additions & 0 deletions bakerydemo/recipes/migrations/0002_alter_recipepage_body.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# Generated by Django 6.0.dev20250116121251 on 2025-02-11 16:44
Copy link
Member

Choose a reason for hiding this comment

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

😎


import wagtail.fields
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("recipes", "0001_initial"),
]

operations = [
migrations.AlterField(
model_name="recipepage",
name="body",
field=wagtail.fields.StreamField(
[
("heading_block", 2),
("paragraph_block", 3),
("block_quote", 6),
("table_block", 7),
("typed_table_block", 12),
("image_block", 13),
("embed_block", 14),
("ingredients_list", 16),
("steps_list", 19),
],
blank=True,
block_lookup={
0: (
"wagtail.blocks.CharBlock",
(),
{"form_classname": "title", "required": True},
),
1: (
"wagtail.blocks.ChoiceBlock",
[],
{
"blank": True,
"choices": [
("", "Select a header size"),
("h2", "H2"),
("h3", "H3"),
("h4", "H4"),
],
"required": False,
},
),
2: (
"wagtail.blocks.StructBlock",
[[("heading_text", 0), ("size", 1)]],
{"group": "Content"},
),
3: (
"wagtail.blocks.RichTextBlock",
(),
{
"group": "Content",
"icon": "pilcrow",
"template": "blocks/paragraph_block.html",
},
),
4: ("wagtail.blocks.TextBlock", (), {}),
5: (
"wagtail.blocks.CharBlock",
(),
{"blank": True, "label": "e.g. Mary Berry", "required": False},
),
6: (
"wagtail.blocks.StructBlock",
[[("text", 4), ("attribute_name", 5)]],
{"group": "Content"},
),
7: (
"wagtail.contrib.table_block.blocks.TableBlock",
(),
{"group": "Content"},
),
8: ("wagtail.blocks.CharBlock", (), {}),
9: ("wagtail.blocks.FloatBlock", (), {}),
10: ("wagtail.blocks.RichTextBlock", (), {}),
11: ("wagtail.images.blocks.ImageBlock", [], {}),
12: (
"wagtail.contrib.typed_table_block.blocks.TypedTableBlock",
[
[
("text", 8),
("numeric", 9),
("rich_text", 10),
("image", 11),
]
],
{"group": "Content"},
),
13: ("wagtail.images.blocks.ImageBlock", [], {"group": "Media"}),
14: (
"wagtail.embeds.blocks.EmbedBlock",
(),
{
"group": "Media",
"help_text": "Insert an embed URL e.g https://www.youtube.com/watch?v=SGJFWirQ3ks",
"icon": "media",
"template": "blocks/embed_block.html",
},
),
15: (
"wagtail.blocks.RichTextBlock",
(),
{"features": ["bold", "italic", "link"]},
),
16: (
"wagtail.blocks.ListBlock",
(15,),
{
"group": "Cooking",
"icon": "list-ol",
"max_num": 10,
"min_num": 2,
},
),
17: (
"wagtail.blocks.ChoiceBlock",
[],
{"choices": [("S", "Small"), ("M", "Medium"), ("L", "Large")]},
),
18: (
"wagtail.blocks.StructBlock",
[[("text", 15), ("difficulty", 17)]],
{},
),
19: (
"wagtail.blocks.ListBlock",
(18,),
{
"group": "Cooking",
"icon": "tasks",
"max_num": 10,
"min_num": 2,
},
),
},
help_text="The recipe’s step-by-step instructions and any other relevant information.",
),
),
]
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ If you're a Python or Django developer, fork the repo and get stuck in! If you'd
If you change content or images in this repo and need to prepare a new fixture file for export, do the following on a branch:

```bash
./manage.py dumpdata --natural-foreign --indent 2 -e auth.permission -e contenttypes -e wagtailcore.GroupCollectionPermission -e wagtailimages.rendition -e sessions -e wagtailsearch.indexentry -e wagtailsearch.sqliteftsindexentry -e wagtailcore.referenceindex -e wagtailcore.pagesubscription > bakerydemo/base/fixtures/bakerydemo.json
prettier --write bakerydemo/base/fixtures/bakerydemo.json
./manage.py dumpdata --natural-foreign --indent 2 -e auth.permission -e contenttypes -e wagtailcore.GroupCollectionPermission -e wagtailimages.rendition -e sessions -e wagtailsearch.indexentry -e wagtailsearch.sqliteftsindexentry -e wagtailcore.referenceindex -e wagtailcore.pagesubscription -e wagtailcore.workflowcontenttype -e wagtailadmin.editingsession > bakerydemo/base/fixtures/bakerydemo.json
npx prettier --write bakerydemo/base/fixtures/bakerydemo.json
Copy link
Member

Choose a reason for hiding this comment

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

Thank you!

```

Please optimize any included images to 1200px wide with JPEG compression at 60%. Note that `media/images` is ignored in the repo by `.gitignore` but `media/original_images` is not. Wagtail's local image "renditions" are excluded in the fixture recipe above.
Expand Down