diff --git a/dnscms/associations/migrations/0009_alter_associationindex_body_and_more.py b/dnscms/associations/migrations/0009_alter_associationindex_body_and_more.py new file mode 100644 index 0000000..d890bef --- /dev/null +++ b/dnscms/associations/migrations/0009_alter_associationindex_body_and_more.py @@ -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', '')]), + ), + ] diff --git a/dnscms/associations/models.py b/dnscms/associations/models.py index 03f7e07..2eaa699 100644 --- a/dnscms/associations/models.py +++ b/dnscms/associations/models.py @@ -5,11 +5,12 @@ from grapple.models import ( GraphQLStreamfield, GraphQLString, ) -from wagtail import blocks from wagtail.admin.panels import FieldPanel -from wagtail.fields import RichTextField, StreamField +from wagtail.fields import RichTextField from wagtail.models import Page +from dnscms.fields import CommonStreamField + class AssociationIndex(Page): max_count = 1 @@ -17,11 +18,7 @@ class AssociationIndex(Page): lead = RichTextField(features=["bold", "italic", "link"]) - body = StreamField( - [ - ("paragraph", blocks.RichTextBlock()), - ] - ) + body = CommonStreamField content_panels = Page.content_panels + [ FieldPanel("lead", heading="Leder"), @@ -44,11 +41,7 @@ class AssociationPage(Page): UTVALG = "utvalg", "Utvalg" excerpt = models.TextField(max_length=512, blank=False) - body = StreamField( - [ - ("paragraph", blocks.RichTextBlock()), - ] - ) + body = CommonStreamField association_type = models.CharField( max_length=64, choices=AssociationType, default=AssociationType.FORENING ) diff --git a/dnscms/dnscms/fields.py b/dnscms/dnscms/fields.py new file mode 100644 index 0000000..a8e72ba --- /dev/null +++ b/dnscms/dnscms/fields.py @@ -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", "")], +) diff --git a/dnscms/events/migrations/0027_alter_eventpage_body.py b/dnscms/events/migrations/0027_alter_eventpage_body.py new file mode 100644 index 0000000..a9edb28 --- /dev/null +++ b/dnscms/events/migrations/0027_alter_eventpage_body.py @@ -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', '')]), + ), + ] diff --git a/dnscms/events/models.py b/dnscms/events/models.py index 43ebb59..110ea88 100644 --- a/dnscms/events/models.py +++ b/dnscms/events/models.py @@ -15,7 +15,6 @@ from grapple.models import ( ) from modelcluster.fields import ParentalKey, ParentalManyToManyField from modelcluster.models import ClusterableModel -from wagtail import blocks from wagtail.admin.panels import ( FieldPanel, FieldRowPanel, @@ -25,11 +24,10 @@ from wagtail.admin.panels import ( PageChooserPanel, TitleFieldPanel, ) -from wagtail.fields import StreamField -from wagtail.images.blocks import ImageChooserBlock from wagtail.models import Orderable, Page, PageManager, PageQuerySet from wagtail.snippets.models import register_snippet +from dnscms.fields import CommonStreamField from venues.models import VenuePage @@ -154,12 +152,7 @@ class EventPage(Page): ), ) - body = StreamField( - [ - ("paragraph", blocks.RichTextBlock()), - ("image", ImageChooserBlock()), - ] - ) + body = CommonStreamField categories = ParentalManyToManyField( "events.EventCategory", diff --git a/dnscms/generic/migrations/0005_alter_genericpage_body.py b/dnscms/generic/migrations/0005_alter_genericpage_body.py new file mode 100644 index 0000000..c8f3b82 --- /dev/null +++ b/dnscms/generic/migrations/0005_alter_genericpage_body.py @@ -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', '')]), + ), + ] diff --git a/dnscms/generic/models.py b/dnscms/generic/models.py index f2ff63f..87263b6 100644 --- a/dnscms/generic/models.py +++ b/dnscms/generic/models.py @@ -1,23 +1,15 @@ from grapple.models import GraphQLStreamfield -from wagtail import blocks from wagtail.admin.panels import FieldPanel -from wagtail.fields import StreamField from wagtail.models import Page -from dnscms.blocks import ImageSliderBlock, ImageWithTextBlock +from dnscms.fields import CommonStreamField class GenericPage(Page): subpage_types = ["generic.GenericPage"] show_in_menus = True - body = StreamField( - [ - ("paragraph", blocks.RichTextBlock(label="Rik tekst")), - ("image", ImageWithTextBlock(label="Bilde")), - ("image_slider", ImageSliderBlock(label="Bildegalleri")), - ] - ) + body = CommonStreamField content_panels = Page.content_panels + [ FieldPanel("body", heading="Innhold"), diff --git a/dnscms/venues/migrations/0004_alter_venuepage_body.py b/dnscms/venues/migrations/0004_alter_venuepage_body.py new file mode 100644 index 0000000..4b6308d --- /dev/null +++ b/dnscms/venues/migrations/0004_alter_venuepage_body.py @@ -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', '')]), + ), + ] diff --git a/dnscms/venues/models.py b/dnscms/venues/models.py index b5e443d..643cf1f 100644 --- a/dnscms/venues/models.py +++ b/dnscms/venues/models.py @@ -1,11 +1,10 @@ from django.db import models from grapple.models import GraphQLBoolean, GraphQLImage, GraphQLStreamfield, GraphQLString -from wagtail import blocks 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 dnscms.fields import CommonStreamField + class VenueIndex(Page): # there can only be one venue index page @@ -30,12 +29,7 @@ class VenuePage(Page): help_text=("Bilde av lokalet"), ) - body = StreamField( - [ - ("paragraph", blocks.RichTextBlock()), - ("image", ImageChooserBlock()), - ] - ) + body = CommonStreamField show_as_bookable = models.BooleanField( default=True, help_text="Skal lokalet dukke i oversikten over lokaler som leies ut?" diff --git a/web/src/app/foreninger/page.tsx b/web/src/app/foreninger/page.tsx index 86be158..9efb85f 100644 --- a/web/src/app/foreninger/page.tsx +++ b/web/src/app/foreninger/page.tsx @@ -12,13 +12,7 @@ const AssociationIndexDefinition = graphql(` title lead body { - id - blockType - field - ... on RichTextBlock { - rawValue - value - } + ...Blocks } } } @@ -32,13 +26,7 @@ const AssociationFragmentDefinition = graphql(` title excerpt body { - id - blockType - field - ... on RichTextBlock { - rawValue - value - } + ...Blocks } logo { url diff --git a/web/src/app/lokaler/page.tsx b/web/src/app/lokaler/page.tsx index 11c253d..eb857d2 100644 --- a/web/src/app/lokaler/page.tsx +++ b/web/src/app/lokaler/page.tsx @@ -12,13 +12,7 @@ const VenueFragmentDefinition = graphql(` slug title body { - id - blockType - field - ... on RichTextBlock { - rawValue - value - } + ...Blocks } featuredImage { ...Image