Files
neuf-www/dnscms/contacts/blocks.py

63 lines
1.8 KiB
Python

from grapple.helpers import register_streamfield_block
from grapple.models import GraphQLForeignKey, GraphQLStreamfield, GraphQLString
from wagtail import blocks
from wagtail.snippets.blocks import SnippetChooserBlock
@register_streamfield_block
class ContactEntityBlock(blocks.StructBlock):
contact_entity = SnippetChooserBlock("contacts.ContactEntity")
graphql_fields = [
GraphQLForeignKey("contact_entity", "contacts.ContactEntity"),
]
@register_streamfield_block
class ContactListBlock(blocks.ListBlock):
pass
ContactEntityList = ContactListBlock(ContactEntityBlock(), label="Liste med kontaktpunkter")
@register_streamfield_block
class ContactSubsectionBlock(blocks.StructBlock):
title = blocks.CharBlock(max_length=64, required=True, label="Tittel")
text = blocks.RichTextBlock(features=["bold", "italic", "link"])
blocks = blocks.StreamBlock(
[
("contact_entity_list", ContactEntityList),
]
)
graphql_fields = [
GraphQLString("title", required=True),
GraphQLString("text", required=False),
GraphQLStreamfield("blocks", required=False),
]
class Meta:
icon = "folder-open-1"
@register_streamfield_block
class ContactSectionBlock(blocks.StructBlock):
title = blocks.CharBlock(max_length=64, required=True, label="Tittel")
text = blocks.RichTextBlock(features=["bold", "italic", "link"])
blocks = blocks.StreamBlock(
[
("contact_entity_list", ContactEntityList),
("contact_subsection", ContactSubsectionBlock(label="Kontaktunderseksjon")),
]
)
graphql_fields = [
GraphQLString("title", required=True),
GraphQLString("text", required=False),
GraphQLStreamfield("blocks", required=False),
]
class Meta:
icon = "folder-open-1"