From 8ec7648c4390367b80524d6ab97a44de65f40612 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Bedna=C5=99=C3=ADk?= <jan.bednarik@gmail.com>
Date: Thu, 10 Sep 2020 00:03:07 +0200
Subject: [PATCH] uniweb: Double columns section

---
 uniweb/migrations/0003_auto_20200909_2354.py  | 274 ++++++++++++++++++
 uniweb/models.py                              |  13 +
 uniweb/templates/uniweb/snippet_sections.html |  11 +
 3 files changed, 298 insertions(+)
 create mode 100644 uniweb/migrations/0003_auto_20200909_2354.py

diff --git a/uniweb/migrations/0003_auto_20200909_2354.py b/uniweb/migrations/0003_auto_20200909_2354.py
new file mode 100644
index 00000000..0f63dcdc
--- /dev/null
+++ b/uniweb/migrations/0003_auto_20200909_2354.py
@@ -0,0 +1,274 @@
+# Generated by Django 3.1.1 on 2020-09-09 21:54
+
+import wagtail.core.blocks
+import wagtail.core.fields
+import wagtail.images.blocks
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ("uniweb", "0002_auto_20200908_2354"),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name="uniwebflexiblepage",
+            name="content",
+            field=wagtail.core.fields.StreamField(
+                [
+                    (
+                        "text_section",
+                        wagtail.core.blocks.StructBlock(
+                            [
+                                (
+                                    "title",
+                                    wagtail.core.blocks.CharBlock(
+                                        label="nadpis", required=False
+                                    ),
+                                ),
+                                (
+                                    "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",
+                                    ),
+                                ),
+                            ]
+                        ),
+                    ),
+                    (
+                        "columns_section",
+                        wagtail.core.blocks.StructBlock(
+                            [
+                                (
+                                    "title",
+                                    wagtail.core.blocks.CharBlock(
+                                        label="nadpis", required=False
+                                    ),
+                                ),
+                                (
+                                    "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="text",
+                                    ),
+                                ),
+                                (
+                                    "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="text",
+                                    ),
+                                ),
+                            ]
+                        ),
+                    ),
+                    (
+                        "gallery_section",
+                        wagtail.core.blocks.StructBlock(
+                            [
+                                (
+                                    "title",
+                                    wagtail.core.blocks.CharBlock(
+                                        label="nadpis", required=False
+                                    ),
+                                ),
+                                (
+                                    "images",
+                                    wagtail.core.blocks.ListBlock(
+                                        wagtail.images.blocks.ImageChooserBlock(
+                                            label="obrázek"
+                                        )
+                                    ),
+                                ),
+                            ]
+                        ),
+                    ),
+                ],
+                blank=True,
+                verbose_name="obsah stránky",
+            ),
+        ),
+        migrations.AlterField(
+            model_name="uniwebhomepage",
+            name="content",
+            field=wagtail.core.fields.StreamField(
+                [
+                    (
+                        "text_section",
+                        wagtail.core.blocks.StructBlock(
+                            [
+                                (
+                                    "title",
+                                    wagtail.core.blocks.CharBlock(
+                                        label="nadpis", required=False
+                                    ),
+                                ),
+                                (
+                                    "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",
+                                    ),
+                                ),
+                            ]
+                        ),
+                    ),
+                    (
+                        "columns_section",
+                        wagtail.core.blocks.StructBlock(
+                            [
+                                (
+                                    "title",
+                                    wagtail.core.blocks.CharBlock(
+                                        label="nadpis", required=False
+                                    ),
+                                ),
+                                (
+                                    "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="text",
+                                    ),
+                                ),
+                                (
+                                    "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="text",
+                                    ),
+                                ),
+                            ]
+                        ),
+                    ),
+                    (
+                        "gallery_section",
+                        wagtail.core.blocks.StructBlock(
+                            [
+                                (
+                                    "title",
+                                    wagtail.core.blocks.CharBlock(
+                                        label="nadpis", required=False
+                                    ),
+                                ),
+                                (
+                                    "images",
+                                    wagtail.core.blocks.ListBlock(
+                                        wagtail.images.blocks.ImageChooserBlock(
+                                            label="obrázek"
+                                        )
+                                    ),
+                                ),
+                            ]
+                        ),
+                    ),
+                ],
+                blank=True,
+                verbose_name="obsah stránky",
+            ),
+        ),
+    ]
diff --git a/uniweb/models.py b/uniweb/models.py
index ecb4cbb0..ddca6ef0 100644
--- a/uniweb/models.py
+++ b/uniweb/models.py
@@ -43,6 +43,17 @@ class TextSectionBlock(blocks.StructBlock):
         label = "textová sekce"
 
 
+class ColumnsSectionBlock(blocks.StructBlock):
+    title = blocks.CharBlock(label="nadpis", required=False)
+    left_text = blocks.RichTextBlock(label="levý sloupec", features=RICH_TEXT_FEATURES)
+    right_text = blocks.RichTextBlock(
+        label="pravý sloupec", features=RICH_TEXT_FEATURES
+    )
+
+    class Meta:
+        label = "dvousloupcová textová sekce"
+
+
 class GallerySectionBlock(blocks.StructBlock):
     title = blocks.CharBlock(label="nadpis", required=False)
     images = blocks.ListBlock(ImageChooserBlock(label="obrázek"))
@@ -81,6 +92,7 @@ class UniwebHomePage(MetadataPageMixin, Page):
     content = StreamField(
         [
             ("text_section", TextSectionBlock()),
+            ("columns_section", ColumnsSectionBlock()),
             ("gallery_section", GallerySectionBlock()),
         ],
         verbose_name="obsah stránky",
@@ -139,6 +151,7 @@ class UniwebFlexiblePage(Page, SubpageMixin, MetadataPageMixin):
     content = StreamField(
         [
             ("text_section", TextSectionBlock()),
+            ("columns_section", ColumnsSectionBlock()),
             ("gallery_section", GallerySectionBlock()),
         ],
         verbose_name="obsah stránky",
diff --git a/uniweb/templates/uniweb/snippet_sections.html b/uniweb/templates/uniweb/snippet_sections.html
index 277fe9e3..59c19190 100644
--- a/uniweb/templates/uniweb/snippet_sections.html
+++ b/uniweb/templates/uniweb/snippet_sections.html
@@ -13,6 +13,17 @@
   </div>
   {% endif %}
 
+  {% if section.block_type == "columns_section" %}
+  <div class="lg:flex">
+    <div class="content-block lg:w-1/2 lg:pr-5 my-4">
+      {{ section.value.left_text|richtext }}
+    </div>
+    <div class="content-block lg:w-1/2 lg:pl-5 my-4">
+      {{ section.value.right_text|richtext }}
+    </div>
+  </div>
+  {% endif %}
+
   {% if section.block_type == "gallery_section" %}
   <div class="content-block w-full my-6 grid grid-cols-4 gap-4">
     {% for picture in section.value.images %}
-- 
GitLab