diff --git a/majak/settings/base.py b/majak/settings/base.py index 9e4003c47823d311c1e1027ca0410a0d92e047ed..0f7c6d6a67c1aee5116fa8e7c8c7f7b09270e867 100644 --- a/majak/settings/base.py +++ b/majak/settings/base.py @@ -49,6 +49,7 @@ INSTALLED_APPS = [ "wagtail.contrib.forms", "wagtail.contrib.redirects", "wagtail.contrib.modeladmin", + "wagtail.contrib.table_block", "wagtail.embeds", "wagtail.sites", "wagtail.users", diff --git a/uniweb/migrations/0006_auto_20200911_1426.py b/uniweb/migrations/0006_auto_20200911_1426.py new file mode 100644 index 0000000000000000000000000000000000000000..4411c4f89f078ebe11fa2852ef8dbc3d7f503ff6 --- /dev/null +++ b/uniweb/migrations/0006_auto_20200911_1426.py @@ -0,0 +1,231 @@ +# Generated by Django 3.1.1 on 2020-09-11 12:26 + +import wagtail.contrib.table_block.blocks +import wagtail.core.blocks +import wagtail.core.fields +import wagtail.images.blocks +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("uniweb", "0005_auto_20200911_0050"), + ] + + operations = [ + migrations.AlterField( + model_name="uniwebflexiblepage", + name="content", + field=wagtail.core.fields.StreamField( + [ + ( + "title", + wagtail.core.blocks.CharBlock(icon="title", label="nadpis"), + ), + ( + "text", + wagtail.core.blocks.RichTextBlock( + features=[ + "h2", + "h3", + "h4", + "h5", + "bold", + "italic", + "ol", + "ul", + "hr", + "link", + "document-link", + "image", + "superscript", + "subscript", + "strikethrough", + "blockquote", + ], + label="text", + ), + ), + ( + "text_columns", + wagtail.core.blocks.StructBlock( + [ + ( + "left_text", + wagtail.core.blocks.RichTextBlock( + features=[ + "h2", + "h3", + "h4", + "h5", + "bold", + "italic", + "ol", + "ul", + "hr", + "link", + "document-link", + "image", + "superscript", + "subscript", + "strikethrough", + "blockquote", + ], + label="levý sloupec", + ), + ), + ( + "right_text", + wagtail.core.blocks.RichTextBlock( + features=[ + "h2", + "h3", + "h4", + "h5", + "bold", + "italic", + "ol", + "ul", + "hr", + "link", + "document-link", + "image", + "superscript", + "subscript", + "strikethrough", + "blockquote", + ], + label="pravý sloupec", + ), + ), + ] + ), + ), + ( + "gallery", + wagtail.core.blocks.ListBlock( + wagtail.images.blocks.ImageChooserBlock(label="obrázek"), + icon="image", + label="galerie", + ), + ), + ( + "table", + wagtail.contrib.table_block.blocks.TableBlock( + label="tabulka", template="uniweb/snippet_table.html" + ), + ), + ], + blank=True, + verbose_name="obsah stránky", + ), + ), + migrations.AlterField( + model_name="uniwebhomepage", + name="content", + field=wagtail.core.fields.StreamField( + [ + ( + "title", + wagtail.core.blocks.CharBlock(icon="title", label="nadpis"), + ), + ( + "text", + wagtail.core.blocks.RichTextBlock( + features=[ + "h2", + "h3", + "h4", + "h5", + "bold", + "italic", + "ol", + "ul", + "hr", + "link", + "document-link", + "image", + "superscript", + "subscript", + "strikethrough", + "blockquote", + ], + label="text", + ), + ), + ( + "text_columns", + wagtail.core.blocks.StructBlock( + [ + ( + "left_text", + wagtail.core.blocks.RichTextBlock( + features=[ + "h2", + "h3", + "h4", + "h5", + "bold", + "italic", + "ol", + "ul", + "hr", + "link", + "document-link", + "image", + "superscript", + "subscript", + "strikethrough", + "blockquote", + ], + label="levý sloupec", + ), + ), + ( + "right_text", + wagtail.core.blocks.RichTextBlock( + features=[ + "h2", + "h3", + "h4", + "h5", + "bold", + "italic", + "ol", + "ul", + "hr", + "link", + "document-link", + "image", + "superscript", + "subscript", + "strikethrough", + "blockquote", + ], + label="pravý sloupec", + ), + ), + ] + ), + ), + ( + "gallery", + wagtail.core.blocks.ListBlock( + wagtail.images.blocks.ImageChooserBlock(label="obrázek"), + icon="image", + label="galerie", + ), + ), + ( + "table", + wagtail.contrib.table_block.blocks.TableBlock( + label="tabulka", template="uniweb/snippet_table.html" + ), + ), + ], + blank=True, + verbose_name="obsah stránky", + ), + ), + ] diff --git a/uniweb/models.py b/uniweb/models.py index 427aaacc504fc0b23f87dacd81c5794aaac00f0d..6c6539e42c550423e72032188c87ecf8d4c219de 100644 --- a/uniweb/models.py +++ b/uniweb/models.py @@ -6,6 +6,7 @@ from wagtail.admin.edit_handlers import ( MultiFieldPanel, StreamFieldPanel, ) +from wagtail.contrib.table_block.blocks import TableBlock from wagtail.core import blocks from wagtail.core.fields import StreamField from wagtail.core.models import Page @@ -84,6 +85,10 @@ class UniwebHomePage(MetadataPageMixin, Page): ImageChooserBlock(label="obrázek"), label="galerie", icon="image" ), ), + ( + "table", + TableBlock(label="tabulka", template="uniweb/snippet_table.html",), + ), ], verbose_name="obsah stránky", blank=True, @@ -149,6 +154,10 @@ class UniwebFlexiblePage(Page, SubpageMixin, MetadataPageMixin): ImageChooserBlock(label="obrázek"), label="galerie", icon="image" ), ), + ( + "table", + TableBlock(label="tabulka", template="uniweb/snippet_table.html",), + ), ], verbose_name="obsah stránky", blank=True, diff --git a/uniweb/templates/uniweb/snippet_sections.html b/uniweb/templates/uniweb/snippet_sections.html index 6a6f7ec1744f0b3c9490e5829e1fb85f5804bdf5..fc8db88896967539cfe16b5083a63a45849625e0 100644 --- a/uniweb/templates/uniweb/snippet_sections.html +++ b/uniweb/templates/uniweb/snippet_sections.html @@ -8,7 +8,7 @@ {% endif %} {% if block.block_type == "text" %} - <div class="content-block w-full my-4 clearfix{% if forloop.first %} mt-8 lg:mt-12{% endif %}"> + <div class="content-block my-4 clearfix{% if forloop.first %} mt-8 lg:mt-12{% endif %}"> {{ block.value|richtext }} </div> {% endif %} @@ -36,5 +36,11 @@ </div> {% endif %} + {% if block.block_type == "table" %} + <div class="my-6{% if forloop.first %} mt-8 lg:mt-12{% endif %}"> + {% include_block block %} + </div> + {% endif %} + {% endfor %} </section> diff --git a/uniweb/templates/uniweb/snippet_table.html b/uniweb/templates/uniweb/snippet_table.html new file mode 100644 index 0000000000000000000000000000000000000000..eb2061b7d0857160f7e9ad9ad3efbedcbefebf76 --- /dev/null +++ b/uniweb/templates/uniweb/snippet_table.html @@ -0,0 +1,59 @@ +{% load table_block_tags %} + +<table class="table table--bordered table--condensed mx-auto"> + {% 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 %} + {% if html_renderer %} + {{ column.strip|safe|linebreaksbr }} + {% else %} + {{ column.strip|linebreaksbr }} + {% endif %} + {% 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 %} + {% if html_renderer %} + {{ column.strip|safe|linebreaksbr }} + {% else %} + {{ column.strip|linebreaksbr }} + {% endif %} + {% endif %} + </th> + {% else %} + <td {% cell_classname row_index col_index table_header %}> + {% if column.strip %} + {% if html_renderer %} + {{ column.strip|safe|linebreaksbr }} + {% else %} + {{ column.strip|linebreaksbr }} + {% endif %} + {% endif %} + </td> + {% endif %} + {% endwith %} + {% endfor %} + </tr> + {% endwith %} + {% endfor %} + </tbody> +</table>