add image-and-text and image slider block types

This commit is contained in:
2024-05-15 06:33:14 +02:00
parent 71b0a87180
commit ba28578a0c
18 changed files with 453 additions and 47 deletions

70
dnscms/dnscms/blocks.py Normal file
View File

@@ -0,0 +1,70 @@
from grapple.helpers import register_streamfield_block
from grapple.models import (
GraphQLImage,
GraphQLStreamfield,
GraphQLString,
)
from wagtail import blocks
from wagtail.images.blocks import ImageChooserBlock
@register_streamfield_block
class ImageWithTextBlock(blocks.StructBlock):
image = ImageChooserBlock(
label="Bilde",
)
image_format = blocks.ChoiceBlock(
choices=[
("fullwidth", "Fullbredde"),
("bleed", "Utfallende"),
("original", "Uendret størrelse"),
],
default="fullwidth",
icon="cup",
label="Bildeformat",
)
text = blocks.CharBlock(
label="Tekst",
required=False,
max_length=512,
)
graphql_fields = [
GraphQLImage("image", required=True),
GraphQLString("image_format", required=True),
GraphQLString("text"),
]
class Meta:
icon = "image"
@register_streamfield_block
class ImageSliderItemBlock(blocks.StructBlock):
image = ImageChooserBlock(
label="Bilde",
)
text = blocks.CharBlock(
label="Tekst",
required=False,
max_length=512,
)
graphql_fields = [GraphQLImage("image", required=True), GraphQLString("text")]
class Meta:
icon = "image"
@register_streamfield_block
class ImageSliderBlock(blocks.StructBlock):
images = blocks.ListBlock(
ImageSliderItemBlock(),
min_num=1,
label="Bilder",
)
graphql_fields = [GraphQLStreamfield("images", required=True)]
class Meta:
icon = "image"