Skip to content

Commit 991fca2

Browse files
author
Arne Tarara - Automated
committed
Merge remote-tracking branch 'upstream/main'
2 parents 78ac91b + 99e6906 commit 991fca2

File tree

15 files changed

+1178
-11
lines changed

15 files changed

+1178
-11
lines changed

bakerydemo/base/blocks.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@
1212
from wagtail.images.blocks import ImageChooserBlock
1313

1414

15+
def get_image_api_representation(image):
16+
return {
17+
"id": image.pk,
18+
"title": image.title,
19+
"meta": {
20+
"type": type(image)._meta.label,
21+
"download_url": image.file.url,
22+
},
23+
}
24+
25+
1526
class CaptionedImageBlock(StructBlock):
1627
"""
1728
Custom `StructBlock` for utilizing images with associated caption and
@@ -34,6 +45,11 @@ def get_preview_value(self):
3445
"caption": self.preview_image.description,
3546
}
3647

48+
def get_api_representation(self, value, context=None):
49+
data = super().get_api_representation(value, context)
50+
data["image"] = get_image_api_representation(value["image"])
51+
return data
52+
3753
class Meta:
3854
icon = "image"
3955
template = "blocks/captioned_image_block.html"

bakerydemo/base/migrations/0024_alter_formpage_body_alter_gallerypage_body_and_more.py

Lines changed: 352 additions & 0 deletions
Large diffs are not rendered by default.

bakerydemo/base/models.py

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
from wagtail.admin.panels import (
88
FieldPanel,
99
FieldRowPanel,
10+
HelpPanel,
1011
InlinePanel,
1112
MultiFieldPanel,
1213
PublishingPanel,
1314
)
15+
from wagtail.api import APIField
1416
from wagtail.contrib.forms.models import AbstractEmailForm, AbstractFormField
1517
from wagtail.contrib.forms.panels import FormSubmissionsPanel
1618
from wagtail.contrib.settings.models import (
@@ -19,6 +21,7 @@
1921
register_setting,
2022
)
2123
from wagtail.fields import RichTextField, StreamField
24+
from wagtail.images.models import Image
2225
from wagtail.models import (
2326
Collection,
2427
DraftStateMixin,
@@ -35,6 +38,9 @@
3538

3639
from .blocks import BaseStreamBlock
3740

41+
# Allow filtering by collection
42+
Image.api_fields = [APIField("collection")]
43+
3844

3945
class Person(
4046
WorkflowMixin,
@@ -111,6 +117,13 @@ class Person(
111117
index.AutocompleteField("last_name"),
112118
]
113119

120+
api_fields = [
121+
APIField("first_name"),
122+
APIField("last_name"),
123+
APIField("job_title"),
124+
APIField("image"),
125+
]
126+
114127
@property
115128
def thumb_image(self):
116129
# Returns an empty string if there is no profile pic or the rendition
@@ -195,6 +208,10 @@ class FooterText(
195208
PublishingPanel(),
196209
]
197210

211+
api_fields = [
212+
APIField("body"),
213+
]
214+
198215
def __str__(self):
199216
return "Footer text"
200217

@@ -234,6 +251,12 @@ class StandardPage(Page):
234251
FieldPanel("image"),
235252
]
236253

254+
api_fields = [
255+
APIField("introduction"),
256+
APIField("image"),
257+
APIField("body"),
258+
]
259+
237260

238261
class HomePage(Page):
239262
"""
@@ -358,13 +381,15 @@ class HomePage(Page):
358381
],
359382
heading="Hero section",
360383
),
384+
HelpPanel("This is a help panel"),
361385
MultiFieldPanel(
362386
[
363387
FieldPanel("promo_image"),
364388
FieldPanel("promo_title"),
365389
FieldPanel("promo_text"),
366390
],
367391
heading="Promo section",
392+
help_text="This is just a help text",
368393
),
369394
FieldPanel("body"),
370395
MultiFieldPanel(
@@ -392,6 +417,23 @@ class HomePage(Page):
392417
),
393418
]
394419

420+
api_fields = [
421+
APIField("image"),
422+
APIField("hero_text"),
423+
APIField("hero_cta"),
424+
APIField("hero_cta_link"),
425+
APIField("body"),
426+
APIField("promo_image"),
427+
APIField("promo_title"),
428+
APIField("promo_text"),
429+
APIField("featured_section_1_title"),
430+
APIField("featured_section_1"),
431+
APIField("featured_section_2_title"),
432+
APIField("featured_section_2"),
433+
APIField("featured_section_3_title"),
434+
APIField("featured_section_3"),
435+
]
436+
395437
def __str__(self):
396438
return self.title
397439

@@ -411,7 +453,7 @@ class GalleryPage(Page):
411453
blank=True,
412454
on_delete=models.SET_NULL,
413455
related_name="+",
414-
help_text="Landscape mode only; horizontal width between 1000px and " "3000px.",
456+
help_text="Landscape mode only; horizontal width between 1000px and 3000px.",
415457
)
416458
body = StreamField(
417459
BaseStreamBlock(), verbose_name="Page body", blank=True, use_json_field=True
@@ -436,6 +478,13 @@ class GalleryPage(Page):
436478
# array no subpage can be added
437479
subpage_types = []
438480

481+
api_fields = [
482+
APIField("introduction"),
483+
APIField("image"),
484+
APIField("body"),
485+
APIField("collection"),
486+
]
487+
439488

440489
class FormField(AbstractFormField):
441490
"""
@@ -483,6 +532,16 @@ class FormPage(AbstractEmailForm):
483532
),
484533
]
485534

535+
api_fields = [
536+
APIField("form_fields"),
537+
APIField("from_address"),
538+
APIField("to_address"),
539+
APIField("subject"),
540+
APIField("image"),
541+
APIField("body"),
542+
APIField("thank_you_text"),
543+
]
544+
486545

487546
@register_setting(icon="cog")
488547
class GenericSettings(ClusterableModel, BaseGenericSetting):
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Generated by Django 5.1.8 on 2025-06-19 11:15
2+
3+
import wagtail.fields
4+
from django.db import migrations
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
("blog", "0006_rename_blogpeoplerelationship_person"),
11+
]
12+
13+
operations = [
14+
migrations.AlterField(
15+
model_name="blogpage",
16+
name="body",
17+
field=wagtail.fields.StreamField(
18+
[
19+
("heading_block", 2),
20+
("paragraph_block", 3),
21+
("image_block", 6),
22+
("block_quote", 9),
23+
("embed_block", 10),
24+
],
25+
blank=True,
26+
block_lookup={
27+
0: (
28+
"wagtail.blocks.CharBlock",
29+
(),
30+
{"form_classname": "title", "required": True},
31+
),
32+
1: (
33+
"wagtail.blocks.ChoiceBlock",
34+
[],
35+
{
36+
"blank": True,
37+
"choices": [
38+
("", "Select a header size"),
39+
("h2", "H2"),
40+
("h3", "H3"),
41+
("h4", "H4"),
42+
],
43+
"required": False,
44+
},
45+
),
46+
2: (
47+
"wagtail.blocks.StructBlock",
48+
[[("heading_text", 0), ("size", 1)]],
49+
{},
50+
),
51+
3: (
52+
"wagtail.blocks.RichTextBlock",
53+
(),
54+
{
55+
"description": "A rich text paragraph",
56+
"icon": "pilcrow",
57+
"preview_value": '\n <h2>Our bread pledge</h2>\n <p>As a bakery, <b>breads</b> have <i>always</i> been in our hearts.\n <a href="https://en.wikipedia.org/wiki/Staple_food">Staple foods</a>\n are essential for society, and – bread is the tastiest of all.\n We love to transform batters and doughs into baked goods with a firm\n dry crust and fluffy center.</p>\n ',
58+
"template": "blocks/paragraph_block.html",
59+
},
60+
),
61+
4: (
62+
"wagtail.images.blocks.ImageChooserBlock",
63+
(),
64+
{"required": True},
65+
),
66+
5: ("wagtail.blocks.CharBlock", (), {"required": False}),
67+
6: (
68+
"wagtail.blocks.StructBlock",
69+
[[("image", 4), ("caption", 5), ("attribution", 5)]],
70+
{},
71+
),
72+
7: ("wagtail.blocks.TextBlock", (), {}),
73+
8: (
74+
"wagtail.blocks.CharBlock",
75+
(),
76+
{"blank": True, "label": "e.g. Mary Berry", "required": False},
77+
),
78+
9: (
79+
"wagtail.blocks.StructBlock",
80+
[[("text", 7), ("attribute_name", 8)]],
81+
{},
82+
),
83+
10: (
84+
"wagtail.embeds.blocks.EmbedBlock",
85+
(),
86+
{
87+
"description": "An embedded video or other media",
88+
"help_text": "Insert an embed URL e.g https://www.youtube.com/watch?v=SGJFWirQ3ks",
89+
"icon": "media",
90+
"preview_template": "base/preview/static_embed_block.html",
91+
"preview_value": "https://www.youtube.com/watch?v=mwrGSfiB1Mg",
92+
"template": "blocks/embed_block.html",
93+
},
94+
),
95+
},
96+
verbose_name="Page body",
97+
),
98+
),
99+
]

bakerydemo/blog/models.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from modelcluster.fields import ParentalKey
66
from taggit.models import Tag, TaggedItemBase
77
from wagtail.admin.panels import FieldPanel, MultipleChooserPanel
8+
from wagtail.api import APIField
89
from wagtail.contrib.routable_page.models import RoutablePageMixin, route
910
from wagtail.fields import StreamField
1011
from wagtail.models import Orderable, Page
@@ -30,6 +31,11 @@ class BlogPersonRelationship(Orderable, models.Model):
3031
)
3132
panels = [FieldPanel("person")]
3233

34+
api_fields = [
35+
APIField("page"),
36+
APIField("person"),
37+
]
38+
3339

3440
class BlogPageTag(TaggedItemBase):
3541
"""
@@ -89,6 +95,16 @@ class BlogPage(Page):
8995
index.SearchField("body"),
9096
]
9197

98+
api_fields = [
99+
APIField("introduction"),
100+
APIField("image"),
101+
APIField("body"),
102+
APIField("subtitle"),
103+
APIField("tags"),
104+
APIField("date_published"),
105+
APIField("blog_person_relationship"),
106+
]
107+
92108
def authors(self):
93109
"""
94110
Returns the BlogPage's related people. Again note that we are using
@@ -151,6 +167,11 @@ class BlogIndexPage(RoutablePageMixin, Page):
151167
FieldPanel("image"),
152168
]
153169

170+
api_fields = [
171+
APIField("introduction"),
172+
APIField("image"),
173+
]
174+
154175
# Specifies that only BlogPage objects can live under this index page
155176
subpage_types = ["BlogPage"]
156177

@@ -176,7 +197,6 @@ def get_context(self, request):
176197
@route(r"^tags/$", name="tag_archive")
177198
@route(r"^tags/([\w-]+)/$", name="tag_archive")
178199
def tag_archive(self, request, tag=None):
179-
180200
try:
181201
tag = Tag.objects.get(slug=tag)
182202
except Tag.DoesNotExist:

0 commit comments

Comments
 (0)