From 9db6952ba4c1f8437a25b25a306ba822f0bd7fc5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Bedna=C5=99=C3=ADk?= <jan.bednarik@gmail.com>
Date: Thu, 2 Sep 2021 16:18:40 +0200
Subject: [PATCH] elections2021: Text downloads

---
 ...ections2021downloadspage_text_downloads.py | 40 +++++++++++++++++++
 elections2021/models.py                       | 19 ++++++++-
 .../elections2021_downloads_page.html         | 10 +++++
 3 files changed, 68 insertions(+), 1 deletion(-)
 create mode 100644 elections2021/migrations/0046_elections2021downloadspage_text_downloads.py

diff --git a/elections2021/migrations/0046_elections2021downloadspage_text_downloads.py b/elections2021/migrations/0046_elections2021downloadspage_text_downloads.py
new file mode 100644
index 00000000..af3f3f6f
--- /dev/null
+++ b/elections2021/migrations/0046_elections2021downloadspage_text_downloads.py
@@ -0,0 +1,40 @@
+# Generated by Django 3.2.6 on 2021-09-02 08:40
+
+import wagtail.core.blocks
+import wagtail.core.fields
+import wagtail.documents.blocks
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ("elections2021", "0045_elections2021homepage_program_silver_page"),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name="elections2021downloadspage",
+            name="text_downloads",
+            field=wagtail.core.fields.StreamField(
+                [
+                    (
+                        "document",
+                        wagtail.core.blocks.StructBlock(
+                            [
+                                ("title", wagtail.core.blocks.CharBlock(label="název")),
+                                (
+                                    "document",
+                                    wagtail.documents.blocks.DocumentChooserBlock(
+                                        label="dokument"
+                                    ),
+                                ),
+                            ]
+                        ),
+                    )
+                ],
+                blank=True,
+                verbose_name="textové soubory ke stažení",
+            ),
+        ),
+    ]
diff --git a/elections2021/models.py b/elections2021/models.py
index 52ccce66..b34d162c 100644
--- a/elections2021/models.py
+++ b/elections2021/models.py
@@ -2286,6 +2286,15 @@ class DownloadSpotifyBlock(blocks.StructBlock):
         template = "elections2021/_download_spotify_block.html"
 
 
+class DownloadTextDocumentBlock(blocks.StructBlock):
+    title = blocks.CharBlock(label="název")
+    document = DocumentChooserBlock(label="dokument")
+
+    class Meta:
+        label = "dokument ke stažení"
+        icon = "doc-full"
+
+
 class Elections2021DownloadsPage(SubpageMixin, MetadataPageMixin, Page):
     ### FIELDS
 
@@ -2294,10 +2303,18 @@ class Elections2021DownloadsPage(SubpageMixin, MetadataPageMixin, Page):
         verbose_name="soubory ke stažení",
         blank=True,
     )
+    text_downloads = StreamField(
+        [("document", DownloadTextDocumentBlock())],
+        verbose_name="textové soubory ke stažení",
+        blank=True,
+    )
 
     ### PANELS
 
-    content_panels = Page.content_panels + [StreamFieldPanel("downloads")]
+    content_panels = Page.content_panels + [
+        StreamFieldPanel("downloads"),
+        StreamFieldPanel("text_downloads"),
+    ]
 
     promote_panels = [
         MultiFieldPanel(
diff --git a/elections2021/templates/elections2021/elections2021_downloads_page.html b/elections2021/templates/elections2021/elections2021_downloads_page.html
index c6d26a0e..6d41b23c 100644
--- a/elections2021/templates/elections2021/elections2021_downloads_page.html
+++ b/elections2021/templates/elections2021/elections2021_downloads_page.html
@@ -14,6 +14,16 @@
           {% include_block block %}
         {% endfor %}
       </div>
+      {% if page.text_downloads %}
+        <h1 class="head-alt-md pb-4 lg:pb-8 mt-16">OSTATNÍ</h1>
+        <div class="content-block">
+          <ul class="unordered-list unordered-list-colored">
+            {% for block in page.text_downloads %}
+              <li><a href="{{ block.value.document.url }}">{{ block.value.title }}</a></li>
+            {% endfor %}
+          </ul>
+        </div>
+      {% endif %}
     </main>
   </section>
 </div>
-- 
GitLab