add image-and-text and image slider block types
This commit is contained in:
70
dnscms/dnscms/blocks.py
Normal file
70
dnscms/dnscms/blocks.py
Normal 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"
|
Reference in New Issue
Block a user