From a559b5feb658702ac3fd6e492e430373f7a49911 Mon Sep 17 00:00:00 2001
From: Ondrej Rehounek <ondra.rehounek@seznam.cz>
Date: Sun, 28 Nov 2021 17:13:46 +0100
Subject: [PATCH] district and region:More custom settings for candidate list

---
 district/blocks.py                            |  8 ++
 ...0030_alter_districtelectionpage_content.py | 83 +++++++++++++++++++
 .../district/blocks/candidate_list_block.html | 14 ++--
 region/blocks.py                              |  8 ++
 .../0007_alter_regionelectionpage_content.py  | 83 +++++++++++++++++++
 .../region/blocks/candidate_list_block.html   | 16 ++--
 6 files changed, 197 insertions(+), 15 deletions(-)
 create mode 100644 district/migrations/0030_alter_districtelectionpage_content.py
 create mode 100644 region/migrations/0007_alter_regionelectionpage_content.py

diff --git a/district/blocks.py b/district/blocks.py
index 4bf6dc93..9915b424 100644
--- a/district/blocks.py
+++ b/district/blocks.py
@@ -45,6 +45,14 @@ class CandidateListBlock(StructBlock):
     call_to_action_button_text = CharBlock(
         label="Text tlačítka 'call-to-action' baneru", max_length=24, required=False
     )
+    candidate_list_big_count = IntegerBlock(
+        label="Počet kanditátů s velkým náhledem", default=7
+    )
+    candidate_list_shown_count = IntegerBlock(
+        label="Počet zobrazených kandidátů při načtení stránky (včetně velkých náhledů)",
+        default=16,
+    )
+
     candidate_list = ListBlock(
         PageChooserBlock(label="Osoba", page_type=["district.DistrictPersonPage"]),
         label="Kandidáti",
diff --git a/district/migrations/0030_alter_districtelectionpage_content.py b/district/migrations/0030_alter_districtelectionpage_content.py
new file mode 100644
index 00000000..ad7705f0
--- /dev/null
+++ b/district/migrations/0030_alter_districtelectionpage_content.py
@@ -0,0 +1,83 @@
+# Generated by Django 3.2.8 on 2021-11-28 16:13
+
+import wagtail.core.blocks
+import wagtail.core.fields
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ("district", "0029_alter_districtcenterpage_sidebar_content"),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name="districtelectionpage",
+            name="content",
+            field=wagtail.core.fields.StreamField(
+                [
+                    (
+                        "candidate_list",
+                        wagtail.core.blocks.StructBlock(
+                            [
+                                (
+                                    "title",
+                                    wagtail.core.blocks.CharBlock(
+                                        label="Titulek", required=True
+                                    ),
+                                ),
+                                (
+                                    "call_to_action_text",
+                                    wagtail.core.blocks.CharBlock(
+                                        label="Text 'call-to-action' baneru"
+                                    ),
+                                ),
+                                (
+                                    "call_to_action_link",
+                                    wagtail.core.blocks.URLBlock(
+                                        label="Odkaz 'call-to-action' baneru",
+                                        required=False,
+                                    ),
+                                ),
+                                (
+                                    "call_to_action_button_text",
+                                    wagtail.core.blocks.CharBlock(
+                                        label="Text tlačítka 'call-to-action' baneru",
+                                        max_length=24,
+                                        required=False,
+                                    ),
+                                ),
+                                (
+                                    "candidate_list_big_count",
+                                    wagtail.core.blocks.IntegerBlock(
+                                        default=7,
+                                        label="Počet kanditátů s velkým náhledem",
+                                    ),
+                                ),
+                                (
+                                    "candidate_list_shown_count",
+                                    wagtail.core.blocks.IntegerBlock(
+                                        default=16,
+                                        label="Počet zobrazených kandidátů při načtení stránky (včetně velkých náhledů)",
+                                    ),
+                                ),
+                                (
+                                    "candidate_list",
+                                    wagtail.core.blocks.ListBlock(
+                                        wagtail.core.blocks.PageChooserBlock(
+                                            label="Osoba",
+                                            page_type=["district.DistrictPersonPage"],
+                                        ),
+                                        label="Kandidáti",
+                                    ),
+                                ),
+                            ]
+                        ),
+                    )
+                ],
+                blank=True,
+                verbose_name="Obsah stránky",
+            ),
+        ),
+    ]
diff --git a/district/templates/district/blocks/candidate_list_block.html b/district/templates/district/blocks/candidate_list_block.html
index 8b08652d..1d9702be 100644
--- a/district/templates/district/blocks/candidate_list_block.html
+++ b/district/templates/district/blocks/candidate_list_block.html
@@ -1,10 +1,10 @@
-
 <h1 class="head-alt-md text-center py-8 lg:pt-24 lg:pb-8">
-  Kandidáti do zastupitelstva Pardubického kraje
+  {{ self.title }}
 </h1>
+
 <div class="candidate-card-list grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4">
   {% for person_page in self.candidate_list %}
-    {% if forloop.counter < 8 %}
+    {% if forloop.counter <= self.candidate_list_big_count %}
       {% include "shared/full_candidate_snippet.html" %}
     {% endif %}
   {% endfor %}
@@ -29,15 +29,15 @@
     <div class="candidate-table pt-8 container-padding--zero lg:container-padding--auto"
          :class="{'candidate-table--fadeout': !isCurrentView('fullCandidateTable')}">
       {% for person_page in self.candidate_list %}
-        {# Záměrně neomezuju list přes indexy, abych si držel counter pro snippet #}
-        {% if forloop.counter >= 8 and forloop.counter < 16  %}
+        {# Záměrně neomezuju list přes indexy, ale ifuju, abych si držel counter pro snippet #}
+        {% if forloop.counter > self.candidate_list_big_count and forloop.counter <= self.candidate_list_shown_count  %}
           {% include "shared/compact_candidate_snippet.html" %}
         {% endif %}
       {% endfor %}
       <template v-if="isCurrentView('fullCandidateTable')">
         {% for person_page in self.candidate_list %}
-          {# Záměrně neomezuju list přes indexy, abych si držel counter pro snippet #}
-          {% if forloop.counter >= 16  %}
+          {# Záměrně neomezuju list přes indexy, ale ifuju, abych si držel counter pro snippet #}
+          {% if forloop.counter > self.candidate_list_shown_count  %}
             {% include "shared/compact_candidate_snippet.html" %}
           {% endif %}
         {% endfor %}
diff --git a/region/blocks.py b/region/blocks.py
index 9e2eacd5..7ec56447 100644
--- a/region/blocks.py
+++ b/region/blocks.py
@@ -45,6 +45,14 @@ class CandidateListBlock(StructBlock):
     call_to_action_button_text = CharBlock(
         label="Text tlačítka 'call-to-action' baneru", max_length=24, required=False
     )
+    candidate_list_big_count = IntegerBlock(
+        label="Počet kanditátů s velkým náhledem", default=7
+    )
+    candidate_list_shown_count = IntegerBlock(
+        label="Počet zobrazených kandidátů při načtení stránky (včetně velkých náhledů)",
+        default=16,
+    )
+
     candidate_list = ListBlock(
         PageChooserBlock(label="Osoba", page_type=["region.RegionPersonPage"]),
         label="Kandidáti",
diff --git a/region/migrations/0007_alter_regionelectionpage_content.py b/region/migrations/0007_alter_regionelectionpage_content.py
new file mode 100644
index 00000000..71ff15f4
--- /dev/null
+++ b/region/migrations/0007_alter_regionelectionpage_content.py
@@ -0,0 +1,83 @@
+# Generated by Django 3.2.8 on 2021-11-28 16:13
+
+import wagtail.core.blocks
+import wagtail.core.fields
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ("region", "0006_alter_regioncenterpage_sidebar_content"),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name="regionelectionpage",
+            name="content",
+            field=wagtail.core.fields.StreamField(
+                [
+                    (
+                        "candidate_list",
+                        wagtail.core.blocks.StructBlock(
+                            [
+                                (
+                                    "title",
+                                    wagtail.core.blocks.CharBlock(
+                                        label="Titulek", required=True
+                                    ),
+                                ),
+                                (
+                                    "call_to_action_text",
+                                    wagtail.core.blocks.CharBlock(
+                                        label="Text 'call-to-action' baneru"
+                                    ),
+                                ),
+                                (
+                                    "call_to_action_link",
+                                    wagtail.core.blocks.URLBlock(
+                                        label="Odkaz 'call-to-action' baneru",
+                                        required=False,
+                                    ),
+                                ),
+                                (
+                                    "call_to_action_button_text",
+                                    wagtail.core.blocks.CharBlock(
+                                        label="Text tlačítka 'call-to-action' baneru",
+                                        max_length=24,
+                                        required=False,
+                                    ),
+                                ),
+                                (
+                                    "candidate_list_big_count",
+                                    wagtail.core.blocks.IntegerBlock(
+                                        default=7,
+                                        label="Počet kanditátů s velkým náhledem",
+                                    ),
+                                ),
+                                (
+                                    "candidate_list_shown_count",
+                                    wagtail.core.blocks.IntegerBlock(
+                                        default=16,
+                                        label="Počet zobrazených kandidátů při načtení stránky (včetně velkých náhledů)",
+                                    ),
+                                ),
+                                (
+                                    "candidate_list",
+                                    wagtail.core.blocks.ListBlock(
+                                        wagtail.core.blocks.PageChooserBlock(
+                                            label="Osoba",
+                                            page_type=["region.RegionPersonPage"],
+                                        ),
+                                        label="Kandidáti",
+                                    ),
+                                ),
+                            ]
+                        ),
+                    )
+                ],
+                blank=True,
+                verbose_name="Obsah stránky",
+            ),
+        ),
+    ]
diff --git a/region/templates/region/blocks/candidate_list_block.html b/region/templates/region/blocks/candidate_list_block.html
index 8b08652d..06df7bad 100644
--- a/region/templates/region/blocks/candidate_list_block.html
+++ b/region/templates/region/blocks/candidate_list_block.html
@@ -1,15 +1,15 @@
-
 <h1 class="head-alt-md text-center py-8 lg:pt-24 lg:pb-8">
-  Kandidáti do zastupitelstva Pardubického kraje
+  {{ self.title }}
 </h1>
+
 <div class="candidate-card-list grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4">
   {% for person_page in self.candidate_list %}
-    {% if forloop.counter < 8 %}
+    {% if forloop.counter <= self.candidate_list_big_count %}
       {% include "shared/full_candidate_snippet.html" %}
     {% endif %}
   {% endfor %}
   <aside class="banner bg-black text-white container-padding--zero sm:container-padding--auto">
-    <i class="ico--pirati banner__icon"></i>
+    <i class="ico--pirati banner__icon"></i>k
     <div class="banner__body">
       <h1 class="head-alt-lg banner__cta">
         {{ self.call_to_action_text }}
@@ -29,15 +29,15 @@
     <div class="candidate-table pt-8 container-padding--zero lg:container-padding--auto"
          :class="{'candidate-table--fadeout': !isCurrentView('fullCandidateTable')}">
       {% for person_page in self.candidate_list %}
-        {# Záměrně neomezuju list přes indexy, abych si držel counter pro snippet #}
-        {% if forloop.counter >= 8 and forloop.counter < 16  %}
+        {# Záměrně neomezuju list přes indexy, ale ifuju, abych si držel counter pro snippet #}
+        {% if forloop.counter > self.candidate_list_big_count and forloop.counter <= self.candidate_list_shown_count  %}
           {% include "shared/compact_candidate_snippet.html" %}
         {% endif %}
       {% endfor %}
       <template v-if="isCurrentView('fullCandidateTable')">
         {% for person_page in self.candidate_list %}
-          {# Záměrně neomezuju list přes indexy, abych si držel counter pro snippet #}
-          {% if forloop.counter >= 16  %}
+          {# Záměrně neomezuju list přes indexy, ale ifuju, abych si držel counter pro snippet #}
+          {% if forloop.counter > self.candidate_list_shown_count  %}
             {% include "shared/compact_candidate_snippet.html" %}
           {% endif %}
         {% endfor %}
-- 
GitLab