From ef6b0496eb41b2b3dc0ee81885ea2896129ba704 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Thu, 26 Jul 2018 08:33:06 +0100 Subject: [PATCH] Add more blocks --- project/common/blocks.py | 24 +++++++++++++++ .../migrations/0002_auto_20180726_0732.py | 29 +++++++++++++++++++ templates/blocks/heading.html | 1 + templates/blocks/ordered-list.html | 5 ++++ 4 files changed, 59 insertions(+) create mode 100644 project/pages/migrations/0002_auto_20180726_0732.py create mode 100644 templates/blocks/heading.html create mode 100644 templates/blocks/ordered-list.html diff --git a/project/common/blocks.py b/project/common/blocks.py index 3401db5..15b4b45 100644 --- a/project/common/blocks.py +++ b/project/common/blocks.py @@ -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()) ]) diff --git a/project/pages/migrations/0002_auto_20180726_0732.py b/project/pages/migrations/0002_auto_20180726_0732.py new file mode 100644 index 0000000..6618e4a --- /dev/null +++ b/project/pages/migrations/0002_auto_20180726_0732.py @@ -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())]))]), + ), + ] diff --git a/templates/blocks/heading.html b/templates/blocks/heading.html new file mode 100644 index 0000000..3a59ef2 --- /dev/null +++ b/templates/blocks/heading.html @@ -0,0 +1 @@ +<{{ value.size }}>{{ value.value }} diff --git a/templates/blocks/ordered-list.html b/templates/blocks/ordered-list.html new file mode 100644 index 0000000..a64eab7 --- /dev/null +++ b/templates/blocks/ordered-list.html @@ -0,0 +1,5 @@ +
    + {% for item in value %} +
  1. {{ item }}
  2. + {% endfor %} +