From ce1c3a2b442ba25403cf637794ac6f63746b0809 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Bedna=C5=99=C3=ADk?= <jan.bednarik@gmail.com>
Date: Tue, 6 Oct 2020 11:23:01 +0200
Subject: [PATCH] senate: Candidates for second round

---
 ..._senatehomepage_candidates_second_round.py | 68 +++++++++++++++++++
 senate/models.py                              |  4 ++
 senate/templates/senate/senate_home_page.html | 41 +++++++----
 3 files changed, 99 insertions(+), 14 deletions(-)
 create mode 100644 senate/migrations/0004_senatehomepage_candidates_second_round.py

diff --git a/senate/migrations/0004_senatehomepage_candidates_second_round.py b/senate/migrations/0004_senatehomepage_candidates_second_round.py
new file mode 100644
index 00000000..883447fc
--- /dev/null
+++ b/senate/migrations/0004_senatehomepage_candidates_second_round.py
@@ -0,0 +1,68 @@
+# Generated by Django 3.1.1 on 2020-10-06 09:21
+
+import wagtail.core.blocks
+import wagtail.core.fields
+import wagtail.images.blocks
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ("senate", "0003_auto_20200702_1831"),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name="senatehomepage",
+            name="candidates_second_round",
+            field=wagtail.core.fields.StreamField(
+                [
+                    (
+                        "item",
+                        wagtail.core.blocks.StructBlock(
+                            [
+                                ("name", wagtail.core.blocks.CharBlock(label="jméno")),
+                                (
+                                    "district",
+                                    wagtail.core.blocks.CharBlock(label="obvod"),
+                                ),
+                                (
+                                    "info",
+                                    wagtail.core.blocks.CharBlock(
+                                        label="info o nominaci"
+                                    ),
+                                ),
+                                (
+                                    "phone",
+                                    wagtail.core.blocks.CharBlock(
+                                        label="telefon", required=False
+                                    ),
+                                ),
+                                (
+                                    "email",
+                                    wagtail.core.blocks.EmailBlock(
+                                        label="email", required=False
+                                    ),
+                                ),
+                                (
+                                    "web",
+                                    wagtail.core.blocks.URLBlock(
+                                        label="web", required=False
+                                    ),
+                                ),
+                                (
+                                    "photo",
+                                    wagtail.images.blocks.ImageChooserBlock(
+                                        label="fotka"
+                                    ),
+                                ),
+                            ]
+                        ),
+                    )
+                ],
+                blank=True,
+                verbose_name="kandidáti do 2. kola",
+            ),
+        ),
+    ]
diff --git a/senate/models.py b/senate/models.py
index 7e21a672..7dea69db 100644
--- a/senate/models.py
+++ b/senate/models.py
@@ -39,6 +39,9 @@ class SenateHomePage(MetadataPageMixin, Page):
     candidates = StreamField(
         [("item", PersonBlock())], verbose_name="kandidáti", blank=True
     )
+    candidates_second_round = StreamField(
+        [("item", PersonBlock())], verbose_name="kandidáti do 2. kola", blank=True
+    )
     matomo_id = models.IntegerField(
         "Matomo ID pro sledování návštěvnosti", blank=True, null=True
     )
@@ -48,6 +51,7 @@ class SenateHomePage(MetadataPageMixin, Page):
     content_panels = Page.content_panels + [
         StreamFieldPanel("senators"),
         StreamFieldPanel("candidates"),
+        StreamFieldPanel("candidates_second_round"),
     ]
 
     promote_panels = [
diff --git a/senate/templates/senate/senate_home_page.html b/senate/templates/senate/senate_home_page.html
index be3dba3f..7069d5ac 100644
--- a/senate/templates/senate/senate_home_page.html
+++ b/senate/templates/senate/senate_home_page.html
@@ -8,24 +8,37 @@
     <div class="container my-5">
       <div class="row">
         <div class="col-lg-12">
-          <h2 class="headline-normal">Kandidáti do Senátu</h2>
 
-          <div class="row">
-          {% for person in page.candidates %}
-            {% include "senate/person_snippet.html" %}
-          {% endfor %}
-          </div>
+          {% if page.candidates_second_round %}
+            <h2 class="headline-normal">Kandidáti postupující do 2. kola senátních voleb</h2>
+            <div class="row">
+            {% for person in page.candidates_second_round %}
+              {% include "senate/person_snippet.html" %}
+            {% endfor %}
+            </div>
+            <hr class="my-4">
+          {% endif %}
 
-          <hr class="my-4">
-          <h2 class="headline-normal">Naši Senátoři</h2>
+          {% if page.candidates %}
+            <h2 class="headline-normal">Kandidáti do Senátu</h2>
+            <div class="row">
+            {% for person in page.candidates %}
+              {% include "senate/person_snippet.html" %}
+            {% endfor %}
+            </div>
+            <hr class="my-4">
+          {% endif %}
 
-          <div class="row">
-          {% for person in page.senators %}
-            {% include "senate/person_snippet.html" %}
-          {% endfor %}
-          </div>
+          {% if page.senators %}
+            <h2 class="headline-normal">Naši Senátoři</h2>
+            <div class="row">
+            {% for person in page.senators %}
+              {% include "senate/person_snippet.html" %}
+            {% endfor %}
+            </div>
+            <hr class="my-4">
+          {% endif %}
 
-          <hr class="my-4">
         </div>
       </div>
     </div>
-- 
GitLab