From 1aba2c2909ced8bcfa7795d0adf6ac9987a3788f Mon Sep 17 00:00:00 2001 From: John Carroll Date: Sat, 16 Apr 2022 23:19:55 -0400 Subject: [PATCH 1/2] typed_tableblock block, template, migations --- fec/fec/settings/base.py | 1 + fec/home/blocks.py | 20 ++++ .../migrations/0124_auto_20220416_1954.py | 26 ++++++ .../migrations/0125_auto_20220416_2009.py | 26 ++++++ .../migrations/0126_auto_20220416_2251.py | 26 ++++++ .../templates/blocks/typed_table_block.html | 92 +++++++++++++++++++ 6 files changed, 191 insertions(+) create mode 100644 fec/home/migrations/0124_auto_20220416_1954.py create mode 100644 fec/home/migrations/0125_auto_20220416_2009.py create mode 100644 fec/home/migrations/0126_auto_20220416_2251.py create mode 100644 fec/home/templates/blocks/typed_table_block.html diff --git a/fec/fec/settings/base.py b/fec/fec/settings/base.py index 580cd436fb..d457fd2d16 100644 --- a/fec/fec/settings/base.py +++ b/fec/fec/settings/base.py @@ -114,6 +114,7 @@ 'wagtail.contrib.modeladmin', 'wagtail.contrib.search_promotions', 'wagtail.contrib.table_block', + 'wagtail.contrib.typed_table_block', 'wagtail.contrib.styleguide', 'fec', diff --git a/fec/home/blocks.py b/fec/home/blocks.py index 81d6fcf119..912a6da381 100644 --- a/fec/home/blocks.py +++ b/fec/home/blocks.py @@ -2,6 +2,7 @@ from wagtail.images.blocks import ImageChooserBlock from wagtail.documents.blocks import DocumentChooserBlock from wagtail.contrib.table_block.blocks import TableBlock +from wagtail.contrib.typed_table_block.blocks import TypedTableBlock from wagtail.snippets.blocks import SnippetChooserBlock """options for wagtail default table_block """ @@ -186,6 +187,24 @@ class Meta: template = 'blocks/custom_table.html' icon = 'table' +class CustomTypedTableBlock(blocks.StructBlock): + + table_layout = blocks.ChoiceBlock(choices=[ + ('fixed', 'Fixed'), + ('auto', 'Auto'), + ]) + + table = TypedTableBlock([ + ('text', blocks.CharBlock()), + ('numeric', blocks.FloatBlock()), + ('rich_text', blocks.RichTextBlock()), + ('image', ImageChooserBlock()), + ('ten_percent_width', blocks.RichTextBlock(cssClass='ten-percent-width')), + ('twenty_percent_width', blocks.RichTextBlock(cssClass='twenty-percent-width')), + ('thirty_percent_width', blocks.RichTextBlock(cssClass='thirty-percent-width')), + ('forty_percent_width', blocks.RichTextBlock(cssClass='forty-percent-width')), + + ]) class ExampleImage(blocks.StructBlock): """Creates an example module with an image and a caption, side-by-side @@ -238,6 +257,7 @@ class ResourceBlock(blocks.StructBlock): ('af_search', AFSearchBlock()), ('table', TableBlock(table_options=core_table_options)), ('custom_table', CustomTableBlock()), + ('typed_table', CustomTypedTableBlock(template = 'blocks/typed_table_block.html')), ('html', blocks.RawHTMLBlock()), ('reporting_example_cards', ReportingExampleCards()), ('contribution_limits_table', SnippetChooserBlock( diff --git a/fec/home/migrations/0124_auto_20220416_1954.py b/fec/home/migrations/0124_auto_20220416_1954.py new file mode 100644 index 0000000000..7653e1d209 --- /dev/null +++ b/fec/home/migrations/0124_auto_20220416_1954.py @@ -0,0 +1,26 @@ +# Generated by Django 3.1.14 on 2022-04-16 23:54 + +from django.db import migrations +import home.blocks +import wagtail.contrib.table_block.blocks +import wagtail.contrib.typed_table_block.blocks +import wagtail.core.blocks +import wagtail.core.fields +import wagtail.documents.blocks +import wagtail.images.blocks +import wagtail.snippets.blocks + + +class Migration(migrations.Migration): + + dependencies = [ + ('home', '0123_merge_20220308_1116'), + ] + + operations = [ + migrations.AlterField( + model_name='resourcepage', + name='sections', + field=wagtail.core.fields.StreamField([('sections', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.CharBlock(required=True)), ('hide_title', wagtail.core.blocks.BooleanBlock(help_text='Should the section title be displayed?', required=False)), ('content', wagtail.core.blocks.StreamBlock([('text', wagtail.core.blocks.RichTextBlock(blank=False, icon='pilcrow', null=False, required=False)), ('documents', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock(required=False)), ('url', wagtail.core.blocks.URLBlock()), ('media_type', wagtail.core.blocks.CharBlock()), ('text', wagtail.core.blocks.CharBlock())]), icon='doc-empty', template='blocks/section-documents.html')), ('contact_info', wagtail.core.blocks.StructBlock([('label', wagtail.core.blocks.CharBlock(icon='title', required=False)), ('contact_items', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock([('item_label', wagtail.core.blocks.CharBlock(required=False)), ('item_icon', wagtail.core.blocks.ChoiceBlock(choices=[('email', 'Email'), ('fax', 'Fax'), ('hand', 'Hand delivery'), ('phone', 'Phone'), ('mail', 'Mail'), ('github', 'Github'), ('question-bubble', 'Question')])), ('item_info', wagtail.core.blocks.RichTextBlock(required=True))])))])), ('internal_button', wagtail.core.blocks.StructBlock([('internal_page', wagtail.core.blocks.PageChooserBlock()), ('text', wagtail.core.blocks.CharBlock())])), ('external_button', wagtail.core.blocks.StructBlock([('url', wagtail.core.blocks.URLBlock()), ('text', wagtail.core.blocks.CharBlock())])), ('page', wagtail.core.blocks.PageChooserBlock(template='blocks/page-links.html')), ('disabled_page', wagtail.core.blocks.CharBlock(blank=False, help_text='Name of a disabled link', icon='placeholder', null=False, required=False, template='blocks/disabled-page-links.html')), ('document_list', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.CharBlock()), ('document', wagtail.documents.blocks.DocumentChooserBlock())]), icon='doc-empty', template='blocks/document-list.html')), ('simple_document_list', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.CharBlock()), ('document', wagtail.documents.blocks.DocumentChooserBlock())]), icon='doc-empty', template='blocks/simple-document-list.html')), ('current_commissioners', home.blocks.CurrentCommissionersBlock()), ('fec_jobs', home.blocks.CareersBlock()), ('mur_search', home.blocks.MURSearchBlock()), ('audit_search', home.blocks.AuditSearchBlock()), ('af_search', home.blocks.AFSearchBlock()), ('table', wagtail.contrib.table_block.blocks.TableBlock(table_options={'renderer': 'html'})), ('custom_table', wagtail.core.blocks.StructBlock([('custom_table', wagtail.core.blocks.StreamBlock([('title', wagtail.core.blocks.CharBlock(icon='title', required=False)), ('table_intro', wagtail.core.blocks.RichTextBlock(required=False)), ('table', wagtail.contrib.table_block.blocks.TableBlock(table_options={'colHeaders': True, 'height': 108, 'language': 'en', 'renderer': 'html', 'rowHeaders': True, 'startCols': 6, 'startRows': 7})), ('footnote', wagtail.core.blocks.CharBlock(icon='superscript', required=False))]))])), ('typed_table', wagtail.core.blocks.StructBlock([('table_layout', wagtail.core.blocks.ChoiceBlock(choices=[('fixed', 'Fixed'), ('auto', 'Auto')])), ('typed_table', wagtail.contrib.typed_table_block.blocks.TypedTableBlock([('text', wagtail.core.blocks.CharBlock()), ('numeric', wagtail.core.blocks.FloatBlock()), ('rich_text', wagtail.core.blocks.RichTextBlock()), ('image', wagtail.images.blocks.ImageChooserBlock()), ('ten_percent_width', wagtail.core.blocks.RichTextBlock(cssClass='ten-percent-width')), ('twenty_percent_width', wagtail.core.blocks.RichTextBlock(cssClass='twenty-percent-width')), ('thirty_percent_width', wagtail.core.blocks.RichTextBlock(cssClass='thirty-percent-width')), ('forty_percent_width', wagtail.core.blocks.RichTextBlock(cssClass='forty-percent-width'))]))])), ('html', wagtail.core.blocks.RawHTMLBlock()), ('reporting_example_cards', wagtail.core.blocks.StructBlock([('card_width', wagtail.core.blocks.ChoiceBlock(choices=[(2, '1/2'), (3, '1/3')], help_text='Control the width of the cards')), ('cards', wagtail.core.blocks.ListBlock(wagtail.core.blocks.PageChooserBlock(), icon='doc-empty'))])), ('contribution_limits_table', wagtail.snippets.blocks.SnippetChooserBlock('home.EmbedSnippet', icon='table', template='blocks/embed-table.html')), ('informational_message', wagtail.snippets.blocks.SnippetChooserBlock('home.EmbedSnippet', icon='warning', template='blocks/embed-info-message.html')), ('image', wagtail.images.blocks.ImageChooserBlock()), ('example_image', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.CharBlock(required=False)), ('caption', wagtail.core.blocks.RichTextBlock(required=True)), ('image', wagtail.images.blocks.ImageChooserBlock(required=True))])), ('example_paragraph', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.CharBlock(required=True)), ('paragraph', wagtail.core.blocks.RichTextBlock(required=True))]))])), ('aside', wagtail.core.blocks.StreamBlock([('title', wagtail.core.blocks.CharBlock(icon='title', required=False)), ('document', wagtail.core.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock(required=False)), ('url', wagtail.core.blocks.URLBlock()), ('media_type', wagtail.core.blocks.CharBlock()), ('text', wagtail.core.blocks.CharBlock())])), ('link', wagtail.core.blocks.StructBlock([('link_type', wagtail.core.blocks.ChoiceBlock(choices=[('calculator', 'Calculator'), ('calendar', 'Calendar'), ('record', 'Record'), ('search', 'Search')], help_text='Set an icon', icon='link', required=False)), ('url', wagtail.core.blocks.URLBlock()), ('text', wagtail.core.blocks.CharBlock(required=True)), ('coming_soon', wagtail.core.blocks.BooleanBlock(required=False))]))], icon='placeholder', required=False, template='blocks/section-aside.html'))]))], blank=True, null=True), + ), + ] diff --git a/fec/home/migrations/0125_auto_20220416_2009.py b/fec/home/migrations/0125_auto_20220416_2009.py new file mode 100644 index 0000000000..01dbb2a47e --- /dev/null +++ b/fec/home/migrations/0125_auto_20220416_2009.py @@ -0,0 +1,26 @@ +# Generated by Django 3.1.14 on 2022-04-17 00:09 + +from django.db import migrations +import home.blocks +import wagtail.contrib.table_block.blocks +import wagtail.contrib.typed_table_block.blocks +import wagtail.core.blocks +import wagtail.core.fields +import wagtail.documents.blocks +import wagtail.images.blocks +import wagtail.snippets.blocks + + +class Migration(migrations.Migration): + + dependencies = [ + ('home', '0124_auto_20220416_1954'), + ] + + operations = [ + migrations.AlterField( + model_name='resourcepage', + name='sections', + field=wagtail.core.fields.StreamField([('sections', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.CharBlock(required=True)), ('hide_title', wagtail.core.blocks.BooleanBlock(help_text='Should the section title be displayed?', required=False)), ('content', wagtail.core.blocks.StreamBlock([('text', wagtail.core.blocks.RichTextBlock(blank=False, icon='pilcrow', null=False, required=False)), ('documents', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock(required=False)), ('url', wagtail.core.blocks.URLBlock()), ('media_type', wagtail.core.blocks.CharBlock()), ('text', wagtail.core.blocks.CharBlock())]), icon='doc-empty', template='blocks/section-documents.html')), ('contact_info', wagtail.core.blocks.StructBlock([('label', wagtail.core.blocks.CharBlock(icon='title', required=False)), ('contact_items', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock([('item_label', wagtail.core.blocks.CharBlock(required=False)), ('item_icon', wagtail.core.blocks.ChoiceBlock(choices=[('email', 'Email'), ('fax', 'Fax'), ('hand', 'Hand delivery'), ('phone', 'Phone'), ('mail', 'Mail'), ('github', 'Github'), ('question-bubble', 'Question')])), ('item_info', wagtail.core.blocks.RichTextBlock(required=True))])))])), ('internal_button', wagtail.core.blocks.StructBlock([('internal_page', wagtail.core.blocks.PageChooserBlock()), ('text', wagtail.core.blocks.CharBlock())])), ('external_button', wagtail.core.blocks.StructBlock([('url', wagtail.core.blocks.URLBlock()), ('text', wagtail.core.blocks.CharBlock())])), ('page', wagtail.core.blocks.PageChooserBlock(template='blocks/page-links.html')), ('disabled_page', wagtail.core.blocks.CharBlock(blank=False, help_text='Name of a disabled link', icon='placeholder', null=False, required=False, template='blocks/disabled-page-links.html')), ('document_list', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.CharBlock()), ('document', wagtail.documents.blocks.DocumentChooserBlock())]), icon='doc-empty', template='blocks/document-list.html')), ('simple_document_list', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.CharBlock()), ('document', wagtail.documents.blocks.DocumentChooserBlock())]), icon='doc-empty', template='blocks/simple-document-list.html')), ('current_commissioners', home.blocks.CurrentCommissionersBlock()), ('fec_jobs', home.blocks.CareersBlock()), ('mur_search', home.blocks.MURSearchBlock()), ('audit_search', home.blocks.AuditSearchBlock()), ('af_search', home.blocks.AFSearchBlock()), ('table', wagtail.contrib.table_block.blocks.TableBlock(table_options={'renderer': 'html'})), ('custom_table', wagtail.core.blocks.StructBlock([('custom_table', wagtail.core.blocks.StreamBlock([('title', wagtail.core.blocks.CharBlock(icon='title', required=False)), ('table_intro', wagtail.core.blocks.RichTextBlock(required=False)), ('table', wagtail.contrib.table_block.blocks.TableBlock(table_options={'colHeaders': True, 'height': 108, 'language': 'en', 'renderer': 'html', 'rowHeaders': True, 'startCols': 6, 'startRows': 7})), ('footnote', wagtail.core.blocks.CharBlock(icon='superscript', required=False))]))])), ('custom_typed_table', wagtail.core.blocks.StructBlock([('table_layout', wagtail.core.blocks.ChoiceBlock(choices=[('fixed', 'Fixed'), ('auto', 'Auto')])), ('typed_table', wagtail.contrib.typed_table_block.blocks.TypedTableBlock([('text', wagtail.core.blocks.CharBlock()), ('numeric', wagtail.core.blocks.FloatBlock()), ('rich_text', wagtail.core.blocks.RichTextBlock()), ('image', wagtail.images.blocks.ImageChooserBlock()), ('ten_percent_width', wagtail.core.blocks.RichTextBlock(cssClass='ten-percent-width')), ('twenty_percent_width', wagtail.core.blocks.RichTextBlock(cssClass='twenty-percent-width')), ('thirty_percent_width', wagtail.core.blocks.RichTextBlock(cssClass='thirty-percent-width')), ('forty_percent_width', wagtail.core.blocks.RichTextBlock(cssClass='forty-percent-width'))]))])), ('html', wagtail.core.blocks.RawHTMLBlock()), ('reporting_example_cards', wagtail.core.blocks.StructBlock([('card_width', wagtail.core.blocks.ChoiceBlock(choices=[(2, '1/2'), (3, '1/3')], help_text='Control the width of the cards')), ('cards', wagtail.core.blocks.ListBlock(wagtail.core.blocks.PageChooserBlock(), icon='doc-empty'))])), ('contribution_limits_table', wagtail.snippets.blocks.SnippetChooserBlock('home.EmbedSnippet', icon='table', template='blocks/embed-table.html')), ('informational_message', wagtail.snippets.blocks.SnippetChooserBlock('home.EmbedSnippet', icon='warning', template='blocks/embed-info-message.html')), ('image', wagtail.images.blocks.ImageChooserBlock()), ('example_image', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.CharBlock(required=False)), ('caption', wagtail.core.blocks.RichTextBlock(required=True)), ('image', wagtail.images.blocks.ImageChooserBlock(required=True))])), ('example_paragraph', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.CharBlock(required=True)), ('paragraph', wagtail.core.blocks.RichTextBlock(required=True))]))])), ('aside', wagtail.core.blocks.StreamBlock([('title', wagtail.core.blocks.CharBlock(icon='title', required=False)), ('document', wagtail.core.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock(required=False)), ('url', wagtail.core.blocks.URLBlock()), ('media_type', wagtail.core.blocks.CharBlock()), ('text', wagtail.core.blocks.CharBlock())])), ('link', wagtail.core.blocks.StructBlock([('link_type', wagtail.core.blocks.ChoiceBlock(choices=[('calculator', 'Calculator'), ('calendar', 'Calendar'), ('record', 'Record'), ('search', 'Search')], help_text='Set an icon', icon='link', required=False)), ('url', wagtail.core.blocks.URLBlock()), ('text', wagtail.core.blocks.CharBlock(required=True)), ('coming_soon', wagtail.core.blocks.BooleanBlock(required=False))]))], icon='placeholder', required=False, template='blocks/section-aside.html'))]))], blank=True, null=True), + ), + ] diff --git a/fec/home/migrations/0126_auto_20220416_2251.py b/fec/home/migrations/0126_auto_20220416_2251.py new file mode 100644 index 0000000000..aa612685ee --- /dev/null +++ b/fec/home/migrations/0126_auto_20220416_2251.py @@ -0,0 +1,26 @@ +# Generated by Django 3.1.14 on 2022-04-17 02:51 + +from django.db import migrations +import home.blocks +import wagtail.contrib.table_block.blocks +import wagtail.contrib.typed_table_block.blocks +import wagtail.core.blocks +import wagtail.core.fields +import wagtail.documents.blocks +import wagtail.images.blocks +import wagtail.snippets.blocks + + +class Migration(migrations.Migration): + + dependencies = [ + ('home', '0125_auto_20220416_2009'), + ] + + operations = [ + migrations.AlterField( + model_name='resourcepage', + name='sections', + field=wagtail.core.fields.StreamField([('sections', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.CharBlock(required=True)), ('hide_title', wagtail.core.blocks.BooleanBlock(help_text='Should the section title be displayed?', required=False)), ('content', wagtail.core.blocks.StreamBlock([('text', wagtail.core.blocks.RichTextBlock(blank=False, icon='pilcrow', null=False, required=False)), ('documents', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock(required=False)), ('url', wagtail.core.blocks.URLBlock()), ('media_type', wagtail.core.blocks.CharBlock()), ('text', wagtail.core.blocks.CharBlock())]), icon='doc-empty', template='blocks/section-documents.html')), ('contact_info', wagtail.core.blocks.StructBlock([('label', wagtail.core.blocks.CharBlock(icon='title', required=False)), ('contact_items', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock([('item_label', wagtail.core.blocks.CharBlock(required=False)), ('item_icon', wagtail.core.blocks.ChoiceBlock(choices=[('email', 'Email'), ('fax', 'Fax'), ('hand', 'Hand delivery'), ('phone', 'Phone'), ('mail', 'Mail'), ('github', 'Github'), ('question-bubble', 'Question')])), ('item_info', wagtail.core.blocks.RichTextBlock(required=True))])))])), ('internal_button', wagtail.core.blocks.StructBlock([('internal_page', wagtail.core.blocks.PageChooserBlock()), ('text', wagtail.core.blocks.CharBlock())])), ('external_button', wagtail.core.blocks.StructBlock([('url', wagtail.core.blocks.URLBlock()), ('text', wagtail.core.blocks.CharBlock())])), ('page', wagtail.core.blocks.PageChooserBlock(template='blocks/page-links.html')), ('disabled_page', wagtail.core.blocks.CharBlock(blank=False, help_text='Name of a disabled link', icon='placeholder', null=False, required=False, template='blocks/disabled-page-links.html')), ('document_list', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.CharBlock()), ('document', wagtail.documents.blocks.DocumentChooserBlock())]), icon='doc-empty', template='blocks/document-list.html')), ('simple_document_list', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.CharBlock()), ('document', wagtail.documents.blocks.DocumentChooserBlock())]), icon='doc-empty', template='blocks/simple-document-list.html')), ('current_commissioners', home.blocks.CurrentCommissionersBlock()), ('fec_jobs', home.blocks.CareersBlock()), ('mur_search', home.blocks.MURSearchBlock()), ('audit_search', home.blocks.AuditSearchBlock()), ('af_search', home.blocks.AFSearchBlock()), ('table', wagtail.contrib.table_block.blocks.TableBlock(table_options={'renderer': 'html'})), ('custom_table', wagtail.core.blocks.StructBlock([('custom_table', wagtail.core.blocks.StreamBlock([('title', wagtail.core.blocks.CharBlock(icon='title', required=False)), ('table_intro', wagtail.core.blocks.RichTextBlock(required=False)), ('table', wagtail.contrib.table_block.blocks.TableBlock(table_options={'colHeaders': True, 'height': 108, 'language': 'en', 'renderer': 'html', 'rowHeaders': True, 'startCols': 6, 'startRows': 7})), ('footnote', wagtail.core.blocks.CharBlock(icon='superscript', required=False))]))])), ('typed_table', wagtail.core.blocks.StructBlock([('table_layout', wagtail.core.blocks.ChoiceBlock(choices=[('fixed', 'Fixed'), ('auto', 'Auto')])), ('table', wagtail.contrib.typed_table_block.blocks.TypedTableBlock([('text', wagtail.core.blocks.CharBlock()), ('numeric', wagtail.core.blocks.FloatBlock()), ('rich_text', wagtail.core.blocks.RichTextBlock()), ('image', wagtail.images.blocks.ImageChooserBlock()), ('ten_percent_width', wagtail.core.blocks.RichTextBlock(cssClass='ten-percent-width')), ('twenty_percent_width', wagtail.core.blocks.RichTextBlock(cssClass='twenty-percent-width')), ('thirty_percent_width', wagtail.core.blocks.RichTextBlock(cssClass='thirty-percent-width')), ('forty_percent_width', wagtail.core.blocks.RichTextBlock(cssClass='forty-percent-width'))]))])), ('html', wagtail.core.blocks.RawHTMLBlock()), ('reporting_example_cards', wagtail.core.blocks.StructBlock([('card_width', wagtail.core.blocks.ChoiceBlock(choices=[(2, '1/2'), (3, '1/3')], help_text='Control the width of the cards')), ('cards', wagtail.core.blocks.ListBlock(wagtail.core.blocks.PageChooserBlock(), icon='doc-empty'))])), ('contribution_limits_table', wagtail.snippets.blocks.SnippetChooserBlock('home.EmbedSnippet', icon='table', template='blocks/embed-table.html')), ('informational_message', wagtail.snippets.blocks.SnippetChooserBlock('home.EmbedSnippet', icon='warning', template='blocks/embed-info-message.html')), ('image', wagtail.images.blocks.ImageChooserBlock()), ('example_image', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.CharBlock(required=False)), ('caption', wagtail.core.blocks.RichTextBlock(required=True)), ('image', wagtail.images.blocks.ImageChooserBlock(required=True))])), ('example_paragraph', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.CharBlock(required=True)), ('paragraph', wagtail.core.blocks.RichTextBlock(required=True))]))])), ('aside', wagtail.core.blocks.StreamBlock([('title', wagtail.core.blocks.CharBlock(icon='title', required=False)), ('document', wagtail.core.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock(required=False)), ('url', wagtail.core.blocks.URLBlock()), ('media_type', wagtail.core.blocks.CharBlock()), ('text', wagtail.core.blocks.CharBlock())])), ('link', wagtail.core.blocks.StructBlock([('link_type', wagtail.core.blocks.ChoiceBlock(choices=[('calculator', 'Calculator'), ('calendar', 'Calendar'), ('record', 'Record'), ('search', 'Search')], help_text='Set an icon', icon='link', required=False)), ('url', wagtail.core.blocks.URLBlock()), ('text', wagtail.core.blocks.CharBlock(required=True)), ('coming_soon', wagtail.core.blocks.BooleanBlock(required=False))]))], icon='placeholder', required=False, template='blocks/section-aside.html'))]))], blank=True, null=True), + ), + ] diff --git a/fec/home/templates/blocks/typed_table_block.html b/fec/home/templates/blocks/typed_table_block.html new file mode 100644 index 0000000000..e332407c4d --- /dev/null +++ b/fec/home/templates/blocks/typed_table_block.html @@ -0,0 +1,92 @@ +{% load wagtailcore_tags %} +{% load filters %} + + +{% for block in self.typed_table %} + + + {% for subblock in block.value.columns %} + + {{ subblock.block }} + + + {% endfor %} + + + +{% endfor %} + + + + + +
+ +
+ +{% for block in self.value %} + + {% if block.block_type == "title" %} +

{{ block }}

+ + {% elif block.block_type == "paragraph" %} +
{{ block }}
+ + {% elif block.block_type == "table_layout" %} +
+ + + + + {% elif block.block_type == "table" %} + + + + + {% for col in block.value.columns %} + + + {% endfor %} + + + + {% for row in block.value.rows %} + + {% for block in row %} + + + + + {% endfor %} + + {% endfor %} + +
{{ col.heading }}
{% include_block block %}
+ +
+ + {% endif %} + +{% endfor %} From 46add0ba1c0f1164260d2734a4ffe2a2fb9edf76 Mon Sep 17 00:00:00 2001 From: John Carroll Date: Wed, 20 Apr 2022 21:21:22 -0400 Subject: [PATCH 2/2] fun with template language --- fec/home/blocks.py | 48 +++++++++++++------ .../templates/blocks/typed_table_block.html | 44 +++++++++++------ 2 files changed, 63 insertions(+), 29 deletions(-) diff --git a/fec/home/blocks.py b/fec/home/blocks.py index 912a6da381..b88d85cf62 100644 --- a/fec/home/blocks.py +++ b/fec/home/blocks.py @@ -188,23 +188,43 @@ class Meta: icon = 'table' class CustomTypedTableBlock(blocks.StructBlock): - - table_layout = blocks.ChoiceBlock(choices=[ - ('fixed', 'Fixed'), - ('auto', 'Auto'), + typed_table = blocks.StreamBlock([ + ('table_layout', blocks.ChoiceBlock(choices=[ + ('fixed', 'Fixed'), + ('auto', 'Auto'), + ])), + + ('table', TypedTableBlock([ + ('text', blocks.CharBlock()), + ('numeric', blocks.FloatBlock()), + ('rich_text', blocks.RichTextBlock()), + ('image', ImageChooserBlock()), + #('column_header', blocks.RichTextBlock(attr='column')), + ('ten_percent_width', blocks.RichTextBlock(cssClass='ten-percent-width')), + ('twenty_percent_width', blocks.RichTextBlock(cssClass='twenty-percent-width')), + ('thirty_percent_width', blocks.RichTextBlock(cssClass='thirty-percent-width')), + ('forty_percent_width', blocks.RichTextBlock(cssClass='forty-percent-width')), + ])) ]) - table = TypedTableBlock([ - ('text', blocks.CharBlock()), - ('numeric', blocks.FloatBlock()), - ('rich_text', blocks.RichTextBlock()), - ('image', ImageChooserBlock()), - ('ten_percent_width', blocks.RichTextBlock(cssClass='ten-percent-width')), - ('twenty_percent_width', blocks.RichTextBlock(cssClass='twenty-percent-width')), - ('thirty_percent_width', blocks.RichTextBlock(cssClass='thirty-percent-width')), - ('forty_percent_width', blocks.RichTextBlock(cssClass='forty-percent-width')), +# class CustomTypedTableBlock(blocks.StructBlock): + +# table_layout = blocks.ChoiceBlock(choices=[ +# ('fixed', 'Fixed'), +# ('auto', 'Auto'), +# ]) + +# typed_table = TypedTableBlock([ +# ('text', blocks.CharBlock()), +# ('numeric', blocks.FloatBlock()), +# ('rich_text', blocks.RichTextBlock()), +# ('image', ImageChooserBlock()), +# ('ten_percent_width', blocks.RichTextBlock(cssClass='ten-percent-width')), +# ('twenty_percent_width', blocks.RichTextBlock(cssClass='twenty-percent-width')), +# ('thirty_percent_width', blocks.RichTextBlock(cssClass='thirty-percent-width')), +# ('forty_percent_width', blocks.RichTextBlock(cssClass='forty-percent-width')), - ]) +# ]) class ExampleImage(blocks.StructBlock): """Creates an example module with an image and a caption, side-by-side diff --git a/fec/home/templates/blocks/typed_table_block.html b/fec/home/templates/blocks/typed_table_block.html index e332407c4d..f2b6139646 100644 --- a/fec/home/templates/blocks/typed_table_block.html +++ b/fec/home/templates/blocks/typed_table_block.html @@ -10,6 +10,22 @@ {{ subblock.block }} + {% endfor %} +

-------------END COLUMNS-----------------

+ + + + {% for subblock in block.value.row_data %} + +

-------------NEW ROWS----------------

+ + {{ subblock.value}} + {{ subblock.values.0}} +

------------------------------

+ + + + {% endfor %} @@ -28,16 +44,16 @@ padding: 1rem; } - .ten_percent_width { + .ten-percent-width { width: 10%; } - .twenty_percent_width { + .twenty-percent-width { width: 20%; } - .thirty_percent_width { + .thirty-percent-width { width: 30%; } - .forty_percent_width { + .forty-percent-width { width: 40%; } @@ -46,18 +62,12 @@
-{% for block in self.value %} - - {% if block.block_type == "title" %} -

{{ block }}

- - {% elif block.block_type == "paragraph" %} -
{{ block }}
+{% for block in self.typed_table %} - {% elif block.block_type == "table_layout" %} + {% if block.block_type == "table_layout" %}
- +
{% elif block.block_type == "table" %} @@ -66,16 +76,20 @@

{{ block }}

{% for col in block.value.columns %} - {% endfor %} + {% for row in block.value.rows %} + + {% for block in row %} - + + +
{{ col.heading }}
{% include_block block %}{{ block.value | striptags }}