From 370435c879a575d69a15959c196cb6a21901b0cc Mon Sep 17 00:00:00 2001
From: Parbhat Puri <parbhatpuri17@gmail.com>
Date: Thu, 21 Mar 2019 14:27:06 +0000
Subject: [PATCH] Only allow awesome table block in news pages

---
 .../0011_add_awesome_table_block.py           | 30 -------------------
 opentech/public/news/blocks.py                | 18 +++++++++++
 .../0009_add_awesome_table_block.py           |  2 +-
 opentech/public/news/models.py                |  5 ++--
 .../blocks/awesome_table_widget_block.html    |  0
 .../0013_add_awesome_table_block.py           | 24 ---------------
 .../0008_add_awesome_table_block.py           | 24 ---------------
 .../0004_add_awesome_table_block.py           | 24 ---------------
 opentech/public/utils/blocks.py               | 12 --------
 9 files changed, 22 insertions(+), 117 deletions(-)
 delete mode 100644 opentech/public/funds/migrations/0011_add_awesome_table_block.py
 create mode 100644 opentech/public/news/blocks.py
 rename opentech/{templates => public/news/templates/news}/blocks/awesome_table_widget_block.html (100%)
 delete mode 100644 opentech/public/people/migrations/0013_add_awesome_table_block.py
 delete mode 100644 opentech/public/projects/migrations/0008_add_awesome_table_block.py
 delete mode 100644 opentech/public/standardpages/migrations/0004_add_awesome_table_block.py

diff --git a/opentech/public/funds/migrations/0011_add_awesome_table_block.py b/opentech/public/funds/migrations/0011_add_awesome_table_block.py
deleted file mode 100644
index b8d9f5a4b..000000000
--- a/opentech/public/funds/migrations/0011_add_awesome_table_block.py
+++ /dev/null
@@ -1,30 +0,0 @@
-# Generated by Django 2.0.9 on 2019-03-21 14:04
-
-from django.db import migrations
-import opentech.public.funds.blocks
-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 = [
-        ('public_funds', '0010_correct_related_page_required'),
-    ]
-
-    operations = [
-        migrations.AlterField(
-            model_name='baseapplicationpage',
-            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.'))])), ('project_list', opentech.public.funds.blocks.ProjectsBlock()), ('reviewer_list', opentech.public.funds.blocks.ReviewersBlock())]),
-        ),
-        migrations.AlterField(
-            model_name='labpage',
-            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.'))])), ('reviewer_list', opentech.public.funds.blocks.ReviewersBlock())]),
-        ),
-    ]
diff --git a/opentech/public/news/blocks.py b/opentech/public/news/blocks.py
new file mode 100644
index 000000000..9500c2496
--- /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
index 3654dd560..7f509d4cd 100644
--- a/opentech/public/news/migrations/0009_add_awesome_table_block.py
+++ b/opentech/public/news/migrations/0009_add_awesome_table_block.py
@@ -1,4 +1,4 @@
-# Generated by Django 2.0.9 on 2019-03-21 14:04
+# Generated by Django 2.0.9 on 2019-03-21 14:25
 
 from django.db import migrations
 import wagtail.core.blocks
diff --git a/opentech/public/news/models.py b/opentech/public/news/models.py
index 7de88054f..c5a9f5d3f 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(block_counts={'awesome_table_widget': {'max_num': 1}}))
+    body = StreamField(NewsStoryBlock(block_counts={'awesome_table_widget': {'max_num': 1}}))
 
     search_fields = BasePage.search_fields + [
         index.SearchField('introduction'),
diff --git a/opentech/templates/blocks/awesome_table_widget_block.html b/opentech/public/news/templates/news/blocks/awesome_table_widget_block.html
similarity index 100%
rename from opentech/templates/blocks/awesome_table_widget_block.html
rename to opentech/public/news/templates/news/blocks/awesome_table_widget_block.html
diff --git a/opentech/public/people/migrations/0013_add_awesome_table_block.py b/opentech/public/people/migrations/0013_add_awesome_table_block.py
deleted file mode 100644
index 133643f49..000000000
--- a/opentech/public/people/migrations/0013_add_awesome_table_block.py
+++ /dev/null
@@ -1,24 +0,0 @@
-# Generated by Django 2.0.9 on 2019-03-21 14:04
-
-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 = [
-        ('people', '0012_personindexpage_introduction'),
-    ]
-
-    operations = [
-        migrations.AlterField(
-            model_name='personpage',
-            name='biography',
-            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.'))]))], blank=True),
-        ),
-    ]
diff --git a/opentech/public/projects/migrations/0008_add_awesome_table_block.py b/opentech/public/projects/migrations/0008_add_awesome_table_block.py
deleted file mode 100644
index 39ce325f7..000000000
--- a/opentech/public/projects/migrations/0008_add_awesome_table_block.py
+++ /dev/null
@@ -1,24 +0,0 @@
-# Generated by Django 2.0.9 on 2019-03-21 14:04
-
-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 = [
-        ('projects', '0007_fix_related_page_required_behaviour'),
-    ]
-
-    operations = [
-        migrations.AlterField(
-            model_name='projectpage',
-            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/standardpages/migrations/0004_add_awesome_table_block.py b/opentech/public/standardpages/migrations/0004_add_awesome_table_block.py
deleted file mode 100644
index c80159560..000000000
--- a/opentech/public/standardpages/migrations/0004_add_awesome_table_block.py
+++ /dev/null
@@ -1,24 +0,0 @@
-# Generated by Django 2.0.9 on 2019-03-21 14:04
-
-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 = [
-        ('standardpages', '0003_correct_related_page_behaviour'),
-    ]
-
-    operations = [
-        migrations.AlterField(
-            model_name='informationpage',
-            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/utils/blocks.py b/opentech/public/utils/blocks.py
index cbce08839..69409c87f 100644
--- a/opentech/public/utils/blocks.py
+++ b/opentech/public/utils/blocks.py
@@ -33,17 +33,6 @@ class QuoteBlock(blocks.StructBlock):
         template = "blocks/quote_block.html"
 
 
-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 = "blocks/awesome_table_widget_block.html"
-
-
 # Main streamfield block to be inherited by Pages
 class StoryBlock(blocks.StreamBlock):
     heading = blocks.CharBlock(classname="full title", icon='title')
@@ -56,7 +45,6 @@ class StoryBlock(blocks.StreamBlock):
         template="blocks/call_to_action_block.html"
     )
     document = DocumentBlock()
-    awesome_table_widget = AwesomeTableWidgetBlock()
 
     class Meta:
         template = "blocks/stream_block.html"
-- 
GitLab