Skip to content
Snippets Groups Projects
Unverified Commit b2ce1d34 authored by Fredrik Jonsson's avatar Fredrik Jonsson Committed by GitHub
Browse files

Merge pull request #1126 from OpenTechFund/awesome-table-block

Awesome table block in news pages
parents e2651b08 370435c8
No related branches found
No related tags found
No related merge requests found
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()
# 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.'))]))]),
),
]
......@@ -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'),
......
<div data-type="AwesomeTableView" data-viewID="{{ value.table_id }}"></div>
<script src="https://awesome-table.com/AwesomeTableInclude.js"></script>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment