Add more blocks
This commit is contained in:
parent
bac41e2b74
commit
ef6b0496eb
4 changed files with 59 additions and 0 deletions
|
@ -5,11 +5,35 @@ from wagtail.documents.blocks import DocumentChooserBlock
|
||||||
from wagtail.embeds.blocks import EmbedBlock
|
from wagtail.embeds.blocks import EmbedBlock
|
||||||
from wagtailmarkdown.blocks import MarkdownBlock
|
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():
|
def build_stream_field():
|
||||||
return StreamField([
|
return StreamField([
|
||||||
('document', DocumentChooserBlock()),
|
('document', DocumentChooserBlock()),
|
||||||
|
('heading', HeadingBlock()),
|
||||||
('image', ImageChooserBlock()),
|
('image', ImageChooserBlock()),
|
||||||
('markdown', MarkdownBlock()),
|
('markdown', MarkdownBlock()),
|
||||||
|
('ol', blocks.ListBlock(blocks.CharBlock(label="List Item"), icon="list-ol", label="Ordered List", template='blocks/ordered-list.html')),
|
||||||
('paragraph', blocks.RichTextBlock()),
|
('paragraph', blocks.RichTextBlock()),
|
||||||
('raw_html', blocks.RawHTMLBlock(label="Raw HTML")),
|
('raw_html', blocks.RawHTMLBlock(label="Raw HTML")),
|
||||||
|
('ul', blocks.ListBlock(blocks.CharBlock(label="List Item"), icon="list-ul", label="Unordered List")),
|
||||||
|
('video', VideoBlock())
|
||||||
])
|
])
|
||||||
|
|
29
project/pages/migrations/0002_auto_20180726_0732.py
Normal file
29
project/pages/migrations/0002_auto_20180726_0732.py
Normal 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())]))]),
|
||||||
|
),
|
||||||
|
]
|
1
templates/blocks/heading.html
Normal file
1
templates/blocks/heading.html
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<{{ value.size }}>{{ value.value }}</{{ value.size }}>
|
5
templates/blocks/ordered-list.html
Normal file
5
templates/blocks/ordered-list.html
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<ol>
|
||||||
|
{% for item in value %}
|
||||||
|
<li>{{ item }}</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ol>
|
Reference in a new issue