1
Fork 0

Add more blocks

This commit is contained in:
Jake Howard 2018-07-26 08:33:06 +01:00
parent bac41e2b74
commit ef6b0496eb
Signed by: jake
GPG key ID: 57AFB45680EDD477
4 changed files with 59 additions and 0 deletions

View file

@ -5,11 +5,35 @@ from wagtail.documents.blocks import DocumentChooserBlock
from wagtail.embeds.blocks import EmbedBlock
from wagtailmarkdown.blocks import MarkdownBlock
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()),
('heading', HeadingBlock()),
('image', ImageChooserBlock()),
('markdown', MarkdownBlock()),
('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")),
('ul', blocks.ListBlock(blocks.CharBlock(label="List Item"), icon="list-ul", label="Unordered List")),
('video', VideoBlock())
])

View file

@ -0,0 +1,29 @@
# Generated by Django 2.0.7 on 2018-07-26 07:32
from django.db import migrations
import wagtail.core.blocks
import wagtail.core.fields
import wagtail.documents.blocks
import wagtail.embeds.blocks
import wagtail.images.blocks
import wagtailmarkdown.blocks
class Migration(migrations.Migration):
dependencies = [
('pages', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='sectionindexpage',
name='body',
field=wagtail.core.fields.StreamField([('document', wagtail.documents.blocks.DocumentChooserBlock()), ('heading', wagtail.core.blocks.StructBlock([('size', wagtail.core.blocks.ChoiceBlock(choices=[('h1', 'H1'), ('h2', 'H2'), ('h3', 'H3'), ('h4', 'H4'), ('h5', 'H5')])), ('value', wagtail.core.blocks.CharBlock())])), ('image', wagtail.images.blocks.ImageChooserBlock()), ('markdown', wagtailmarkdown.blocks.MarkdownBlock()), ('ol', wagtail.core.blocks.ListBlock(wagtail.core.blocks.CharBlock(label='List Item'), icon='list-ol', label='Ordered List', template='blocks/ordered-list.html')), ('paragraph', wagtail.core.blocks.RichTextBlock()), ('raw_html', wagtail.core.blocks.RawHTMLBlock(label='Raw HTML')), ('ul', wagtail.core.blocks.ListBlock(wagtail.core.blocks.CharBlock(label='List Item'), icon='list-ul', label='Unordered List')), ('video', wagtail.core.blocks.StructBlock([('video', wagtail.embeds.blocks.EmbedBlock()), ('caption', wagtail.core.blocks.CharBlock())]))]),
),
migrations.AlterField(
model_name='simplecontentpage',
name='body',
field=wagtail.core.fields.StreamField([('document', wagtail.documents.blocks.DocumentChooserBlock()), ('heading', wagtail.core.blocks.StructBlock([('size', wagtail.core.blocks.ChoiceBlock(choices=[('h1', 'H1'), ('h2', 'H2'), ('h3', 'H3'), ('h4', 'H4'), ('h5', 'H5')])), ('value', wagtail.core.blocks.CharBlock())])), ('image', wagtail.images.blocks.ImageChooserBlock()), ('markdown', wagtailmarkdown.blocks.MarkdownBlock()), ('ol', wagtail.core.blocks.ListBlock(wagtail.core.blocks.CharBlock(label='List Item'), icon='list-ol', label='Ordered List', template='blocks/ordered-list.html')), ('paragraph', wagtail.core.blocks.RichTextBlock()), ('raw_html', wagtail.core.blocks.RawHTMLBlock(label='Raw HTML')), ('ul', wagtail.core.blocks.ListBlock(wagtail.core.blocks.CharBlock(label='List Item'), icon='list-ul', label='Unordered List')), ('video', wagtail.core.blocks.StructBlock([('video', wagtail.embeds.blocks.EmbedBlock()), ('caption', wagtail.core.blocks.CharBlock())]))]),
),
]

View file

@ -0,0 +1 @@
<{{ value.size }}>{{ value.value }}</{{ value.size }}>

View file

@ -0,0 +1,5 @@
<ol>
{% for item in value %}
<li>{{ item }}</li>
{% endfor %}
</ol>