diff --git a/opentech/public/news/blocks.py b/opentech/public/news/blocks.py new file mode 100644 index 0000000000000000000000000000000000000000..9500c249618a5327713b5b606ec02f372d66693f --- /dev/null +++ b/opentech/public/news/blocks.py @@ -0,0 +1,18 @@ +from wagtail.core import blocks + +from opentech.public.utils.blocks import StoryBlock + + +class AwesomeTableWidgetBlock(blocks.StructBlock): + table_id = blocks.CharBlock( + classname="title", + help_text='Please enter only table id from embed code. Table widget code creates automatically.' + ) + + class Meta: + icon = "table" + template = "news/blocks/awesome_table_widget_block.html" + + +class NewsStoryBlock(StoryBlock): + awesome_table_widget = AwesomeTableWidgetBlock() diff --git a/opentech/public/news/migrations/0009_add_awesome_table_block.py b/opentech/public/news/migrations/0009_add_awesome_table_block.py new file mode 100644 index 0000000000000000000000000000000000000000..7f509d4cdee7373b5569fc370051c2c6b924db87 --- /dev/null +++ b/opentech/public/news/migrations/0009_add_awesome_table_block.py @@ -0,0 +1,24 @@ +# Generated by Django 2.0.9 on 2019-03-21 14:25 + +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 wagtail.snippets.blocks + + +class Migration(migrations.Migration): + + dependencies = [ + ('news', '0008_correct_related_page_behaviour'), + ] + + operations = [ + migrations.AlterField( + model_name='newspage', + name='body', + field=wagtail.core.fields.StreamField([('heading', wagtail.core.blocks.CharBlock(classname='full title', icon='title')), ('paragraph', wagtail.core.blocks.RichTextBlock()), ('image', wagtail.core.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock()), ('caption', wagtail.core.blocks.CharBlock(required=False))])), ('quote', wagtail.core.blocks.StructBlock([('quote', wagtail.core.blocks.CharBlock(classname='title')), ('attribution', wagtail.core.blocks.CharBlock(required=False)), ('job_title', wagtail.core.blocks.CharBlock(required=False))])), ('embed', wagtail.embeds.blocks.EmbedBlock()), ('call_to_action', wagtail.snippets.blocks.SnippetChooserBlock('utils.CallToActionSnippet', template='blocks/call_to_action_block.html')), ('document', wagtail.core.blocks.StructBlock([('document', wagtail.documents.blocks.DocumentChooserBlock()), ('title', wagtail.core.blocks.CharBlock(required=False))])), ('awesome_table_widget', wagtail.core.blocks.StructBlock([('table_id', wagtail.core.blocks.CharBlock(classname='title', help_text='Please enter only table id from embed code. Table widget code creates automatically.'))]))]), + ), + ] diff --git a/opentech/public/news/models.py b/opentech/public/news/models.py index 05f029338bd829128aee9fc1cc7e3c5655a3e35a..c5a9f5d3f31d0c95858f527f1d941e426068d9b2 100644 --- a/opentech/public/news/models.py +++ b/opentech/public/news/models.py @@ -16,7 +16,8 @@ from wagtail.admin.edit_handlers import ( from wagtail.search import index from opentech.public.utils.models import BasePage, RelatedPage -from opentech.public.utils.blocks import StoryBlock + +from .blocks import NewsStoryBlock class NewsType(models.Model): @@ -97,7 +98,7 @@ class NewsPage(BasePage): "news item appears to have been published." ) introduction = models.TextField(blank=True) - body = StreamField(StoryBlock()) + body = StreamField(NewsStoryBlock(block_counts={'awesome_table_widget': {'max_num': 1}})) search_fields = BasePage.search_fields + [ index.SearchField('introduction'), diff --git a/opentech/public/news/templates/news/blocks/awesome_table_widget_block.html b/opentech/public/news/templates/news/blocks/awesome_table_widget_block.html new file mode 100644 index 0000000000000000000000000000000000000000..8b26c0ab0ec04561da0e1009c424c705c8f2b46f --- /dev/null +++ b/opentech/public/news/templates/news/blocks/awesome_table_widget_block.html @@ -0,0 +1,2 @@ +<div data-type="AwesomeTableView" data-viewID="{{ value.table_id }}"></div> +<script src="https://awesome-table.com/AwesomeTableInclude.js"></script>