From de231a0fa9efaef7e9a96be6df90880e85837c25 Mon Sep 17 00:00:00 2001 From: OndraRehounek <ondra.rehounek@seznam.cz> Date: Thu, 28 Apr 2022 11:32:56 +0200 Subject: [PATCH] district (and region): table - markdown enabled template - use one migration with YT block --- ...r_districtarticlepage_content_and_more.py} | 63 ++++++++++++++++++- district/models.py | 4 +- ...ter_regionarticlepage_content_and_more.py} | 63 ++++++++++++++++++- region/models.py | 4 +- .../templates/shared/blocks/table_block.html | 49 +++++++++++++++ .../0025_alter_uniwebarticlepage_content.py | 2 +- 6 files changed, 178 insertions(+), 7 deletions(-) rename district/migrations/{0060_alter_districtarticlepage_content.py => 0060_alter_districtarticlepage_content_and_more.py} (60%) rename region/migrations/{0035_alter_regionarticlepage_content.py => 0035_alter_regionarticlepage_content_and_more.py} (60%) create mode 100644 shared/templates/shared/blocks/table_block.html diff --git a/district/migrations/0060_alter_districtarticlepage_content.py b/district/migrations/0060_alter_districtarticlepage_content_and_more.py similarity index 60% rename from district/migrations/0060_alter_districtarticlepage_content.py rename to district/migrations/0060_alter_districtarticlepage_content_and_more.py index 2414b4a4..803bc825 100644 --- a/district/migrations/0060_alter_districtarticlepage_content.py +++ b/district/migrations/0060_alter_districtarticlepage_content_and_more.py @@ -1,5 +1,6 @@ -# Generated by Django 4.0.3 on 2022-04-28 08:35 +# Generated by Django 4.0.3 on 2022-04-28 09:31 +import wagtail.contrib.table_block.blocks import wagtail.core.blocks import wagtail.core.fields import wagtail.images.blocks @@ -93,4 +94,64 @@ class Migration(migrations.Migration): verbose_name="Článek", ), ), + migrations.AlterField( + model_name="districtcenterpage", + name="content", + field=wagtail.core.fields.StreamField( + [ + ("text", wagtail.core.blocks.RichTextBlock()), + ( + "table", + wagtail.contrib.table_block.blocks.TableBlock( + template="shared/blocks/table_block.html" + ), + ), + ], + blank=True, + verbose_name="Obsah", + ), + ), + migrations.AlterField( + model_name="districtcustompage", + name="content", + field=wagtail.core.fields.StreamField( + [ + ("text", wagtail.core.blocks.RichTextBlock()), + ( + "table", + wagtail.contrib.table_block.blocks.TableBlock( + template="shared/blocks/table_block.html" + ), + ), + ( + "people_group", + wagtail.core.blocks.StructBlock( + [ + ( + "group_title", + wagtail.core.blocks.CharBlock( + label="Titulek", required=True + ), + ), + ( + "person_list", + wagtail.core.blocks.ListBlock( + wagtail.core.blocks.PageChooserBlock( + label="Osoba", + page_type=[ + "district.DistrictPersonPage", + "region.RegionPersonPage", + ], + ), + label="List osob", + ), + ), + ] + ), + ), + ], + blank=True, + verbose_name="Obsah", + ), + ), ] diff --git a/district/models.py b/district/models.py index 3d877d89..51863f64 100644 --- a/district/models.py +++ b/district/models.py @@ -922,7 +922,7 @@ class DistrictCenterPage( content = StreamField( [ ("text", RichTextBlock()), - ("table", TableBlock()), + ("table", TableBlock(template="shared/blocks/table_block.html")), ], verbose_name="Obsah", blank=True, @@ -1039,7 +1039,7 @@ class DistrictCustomPage( content = StreamField( [ ("text", RichTextBlock()), - ("table", TableBlock()), + ("table", TableBlock(template="shared/blocks/table_block.html")), ("people_group", blocks.PeopleGroupListBlock()), ], verbose_name="Obsah", diff --git a/region/migrations/0035_alter_regionarticlepage_content.py b/region/migrations/0035_alter_regionarticlepage_content_and_more.py similarity index 60% rename from region/migrations/0035_alter_regionarticlepage_content.py rename to region/migrations/0035_alter_regionarticlepage_content_and_more.py index 2a4c8cc4..3b9a8aaa 100644 --- a/region/migrations/0035_alter_regionarticlepage_content.py +++ b/region/migrations/0035_alter_regionarticlepage_content_and_more.py @@ -1,5 +1,6 @@ -# Generated by Django 4.0.3 on 2022-04-28 08:35 +# Generated by Django 4.0.3 on 2022-04-28 09:31 +import wagtail.contrib.table_block.blocks import wagtail.core.blocks import wagtail.core.fields import wagtail.images.blocks @@ -93,4 +94,64 @@ class Migration(migrations.Migration): verbose_name="Článek", ), ), + migrations.AlterField( + model_name="regioncenterpage", + name="content", + field=wagtail.core.fields.StreamField( + [ + ("text", wagtail.core.blocks.RichTextBlock()), + ( + "table", + wagtail.contrib.table_block.blocks.TableBlock( + template="shared/blocks/table_block.html" + ), + ), + ], + blank=True, + verbose_name="Obsah", + ), + ), + migrations.AlterField( + model_name="regioncustompage", + name="content", + field=wagtail.core.fields.StreamField( + [ + ("text", wagtail.core.blocks.RichTextBlock()), + ( + "table", + wagtail.contrib.table_block.blocks.TableBlock( + template="shared/blocks/table_block.html" + ), + ), + ( + "people_group", + wagtail.core.blocks.StructBlock( + [ + ( + "group_title", + wagtail.core.blocks.CharBlock( + label="Titulek", required=True + ), + ), + ( + "person_list", + wagtail.core.blocks.ListBlock( + wagtail.core.blocks.PageChooserBlock( + label="Osoba", + page_type=[ + "district.DistrictPersonPage", + "region.RegionPersonPage", + ], + ), + label="List osob", + ), + ), + ] + ), + ), + ], + blank=True, + verbose_name="Obsah", + ), + ), ] diff --git a/region/models.py b/region/models.py index 109dfc95..5531f0f7 100644 --- a/region/models.py +++ b/region/models.py @@ -907,7 +907,7 @@ class RegionCenterPage( content = StreamField( [ ("text", RichTextBlock()), - ("table", TableBlock()), + ("table", TableBlock(template="shared/blocks/table_block.html")), ], verbose_name="Obsah", blank=True, @@ -1024,7 +1024,7 @@ class RegionCustomPage( content = StreamField( [ ("text", RichTextBlock()), - ("table", TableBlock()), + ("table", TableBlock(template="shared/blocks/table_block.html")), ("people_group", blocks.PeopleGroupListBlock()), ], verbose_name="Obsah", diff --git a/shared/templates/shared/blocks/table_block.html b/shared/templates/shared/blocks/table_block.html new file mode 100644 index 00000000..5adfe416 --- /dev/null +++ b/shared/templates/shared/blocks/table_block.html @@ -0,0 +1,49 @@ +{% load table_block_tags shared_filters %} + +<div class="my-6"> + <table class="table table--bordered content-block"> + {% if table_caption %} + <caption class="head-heavy-sm my-4">{{ table_caption }}</caption> + {% endif %} + {% if table_header %} + <thead> + <tr> + {% for column in table_header %} + {% with forloop.counter0 as col_index %} + <th scope="col" {% cell_classname 0 col_index %}> + {% if column.strip %} + {{ column.strip|markdown }} + {% endif %} + </th> + {% endwith %} + {% endfor %} + </tr> + </thead> + {% endif %} + <tbody> + {% for row in data %} + {% with forloop.counter0 as row_index %} + <tr> + {% for column in row %} + {% with forloop.counter0 as col_index %} + {% if first_col_is_header and forloop.first %} + <th scope="row" {% cell_classname row_index col_index table_header %}> + {% if column.strip %} + {{ column.strip|markdown }} + {% endif %} + </th> + {% else %} + <td {% cell_classname row_index col_index table_header %}> + {% if column.strip %} + {{ column.strip|markdown }} + {% endif %} + </td> + {% endif %} + {% endwith %} + {% endfor %} + </tr> + {% endwith %} + {% endfor %} + </tbody> + </table> +</div> diff --git a/uniweb/migrations/0025_alter_uniwebarticlepage_content.py b/uniweb/migrations/0025_alter_uniwebarticlepage_content.py index 500ab523..a9fc245a 100644 --- a/uniweb/migrations/0025_alter_uniwebarticlepage_content.py +++ b/uniweb/migrations/0025_alter_uniwebarticlepage_content.py @@ -1,4 +1,4 @@ -# Generated by Django 4.0.3 on 2022-04-28 08:35 +# Generated by Django 4.0.3 on 2022-04-28 09:31 import wagtail.core.blocks import wagtail.core.fields -- GitLab