1
Fork 0
This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
wagtail-website-2018-spike/project/common/blocks.py

40 lines
1.3 KiB
Python
Raw Normal View History

from wagtail.core.fields import StreamField
from wagtail.core import blocks
from wagtail.images.blocks import ImageChooserBlock
from wagtail.documents.blocks import DocumentChooserBlock
from wagtail.embeds.blocks import EmbedBlock
from wagtailmarkdown.blocks import MarkdownBlock
2018-07-26 08:33:06 +01:00
HEADING_CHOICES = [('h' + str(i), 'H' + str(i)) for i in range(1, 6)]
class HeadingBlock(blocks.StructBlock):
size = blocks.ChoiceBlock(choices=HEADING_CHOICES)
value = blocks.CharBlock()
class Meta:
icon = 'title'
template = 'blocks/heading.html'
class VideoBlock(blocks.StructBlock):
video = EmbedBlock()
caption = blocks.CharBlock()
class Meta:
template = 'blocks/video.html'
def build_stream_field():
return StreamField([
('document', DocumentChooserBlock()),
2018-07-26 08:33:06 +01:00
('heading', HeadingBlock()),
('image', ImageChooserBlock()),
('markdown', MarkdownBlock()),
2018-07-26 08:33:06 +01:00
('ol', blocks.ListBlock(blocks.CharBlock(label="List Item"), icon="list-ol", label="Ordered List", template='blocks/ordered-list.html')),
('paragraph', blocks.RichTextBlock()),
('raw_html', blocks.RawHTMLBlock(label="Raw HTML")),
2018-07-26 08:33:06 +01:00
('ul', blocks.ListBlock(blocks.CharBlock(label="List Item"), icon="list-ul", label="Unordered List")),
('video', VideoBlock())
])