From 0222ec389373ba9835203f010adc046fef388fde Mon Sep 17 00:00:00 2001
From: Ondrej Rehounek <ondra.rehounek@seznam.cz>
Date: Tue, 9 Nov 2021 07:57:00 +0100
Subject: [PATCH] district: fix vars in homepage header block, region: prepare
 homepage block

---
 district/blocks.py                             |  3 +--
 .../district/blocks/homepage_header_block.html |  9 ++++++---
 region/blocks.py                               | 18 ++++++++++++++++++
 region/models.py                               |  2 ++
 .../region/blocks/homepage_header_block.html   |  0
 5 files changed, 27 insertions(+), 5 deletions(-)
 create mode 100644 region/blocks.py
 create mode 100644 region/templates/region/blocks/homepage_header_block.html

diff --git a/district/blocks.py b/district/blocks.py
index 950a9488..7be87e52 100644
--- a/district/blocks.py
+++ b/district/blocks.py
@@ -1,5 +1,4 @@
 from django.forms import Select
-from wagtail.contrib.table_block.blocks import TableBlock
 from wagtail.core.blocks import (
     CharBlock,
     ChooserBlock,
@@ -46,7 +45,7 @@ class ProgramItemBlock(StructBlock):
 class ProgramBlock(StructBlock):
     headline = CharBlock(label="Titulek bloku", required=True)
     perex = TextBlock(label="Krátký text pod nadpisem", required=True)
-    person = PersonChooserBlock(label="Osoba", required=True)
+    person = PersonChooserBlock(label="Osoba", required=True)  # TODO Page chooser block should suffice
     completion_percentage = IntegerBlock(label="Procento dokončení", required=True)
     program_items = ListBlock(ProgramItemBlock())
     # program_items = TableBlock(label="Tabulka plnění programu", required=True)
diff --git a/district/templates/district/blocks/homepage_header_block.html b/district/templates/district/blocks/homepage_header_block.html
index bf9c6076..c6aed45f 100644
--- a/district/templates/district/blocks/homepage_header_block.html
+++ b/district/templates/district/blocks/homepage_header_block.html
@@ -1,13 +1,16 @@
+{% load wagtailimages_tags %}
+
+{% image self.image width-1920 as img %}
 <header
   class="hero hero--image py-16 "
-  style="--image-url: url(https://praha8.pirati.cz/assets/posts/libensky-zamek-c76ce3fd0a7d061e15025fbb7080f4dbd12fab3daebdcbd42d2ab6b1cdbaa2f0.jpg)"
+  style="--image-url: url({{ img.url }})"
 >
   <div class="container container--default">
     <h1 class="head-alt-md md:head-alt-lg max-w-2xl ">
-      Piráti Praha 8
+      {{ self.title }}
     </h1>
     <h2 class="head-xs mt-2 ">
-      Makáme v opozici. Držíme směr!
+      {{ self.subtitle }}
     </h2>
   </div>
 </header>
diff --git a/region/blocks.py b/region/blocks.py
new file mode 100644
index 00000000..117fe917
--- /dev/null
+++ b/region/blocks.py
@@ -0,0 +1,18 @@
+from wagtail.core.blocks import (
+    CharBlock,
+    StructBlock,
+    URLBlock,
+)
+from wagtail.images.blocks import ImageChooserBlock
+
+
+class HomepageHeaderBlock(StructBlock):
+    title = CharBlock(label="Titulek", required=True)
+    image = ImageChooserBlock()
+    button_text = CharBlock(label="Titulek", required=False)
+    button_link = URLBlock(label="Odkaz tlačítka", required=False)
+
+    class Meta:
+        template = "region/blocks/homepage_header_block.html"
+        icon = "image"
+        label = "Nadpis s obrázkem"
diff --git a/region/models.py b/region/models.py
index 81ed0d9f..e781bffd 100644
--- a/region/models.py
+++ b/region/models.py
@@ -182,6 +182,7 @@ class RegionArticlePage(ArticleMixin, SubpageMixin, MetadataPageMixin, Page):
 
 
 class RegionArticlesPage(SubpageMixin, MetadataPageMixin, Page):
+    # TODO this page is very similar to DistrictArticletPage and seem to remain so
     ### FIELDS
 
     max_items = models.IntegerField("Počet článků na stránce", default=12)
@@ -214,6 +215,7 @@ class RegionArticlesPage(SubpageMixin, MetadataPageMixin, Page):
 
 
 class RegionContactPage(SubpageMixin, MetadataPageMixin, Page):
+    # TODO this page is exactly as DistrictContactPage and seem to remain so
     class ContactItemBlock(blocks.StructBlock):
         name = blocks.CharBlock(label="Role")
         person = blocks.PageChooserBlock(
diff --git a/region/templates/region/blocks/homepage_header_block.html b/region/templates/region/blocks/homepage_header_block.html
new file mode 100644
index 00000000..e69de29b
-- 
GitLab