Add a special page to demo various panels with streamfields

wagtail-9232-example
Coen van der Kamp 2022-11-17 16:26:32 +01:00
rodzic 77d55ac019
commit 0a845413b2
7 zmienionych plików z 548 dodań i 0 usunięć

Wyświetl plik

@ -39,6 +39,7 @@ INSTALLED_APPS = [
"bakerydemo.blog",
"bakerydemo.breads",
"bakerydemo.locations",
"bakerydemo.specials",
"bakerydemo.search",
"wagtail.contrib.search_promotions",
"wagtail.contrib.forms",
@ -53,6 +54,7 @@ INSTALLED_APPS = [
"wagtail.admin",
"wagtail.api.v2",
"wagtail.locales",
"wagtail.contrib.typed_table_block",
"wagtail.contrib.modeladmin",
"wagtail.contrib.routable_page",
"wagtail.contrib.simple_translation",

Wyświetl plik

@ -0,0 +1,54 @@
from wagtail.contrib.typed_table_block.blocks import TypedTableBlock
from wagtail.core.blocks import (
CharBlock,
ChoiceBlock,
FloatBlock,
ListBlock,
PageChooserBlock,
RichTextBlock,
StreamBlock,
StructBlock,
TextBlock,
URLBlock,
)
from wagtail.documents.blocks import DocumentChooserBlock
from wagtail.embeds.blocks import EmbedBlock
from wagtail.images.blocks import ImageChooserBlock
class SpecialTableBlock(StructBlock):
title = CharBlock()
description = TextBlock()
table = TypedTableBlock(
[
("text", CharBlock()),
("numeric", FloatBlock()),
("rich_text", RichTextBlock()),
("image", ImageChooserBlock()),
]
)
class SpecialStreamBlock(StreamBlock):
page = PageChooserBlock()
embed = EmbedBlock()
image = ImageChooserBlock()
BLOCKS = [
("char", CharBlock()),
(
"choice",
ChoiceBlock(choices=[("M", "Medium"), ("L", "Large"), ("XL", "Extra large")]),
),
("list", ListBlock(child_block=CharBlock())),
("page", PageChooserBlock()),
("text", TextBlock()),
("rich_text", RichTextBlock()),
("url", URLBlock()),
("document", DocumentChooserBlock()),
("embed", EmbedBlock()),
("image", ImageChooserBlock()),
("table", SpecialTableBlock()),
("stream", SpecialStreamBlock()),
]

Wyświetl plik

@ -0,0 +1,405 @@
# Generated by Django 4.0.8 on 2022-11-17 15:14
from django.db import migrations, models
import django.db.models.deletion
import modelcluster.fields
import wagtail.blocks
import wagtail.contrib.typed_table_block.blocks
import wagtail.documents.blocks
import wagtail.embeds.blocks
import wagtail.fields
import wagtail.images.blocks
class Migration(migrations.Migration):
initial = True
dependencies = [
("wagtailcore", "0078_referenceindex"),
]
operations = [
migrations.CreateModel(
name="SpecialPage",
fields=[
(
"page_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="wagtailcore.page",
),
),
("title_1", models.CharField(default="Title 1", max_length=255)),
(
"section_1",
wagtail.fields.StreamField(
[
("char", wagtail.blocks.CharBlock()),
(
"choice",
wagtail.blocks.ChoiceBlock(
choices=[
("M", "Medium"),
("L", "Large"),
("XL", "Extra large"),
]
),
),
(
"list",
wagtail.blocks.ListBlock(
child_block=wagtail.blocks.CharBlock()
),
),
("page", wagtail.blocks.PageChooserBlock()),
("text", wagtail.blocks.TextBlock()),
("rich_text", wagtail.blocks.RichTextBlock()),
("url", wagtail.blocks.URLBlock()),
(
"document",
wagtail.documents.blocks.DocumentChooserBlock(),
),
("embed", wagtail.embeds.blocks.EmbedBlock()),
("image", wagtail.images.blocks.ImageChooserBlock()),
(
"table",
wagtail.blocks.StructBlock(
[
("title", wagtail.blocks.CharBlock()),
("description", wagtail.blocks.TextBlock()),
(
"table",
wagtail.contrib.typed_table_block.blocks.TypedTableBlock(
[
(
"text",
wagtail.blocks.CharBlock(),
),
(
"numeric",
wagtail.blocks.FloatBlock(),
),
(
"rich_text",
wagtail.blocks.RichTextBlock(),
),
(
"image",
wagtail.images.blocks.ImageChooserBlock(),
),
]
),
),
]
),
),
(
"stream",
wagtail.blocks.StreamBlock(
[
("page", wagtail.blocks.PageChooserBlock()),
("embed", wagtail.embeds.blocks.EmbedBlock()),
(
"image",
wagtail.images.blocks.ImageChooserBlock(),
),
]
),
),
],
blank=True,
help_text="Section 1 is a StreamField in a regular FieldPanel",
use_json_field=True,
),
),
("title_2", models.CharField(default="Title 2", max_length=255)),
(
"section_2",
wagtail.fields.StreamField(
[
("char", wagtail.blocks.CharBlock()),
(
"choice",
wagtail.blocks.ChoiceBlock(
choices=[
("M", "Medium"),
("L", "Large"),
("XL", "Extra large"),
]
),
),
(
"list",
wagtail.blocks.ListBlock(
child_block=wagtail.blocks.CharBlock()
),
),
("page", wagtail.blocks.PageChooserBlock()),
("text", wagtail.blocks.TextBlock()),
("rich_text", wagtail.blocks.RichTextBlock()),
("url", wagtail.blocks.URLBlock()),
(
"document",
wagtail.documents.blocks.DocumentChooserBlock(),
),
("embed", wagtail.embeds.blocks.EmbedBlock()),
("image", wagtail.images.blocks.ImageChooserBlock()),
(
"table",
wagtail.blocks.StructBlock(
[
("title", wagtail.blocks.CharBlock()),
("description", wagtail.blocks.TextBlock()),
(
"table",
wagtail.contrib.typed_table_block.blocks.TypedTableBlock(
[
(
"text",
wagtail.blocks.CharBlock(),
),
(
"numeric",
wagtail.blocks.FloatBlock(),
),
(
"rich_text",
wagtail.blocks.RichTextBlock(),
),
(
"image",
wagtail.images.blocks.ImageChooserBlock(),
),
]
),
),
]
),
),
(
"stream",
wagtail.blocks.StreamBlock(
[
("page", wagtail.blocks.PageChooserBlock()),
("embed", wagtail.embeds.blocks.EmbedBlock()),
(
"image",
wagtail.images.blocks.ImageChooserBlock(),
),
]
),
),
],
blank=True,
help_text="Section 2 is a StreamField in a MultiFieldPanel",
use_json_field=True,
),
),
],
options={
"abstract": False,
},
bases=("wagtailcore.page",),
),
migrations.CreateModel(
name="Item",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"sort_order",
models.IntegerField(blank=True, editable=False, null=True),
),
("title_1", models.CharField(default="Title 1", max_length=255)),
(
"section_1",
wagtail.fields.StreamField(
[
("char", wagtail.blocks.CharBlock()),
(
"choice",
wagtail.blocks.ChoiceBlock(
choices=[
("M", "Medium"),
("L", "Large"),
("XL", "Extra large"),
]
),
),
(
"list",
wagtail.blocks.ListBlock(
child_block=wagtail.blocks.CharBlock()
),
),
("page", wagtail.blocks.PageChooserBlock()),
("text", wagtail.blocks.TextBlock()),
("rich_text", wagtail.blocks.RichTextBlock()),
("url", wagtail.blocks.URLBlock()),
(
"document",
wagtail.documents.blocks.DocumentChooserBlock(),
),
("embed", wagtail.embeds.blocks.EmbedBlock()),
("image", wagtail.images.blocks.ImageChooserBlock()),
(
"table",
wagtail.blocks.StructBlock(
[
("title", wagtail.blocks.CharBlock()),
("description", wagtail.blocks.TextBlock()),
(
"table",
wagtail.contrib.typed_table_block.blocks.TypedTableBlock(
[
(
"text",
wagtail.blocks.CharBlock(),
),
(
"numeric",
wagtail.blocks.FloatBlock(),
),
(
"rich_text",
wagtail.blocks.RichTextBlock(),
),
(
"image",
wagtail.images.blocks.ImageChooserBlock(),
),
]
),
),
]
),
),
(
"stream",
wagtail.blocks.StreamBlock(
[
("page", wagtail.blocks.PageChooserBlock()),
("embed", wagtail.embeds.blocks.EmbedBlock()),
(
"image",
wagtail.images.blocks.ImageChooserBlock(),
),
]
),
),
],
blank=True,
help_text="Section 1 is a StreamField in a regular FieldPanel",
use_json_field=True,
),
),
("title_2", models.CharField(default="Title 2", max_length=255)),
(
"section_2",
wagtail.fields.StreamField(
[
("char", wagtail.blocks.CharBlock()),
(
"choice",
wagtail.blocks.ChoiceBlock(
choices=[
("M", "Medium"),
("L", "Large"),
("XL", "Extra large"),
]
),
),
(
"list",
wagtail.blocks.ListBlock(
child_block=wagtail.blocks.CharBlock()
),
),
("page", wagtail.blocks.PageChooserBlock()),
("text", wagtail.blocks.TextBlock()),
("rich_text", wagtail.blocks.RichTextBlock()),
("url", wagtail.blocks.URLBlock()),
(
"document",
wagtail.documents.blocks.DocumentChooserBlock(),
),
("embed", wagtail.embeds.blocks.EmbedBlock()),
("image", wagtail.images.blocks.ImageChooserBlock()),
(
"table",
wagtail.blocks.StructBlock(
[
("title", wagtail.blocks.CharBlock()),
("description", wagtail.blocks.TextBlock()),
(
"table",
wagtail.contrib.typed_table_block.blocks.TypedTableBlock(
[
(
"text",
wagtail.blocks.CharBlock(),
),
(
"numeric",
wagtail.blocks.FloatBlock(),
),
(
"rich_text",
wagtail.blocks.RichTextBlock(),
),
(
"image",
wagtail.images.blocks.ImageChooserBlock(),
),
]
),
),
]
),
),
(
"stream",
wagtail.blocks.StreamBlock(
[
("page", wagtail.blocks.PageChooserBlock()),
("embed", wagtail.embeds.blocks.EmbedBlock()),
(
"image",
wagtail.images.blocks.ImageChooserBlock(),
),
]
),
),
],
blank=True,
help_text="Section 2 is a StreamField in a MultiFieldPanel",
use_json_field=True,
),
),
(
"page",
modelcluster.fields.ParentalKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="items",
to="specials.specialpage",
),
),
],
options={
"ordering": ["sort_order"],
"abstract": False,
},
),
]

Wyświetl plik

@ -0,0 +1,73 @@
from django.db import models
from modelcluster.fields import ParentalKey
from wagtail.admin.panels import FieldPanel, InlinePanel, MultiFieldPanel
from wagtail.fields import StreamField
from wagtail.models import Orderable, Page
from .blocks import BLOCKS
class SpecialPage(Page):
"""
SpecialPage, to illustrate some special Wagtail scenario's
"""
title_1 = models.CharField(max_length=255, default="Title 1")
section_1 = StreamField(
BLOCKS,
blank=True,
use_json_field=True,
help_text="Section 1 is a StreamField in a regular FieldPanel",
)
title_2 = models.CharField(max_length=255, default="Title 2")
section_2 = StreamField(
BLOCKS,
blank=True,
use_json_field=True,
help_text="Section 2 is a StreamField in a MultiFieldPanel",
)
content_panels = Page.content_panels + [
FieldPanel("title_1"),
FieldPanel("section_1"),
MultiFieldPanel(
[
FieldPanel("title_2"),
FieldPanel("section_2"),
],
heading="MultiFieldPanel for section 2",
),
InlinePanel(
"items", label="Items", help_text="Related items via an inline panel"
),
]
class Item(Orderable):
page = ParentalKey(SpecialPage, on_delete=models.CASCADE, related_name="items")
title_1 = models.CharField(max_length=255, default="Title 1")
section_1 = StreamField(
BLOCKS,
blank=True,
use_json_field=True,
help_text="Section 1 is a StreamField in a regular FieldPanel",
)
title_2 = models.CharField(max_length=255, default="Title 2")
section_2 = StreamField(
BLOCKS,
blank=True,
use_json_field=True,
help_text="Section 2 is a StreamField in a MultiFieldPanel",
)
panels = [
FieldPanel("title_1"),
FieldPanel("section_1"),
MultiFieldPanel(
[
FieldPanel("title_2"),
FieldPanel("section_2"),
],
heading="MultiFieldPanel for section 2",
),
]

Wyświetl plik

@ -0,0 +1,14 @@
{% extends "base.html" %}
{% block content %}
{% include "base/include/header-hero.html" %}
<div class="container bread-detail">
<div class="row">
<div class="col-md-12">
<p>Special page is about admin capabilities and does not render content.</p>
</div>
</div>
</div>
{% endblock content %}