Skip to content

Commit e90cc27

Browse files
committed
Updated versions
2 parents b419608 + fade9b1 commit e90cc27

File tree

23 files changed

+604
-122
lines changed

23 files changed

+604
-122
lines changed

.env.example

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
# Careful about the quoting of directives! It is easy to break.
88
# CSP_DEFAULT_SRC="'self'"
9-
10-
# Enable this rule to allow font awesome to load from CDN
11-
# CSP_FONT_SRC="'self', https://cdnjs.cloudflare.com"
9+
# CSP_SCRIPT_SRC="'self', 'report-sample'"
10+
# CSP_STYLE_SRC="'self', 'report-sample'"
11+
# CSP_IMG_SRC="'self', blob:, i.ytimg.com, www.gravatar.com"
12+
# CSP_CONNECT_SRC="'self', releases.wagtail.org"
13+
# CSP_FRAME_SRC="'self', www.youtube.com"

.github/workflows/nightly.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Deploy nightly build
2+
3+
on:
4+
schedule:
5+
- cron: '0 2 * * *' # Run at 2 AM UTC every day
6+
push:
7+
branches:
8+
- main
9+
workflow_dispatch: # Manual trigger
10+
11+
jobs:
12+
deploy-nightly:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
# We intentionally don't set `persist-credentials` to `false` because we
17+
# want to push to the nightly branch. This is safe because we only use
18+
# our own commands and there are no external actions beyond this point.
19+
20+
- name: Configure git
21+
run: |
22+
git config user.name "github-actions[bot]"
23+
git config user.email "github-actions[bot]@users.noreply.github.com"
24+
25+
- name: Update heroku.yml
26+
run: |
27+
sed -i 's/NIGHTLY: 0/NIGHTLY: 1/' heroku.yml
28+
29+
- name: Create and push commit to nightly branch
30+
run: |
31+
TIMESTAMP=$(date -u +"%Y-%m-%d %H:%M:%S UTC")
32+
git checkout -B nightly
33+
git add heroku.yml
34+
git commit -m "deploy: $TIMESTAMP"
35+
git push --force origin nightly

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
FROM python:3.12-slim
2+
ARG NIGHTLY=0
23

34
# Install packages needed to run your application (not build deps):
45
# We need to recreate the /usr/share/man/man{1..8} directories first because
@@ -34,6 +35,11 @@ RUN set -ex \
3435
zlib1g-dev \
3536
" \
3637
&& apt-get update && apt-get install -y --no-install-recommends $BUILD_DEPS \
38+
&& if [ "$NIGHTLY" = "1" ]; then \
39+
NIGHTLY_URL=$(curl -s https://releases.wagtail.org/nightly/latest.json | \
40+
grep -o 'https://[^"]*') \
41+
&& sed -i "s|wagtail>=.*|${NIGHTLY_URL}|" /requirements/base.txt; \
42+
fi \
3743
&& python3.12 -m venv ${VIRTUAL_ENV} \
3844
&& python3.12 -m pip install -U pip \
3945
&& python3.12 -m pip install --no-cache-dir -r /requirements/production.txt \

bakerydemo/base/blocks.py

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from django.utils.functional import cached_property
12
from wagtail.blocks import (
23
CharBlock,
34
ChoiceBlock,
@@ -7,10 +8,11 @@
78
TextBlock,
89
)
910
from wagtail.embeds.blocks import EmbedBlock
11+
from wagtail.images import get_image_model
1012
from wagtail.images.blocks import ImageChooserBlock
1113

1214

13-
class ImageBlock(StructBlock):
15+
class CaptionedImageBlock(StructBlock):
1416
"""
1517
Custom `StructBlock` for utilizing images with associated caption and
1618
attribution data
@@ -20,9 +22,23 @@ class ImageBlock(StructBlock):
2022
caption = CharBlock(required=False)
2123
attribution = CharBlock(required=False)
2224

25+
@cached_property
26+
def preview_image(self):
27+
# Cache the image object for previews to avoid repeated queries
28+
return get_image_model().objects.last()
29+
30+
def get_preview_value(self):
31+
return {
32+
**self.meta.preview_value,
33+
"image": self.preview_image,
34+
"caption": self.preview_image.description,
35+
}
36+
2337
class Meta:
2438
icon = "image"
25-
template = "blocks/image_block.html"
39+
template = "blocks/captioned_image_block.html"
40+
preview_value = {"attribution": "The Wagtail Bakery"}
41+
description = "An image with optional caption and attribution"
2642

2743

2844
class HeadingBlock(StructBlock):
@@ -45,6 +61,8 @@ class HeadingBlock(StructBlock):
4561
class Meta:
4662
icon = "title"
4763
template = "blocks/heading_block.html"
64+
preview_value = {"heading_text": "Healthy bread types", "size": "h2"}
65+
description = "A heading with level two, three, or four"
4866

4967

5068
class BlockQuote(StructBlock):
@@ -58,6 +76,14 @@ class BlockQuote(StructBlock):
5876
class Meta:
5977
icon = "openquote"
6078
template = "blocks/blockquote.html"
79+
preview_value = {
80+
"text": (
81+
"If you read a lot you're well read / "
82+
"If you eat a lot you're well bread."
83+
),
84+
"attribute_name": "Willie Wagtail",
85+
}
86+
description = "A quote with an optional attribution"
6187

6288

6389
# StreamBlocks
@@ -68,12 +94,27 @@ class BaseStreamBlock(StreamBlock):
6894

6995
heading_block = HeadingBlock()
7096
paragraph_block = RichTextBlock(
71-
icon="pilcrow", template="blocks/paragraph_block.html"
97+
icon="pilcrow",
98+
template="blocks/paragraph_block.html",
99+
preview_value=(
100+
"""
101+
<h2>Our bread pledge</h2>
102+
<p>As a bakery, <b>breads</b> have <i>always</i> been in our hearts.
103+
<a href="https://en.wikipedia.org/wiki/Staple_food">Staple foods</a>
104+
are essential for society, and – bread is the tastiest of all.
105+
We love to transform batters and doughs into baked goods with a firm
106+
dry crust and fluffy center.</p>
107+
"""
108+
),
109+
description="A rich text paragraph",
72110
)
73-
image_block = ImageBlock()
111+
image_block = CaptionedImageBlock()
74112
block_quote = BlockQuote()
75113
embed_block = EmbedBlock(
76114
help_text="Insert an embed URL e.g https://www.youtube.com/watch?v=SGJFWirQ3ks",
77115
icon="media",
78116
template="blocks/embed_block.html",
117+
preview_template="base/preview/static_embed_block.html",
118+
preview_value="https://www.youtube.com/watch?v=mwrGSfiB1Mg",
119+
description="An embedded video or other media",
79120
)

bakerydemo/base/fixtures/bakerydemo.json

Lines changed: 186 additions & 68 deletions
Large diffs are not rendered by default.
66 KB
Loading

bakerydemo/base/management/commands/reset_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def handle(self, **options):
1717
)
1818

1919
# 1. (optional) Remove all objects from S3
20-
if "s3" in settings.DEFAULT_FILE_STORAGE:
20+
if "s3" in default_storage.__class__.__name__.lower():
2121
self.stdout.write("Removing files from S3")
2222
default_storage.bucket.objects.all().delete()
2323
else:

bakerydemo/base/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
PublishingPanel,
1313
)
1414
from wagtail.contrib.forms.models import AbstractEmailForm, AbstractFormField
15+
from wagtail.contrib.forms.panels import FormSubmissionsPanel
1516
from wagtail.contrib.settings.models import (
1617
BaseGenericSetting,
1718
BaseSiteSetting,
@@ -463,6 +464,7 @@ class FormPage(AbstractEmailForm):
463464
# Note how we include the FormField object via an InlinePanel using the
464465
# related_name value
465466
content_panels = AbstractEmailForm.content_panels + [
467+
FormSubmissionsPanel(),
466468
FieldPanel("image"),
467469
FieldPanel("body"),
468470
InlinePanel("form_fields", heading="Form fields", label="Field"),

bakerydemo/base/templatetags/navigation_tags.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from bakerydemo.base.models import FooterText
55

66
register = template.Library()
7-
# https://docs.djangoproject.com/en/3.2/howto/custom-template-tags/
7+
# https://docs.djangoproject.com/en/stable/howto/custom-template-tags/
88

99

1010
@register.simple_tag(takes_context=True)

bakerydemo/recipes/blocks.py

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
from wagtail.contrib.table_block.blocks import TableBlock
1212
from wagtail.contrib.typed_table_block.blocks import TypedTableBlock
1313
from wagtail.embeds.blocks import EmbedBlock
14-
from wagtail.images.blocks import ImageChooserBlock
14+
from wagtail.images.blocks import ImageBlock
1515

16-
from bakerydemo.base.blocks import BlockQuote, HeadingBlock, ImageBlock
16+
from bakerydemo.base.blocks import BlockQuote, HeadingBlock
1717

1818

1919
class RecipeStepBlock(StructBlock):
@@ -39,15 +39,69 @@ class RecipeStreamBlock(StreamBlock):
3939
icon="pilcrow", template="blocks/paragraph_block.html", group="Content"
4040
)
4141
block_quote = BlockQuote(group="Content")
42-
table_block = TableBlock(group="Content")
42+
table_block = TableBlock(
43+
group="Content",
44+
description="A table of data with plain text cells",
45+
preview_value={
46+
"first_row_is_table_header": "True",
47+
"data": [
48+
["Bread type", "Origin"],
49+
["Anpan", "Japan"],
50+
["Crumpet", "United Kingdom"],
51+
["Roti buaya", "Indonesia"],
52+
],
53+
},
54+
)
4355
typed_table_block = TypedTableBlock(
4456
[
4557
("text", CharBlock()),
4658
("numeric", FloatBlock()),
4759
("rich_text", RichTextBlock()),
48-
("image", ImageChooserBlock()),
60+
("image", ImageBlock()),
4961
],
5062
group="Content",
63+
description=(
64+
"A table of data with cells that can include "
65+
"text, numbers, rich text, and images"
66+
),
67+
preview_value={
68+
"caption": "Nutritional information for 100g of bread",
69+
"columns": [
70+
{"type": "rich_text", "heading": "Nutrient"},
71+
{"type": "numeric", "heading": "White bread"},
72+
{"type": "numeric", "heading": "Brown bread"},
73+
{"type": "numeric", "heading": "Wholemeal bread"},
74+
],
75+
"rows": [
76+
{
77+
"values": [
78+
'<p><a href="https://en.wikipedia.org/wiki/Protein">'
79+
"Protein</a> <b>(g)</b></p>",
80+
7.9,
81+
7.9,
82+
9.4,
83+
]
84+
},
85+
{
86+
"values": [
87+
'<p><a href="https://en.wikipedia.org/wiki/Carbohydrate">'
88+
"Carbohydrate</a> <b>(g)</b></p>",
89+
46.1,
90+
42.1,
91+
42,
92+
]
93+
},
94+
{
95+
"values": [
96+
'<p><a href="https://en.wikipedia.org/wiki/Sugar">'
97+
"Total sugars</a> <b>(g)</b></p>",
98+
3.4,
99+
3.4,
100+
2.8,
101+
]
102+
},
103+
],
104+
},
51105
)
52106

53107
image_block = ImageBlock(group="Media")
@@ -56,6 +110,8 @@ class RecipeStreamBlock(StreamBlock):
56110
icon="media",
57111
template="blocks/embed_block.html",
58112
group="Media",
113+
preview_value="https://www.youtube.com/watch?v=mwrGSfiB1Mg",
114+
description="An embedded video or other media",
59115
)
60116

61117
ingredients_list = ListBlock(
@@ -64,11 +120,25 @@ class RecipeStreamBlock(StreamBlock):
64120
max_num=10,
65121
icon="list-ol",
66122
group="Cooking",
123+
preview_value=["<p>200g flour</p>", "<p>1 egg</p>", "<p>1 cup of sugar</p>"],
124+
description=(
125+
"A list of ingredients to use in the recipe "
126+
"with optional bold, italic, and link options"
127+
),
67128
)
68129
steps_list = ListBlock(
69130
RecipeStepBlock(),
70131
min_num=2,
71132
max_num=10,
72133
icon="tasks",
73134
group="Cooking",
135+
preview_value=[
136+
{"text": "<p>An easy step</p>", "difficulty": "S"},
137+
{"text": "<p>A difficult step</p>", "difficulty": "L"},
138+
{"text": "<p>A medium step</p>", "difficulty": "M"},
139+
],
140+
description=(
141+
"A list of steps to follow in the recipe, "
142+
"with a difficulty rating for each step"
143+
),
74144
)

0 commit comments

Comments
 (0)