make a common stream field, support all block types everywhere

This commit is contained in:
2024-05-20 22:42:30 +02:00
parent e88aa5e142
commit a7e83a3163
11 changed files with 117 additions and 61 deletions

View File

@ -0,0 +1,26 @@
# Generated by Django 5.0.6 on 2024-05-20 20:08
import wagtail.blocks
import wagtail.fields
import wagtail.images.blocks
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('associations', '0008_alter_associationpage_excerpt'),
]
operations = [
migrations.AlterField(
model_name='associationindex',
name='body',
field=wagtail.fields.StreamField([('paragraph', wagtail.blocks.RichTextBlock(label='Rik tekst')), ('image', wagtail.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock(label='Bilde')), ('image_format', wagtail.blocks.ChoiceBlock(choices=[('fullwidth', 'Fullbredde'), ('bleed', 'Utfallende'), ('original', 'Uendret størrelse')], icon='cup', label='Bildeformat')), ('text', wagtail.blocks.CharBlock(label='Tekst', max_length=512, required=False))], label='Bilde')), ('image_slider', wagtail.blocks.StructBlock([('images', wagtail.blocks.ListBlock(wagtail.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock(label='Bilde')), ('text', wagtail.blocks.CharBlock(label='Tekst', max_length=512, required=False))]), label='Bilder', min_num=1))], label='Bildegalleri'))], default=[('paragraph', '')]),
),
migrations.AlterField(
model_name='associationpage',
name='body',
field=wagtail.fields.StreamField([('paragraph', wagtail.blocks.RichTextBlock(label='Rik tekst')), ('image', wagtail.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock(label='Bilde')), ('image_format', wagtail.blocks.ChoiceBlock(choices=[('fullwidth', 'Fullbredde'), ('bleed', 'Utfallende'), ('original', 'Uendret størrelse')], icon='cup', label='Bildeformat')), ('text', wagtail.blocks.CharBlock(label='Tekst', max_length=512, required=False))], label='Bilde')), ('image_slider', wagtail.blocks.StructBlock([('images', wagtail.blocks.ListBlock(wagtail.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock(label='Bilde')), ('text', wagtail.blocks.CharBlock(label='Tekst', max_length=512, required=False))]), label='Bilder', min_num=1))], label='Bildegalleri'))], default=[('paragraph', '')]),
),
]

View File

@ -5,11 +5,12 @@ from grapple.models import (
GraphQLStreamfield, GraphQLStreamfield,
GraphQLString, GraphQLString,
) )
from wagtail import blocks
from wagtail.admin.panels import FieldPanel from wagtail.admin.panels import FieldPanel
from wagtail.fields import RichTextField, StreamField from wagtail.fields import RichTextField
from wagtail.models import Page from wagtail.models import Page
from dnscms.fields import CommonStreamField
class AssociationIndex(Page): class AssociationIndex(Page):
max_count = 1 max_count = 1
@ -17,11 +18,7 @@ class AssociationIndex(Page):
lead = RichTextField(features=["bold", "italic", "link"]) lead = RichTextField(features=["bold", "italic", "link"])
body = StreamField( body = CommonStreamField
[
("paragraph", blocks.RichTextBlock()),
]
)
content_panels = Page.content_panels + [ content_panels = Page.content_panels + [
FieldPanel("lead", heading="Leder"), FieldPanel("lead", heading="Leder"),
@ -44,11 +41,7 @@ class AssociationPage(Page):
UTVALG = "utvalg", "Utvalg" UTVALG = "utvalg", "Utvalg"
excerpt = models.TextField(max_length=512, blank=False) excerpt = models.TextField(max_length=512, blank=False)
body = StreamField( body = CommonStreamField
[
("paragraph", blocks.RichTextBlock()),
]
)
association_type = models.CharField( association_type = models.CharField(
max_length=64, choices=AssociationType, default=AssociationType.FORENING max_length=64, choices=AssociationType, default=AssociationType.FORENING
) )

13
dnscms/dnscms/fields.py Normal file
View File

@ -0,0 +1,13 @@
from wagtail import blocks
from wagtail.fields import StreamField
from dnscms.blocks import ImageSliderBlock, ImageWithTextBlock
CommonStreamField = StreamField(
[
("paragraph", blocks.RichTextBlock(label="Rik tekst")),
("image", ImageWithTextBlock(label="Bilde")),
("image_slider", ImageSliderBlock(label="Bildegalleri")),
],
default=[("paragraph", "")],
)

View File

@ -0,0 +1,21 @@
# Generated by Django 5.0.6 on 2024-05-20 20:08
import wagtail.blocks
import wagtail.fields
import wagtail.images.blocks
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('events', '0026_alter_eventpage_featured_image'),
]
operations = [
migrations.AlterField(
model_name='eventpage',
name='body',
field=wagtail.fields.StreamField([('paragraph', wagtail.blocks.RichTextBlock(label='Rik tekst')), ('image', wagtail.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock(label='Bilde')), ('image_format', wagtail.blocks.ChoiceBlock(choices=[('fullwidth', 'Fullbredde'), ('bleed', 'Utfallende'), ('original', 'Uendret størrelse')], icon='cup', label='Bildeformat')), ('text', wagtail.blocks.CharBlock(label='Tekst', max_length=512, required=False))], label='Bilde')), ('image_slider', wagtail.blocks.StructBlock([('images', wagtail.blocks.ListBlock(wagtail.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock(label='Bilde')), ('text', wagtail.blocks.CharBlock(label='Tekst', max_length=512, required=False))]), label='Bilder', min_num=1))], label='Bildegalleri'))], default=[('paragraph', '')]),
),
]

View File

@ -15,7 +15,6 @@ from grapple.models import (
) )
from modelcluster.fields import ParentalKey, ParentalManyToManyField from modelcluster.fields import ParentalKey, ParentalManyToManyField
from modelcluster.models import ClusterableModel from modelcluster.models import ClusterableModel
from wagtail import blocks
from wagtail.admin.panels import ( from wagtail.admin.panels import (
FieldPanel, FieldPanel,
FieldRowPanel, FieldRowPanel,
@ -25,11 +24,10 @@ from wagtail.admin.panels import (
PageChooserPanel, PageChooserPanel,
TitleFieldPanel, TitleFieldPanel,
) )
from wagtail.fields import StreamField
from wagtail.images.blocks import ImageChooserBlock
from wagtail.models import Orderable, Page, PageManager, PageQuerySet from wagtail.models import Orderable, Page, PageManager, PageQuerySet
from wagtail.snippets.models import register_snippet from wagtail.snippets.models import register_snippet
from dnscms.fields import CommonStreamField
from venues.models import VenuePage from venues.models import VenuePage
@ -154,12 +152,7 @@ class EventPage(Page):
), ),
) )
body = StreamField( body = CommonStreamField
[
("paragraph", blocks.RichTextBlock()),
("image", ImageChooserBlock()),
]
)
categories = ParentalManyToManyField( categories = ParentalManyToManyField(
"events.EventCategory", "events.EventCategory",

View File

@ -0,0 +1,21 @@
# Generated by Django 5.0.6 on 2024-05-20 20:08
import wagtail.blocks
import wagtail.fields
import wagtail.images.blocks
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('generic', '0004_alter_genericpage_body'),
]
operations = [
migrations.AlterField(
model_name='genericpage',
name='body',
field=wagtail.fields.StreamField([('paragraph', wagtail.blocks.RichTextBlock(label='Rik tekst')), ('image', wagtail.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock(label='Bilde')), ('image_format', wagtail.blocks.ChoiceBlock(choices=[('fullwidth', 'Fullbredde'), ('bleed', 'Utfallende'), ('original', 'Uendret størrelse')], icon='cup', label='Bildeformat')), ('text', wagtail.blocks.CharBlock(label='Tekst', max_length=512, required=False))], label='Bilde')), ('image_slider', wagtail.blocks.StructBlock([('images', wagtail.blocks.ListBlock(wagtail.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock(label='Bilde')), ('text', wagtail.blocks.CharBlock(label='Tekst', max_length=512, required=False))]), label='Bilder', min_num=1))], label='Bildegalleri'))], default=[('paragraph', '')]),
),
]

View File

@ -1,23 +1,15 @@
from grapple.models import GraphQLStreamfield from grapple.models import GraphQLStreamfield
from wagtail import blocks
from wagtail.admin.panels import FieldPanel from wagtail.admin.panels import FieldPanel
from wagtail.fields import StreamField
from wagtail.models import Page from wagtail.models import Page
from dnscms.blocks import ImageSliderBlock, ImageWithTextBlock from dnscms.fields import CommonStreamField
class GenericPage(Page): class GenericPage(Page):
subpage_types = ["generic.GenericPage"] subpage_types = ["generic.GenericPage"]
show_in_menus = True show_in_menus = True
body = StreamField( body = CommonStreamField
[
("paragraph", blocks.RichTextBlock(label="Rik tekst")),
("image", ImageWithTextBlock(label="Bilde")),
("image_slider", ImageSliderBlock(label="Bildegalleri")),
]
)
content_panels = Page.content_panels + [ content_panels = Page.content_panels + [
FieldPanel("body", heading="Innhold"), FieldPanel("body", heading="Innhold"),

View File

@ -0,0 +1,21 @@
# Generated by Django 5.0.6 on 2024-05-20 20:08
import wagtail.blocks
import wagtail.fields
import wagtail.images.blocks
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('venues', '0003_alter_venuepage_featured_image'),
]
operations = [
migrations.AlterField(
model_name='venuepage',
name='body',
field=wagtail.fields.StreamField([('paragraph', wagtail.blocks.RichTextBlock(label='Rik tekst')), ('image', wagtail.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock(label='Bilde')), ('image_format', wagtail.blocks.ChoiceBlock(choices=[('fullwidth', 'Fullbredde'), ('bleed', 'Utfallende'), ('original', 'Uendret størrelse')], icon='cup', label='Bildeformat')), ('text', wagtail.blocks.CharBlock(label='Tekst', max_length=512, required=False))], label='Bilde')), ('image_slider', wagtail.blocks.StructBlock([('images', wagtail.blocks.ListBlock(wagtail.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock(label='Bilde')), ('text', wagtail.blocks.CharBlock(label='Tekst', max_length=512, required=False))]), label='Bilder', min_num=1))], label='Bildegalleri'))], default=[('paragraph', '')]),
),
]

View File

@ -1,11 +1,10 @@
from django.db import models from django.db import models
from grapple.models import GraphQLBoolean, GraphQLImage, GraphQLStreamfield, GraphQLString from grapple.models import GraphQLBoolean, GraphQLImage, GraphQLStreamfield, GraphQLString
from wagtail import blocks
from wagtail.admin.panels import FieldPanel, FieldRowPanel, MultiFieldPanel from wagtail.admin.panels import FieldPanel, FieldRowPanel, MultiFieldPanel
from wagtail.fields import StreamField
from wagtail.images.blocks import ImageChooserBlock
from wagtail.models import Page from wagtail.models import Page
from dnscms.fields import CommonStreamField
class VenueIndex(Page): class VenueIndex(Page):
# there can only be one venue index page # there can only be one venue index page
@ -30,12 +29,7 @@ class VenuePage(Page):
help_text=("Bilde av lokalet"), help_text=("Bilde av lokalet"),
) )
body = StreamField( body = CommonStreamField
[
("paragraph", blocks.RichTextBlock()),
("image", ImageChooserBlock()),
]
)
show_as_bookable = models.BooleanField( show_as_bookable = models.BooleanField(
default=True, help_text="Skal lokalet dukke i oversikten over lokaler som leies ut?" default=True, help_text="Skal lokalet dukke i oversikten over lokaler som leies ut?"

View File

@ -12,13 +12,7 @@ const AssociationIndexDefinition = graphql(`
title title
lead lead
body { body {
id ...Blocks
blockType
field
... on RichTextBlock {
rawValue
value
}
} }
} }
} }
@ -32,13 +26,7 @@ const AssociationFragmentDefinition = graphql(`
title title
excerpt excerpt
body { body {
id ...Blocks
blockType
field
... on RichTextBlock {
rawValue
value
}
} }
logo { logo {
url url

View File

@ -12,13 +12,7 @@ const VenueFragmentDefinition = graphql(`
slug slug
title title
body { body {
id ...Blocks
blockType
field
... on RichTextBlock {
rawValue
value
}
} }
featuredImage { featuredImage {
...Image ...Image