From 5292b2d36d8201b8f974d04f59ba3fc4fc718ca0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomi=20Valentov=C3=A1?= <git@imaniti.org>
Date: Tue, 23 Jul 2024 14:49:56 +0200
Subject: [PATCH] custom background image for programs

---
 ...259_districtnewprogrampage_header_image.py | 20 ++++++++++++++++
 district/models.py                            | 23 +++++++++++++++++++
 shared/models/main.py                         |  7 ++++++
 .../organisms/header/simple_header.html       |  6 +++++
 .../templates/styleguide2/program_page.html   |  2 +-
 5 files changed, 57 insertions(+), 1 deletion(-)
 create mode 100644 district/migrations/0259_districtnewprogrampage_header_image.py

diff --git a/district/migrations/0259_districtnewprogrampage_header_image.py b/district/migrations/0259_districtnewprogrampage_header_image.py
new file mode 100644
index 00000000..f91ece6b
--- /dev/null
+++ b/district/migrations/0259_districtnewprogrampage_header_image.py
@@ -0,0 +1,20 @@
+# Generated by Django 5.0.6 on 2024-07-23 12:26
+
+import django.db.models.deletion
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('district', '0258_alter_districtnewprogrampage_program'),
+        ('wagtailimages', '0026_delete_uploadedimage'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='districtnewprogrampage',
+            name='header_image',
+            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='+', to='wagtailimages.image', verbose_name='Obrázek na pozadí hlavičky'),
+        ),
+    ]
diff --git a/district/models.py b/district/models.py
index e3e8f2c6..4ee9414e 100644
--- a/district/models.py
+++ b/district/models.py
@@ -579,11 +579,34 @@ class DistrictNewProgramPage(MainProgramPageMixin):
         use_json_field=True,
     )
 
+    header_image = models.ForeignKey(
+        "wagtailimages.Image",
+        on_delete=models.PROTECT,
+        blank=True,
+        null=True,
+        verbose_name="Obrázek na pozadí hlavičky",
+        related_name="+",
+    )
+
     ### RELATIONS
 
     parent_page_types = ["district.DistrictHomePage"]
     subpage_types = ["district.DistrictCustomPage"]
 
+    ### PANELS
+
+    settings_panels = [
+        FieldPanel("header_image")
+    ]
+
+    edit_handler = TabbedInterface(
+        [
+            ObjectList(MainProgramPageMixin.content_panels, heading="Obsah"),
+            ObjectList(settings_panels, heading="Nastavení"),
+            ObjectList(MainProgramPageMixin.promote_panels, heading="Metadata"),
+        ]
+    )
+
 
 class DistrictCrossroadPage(
     ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, PageInMenuMixin, Page
diff --git a/shared/models/main.py b/shared/models/main.py
index 10a792ba..0f2cd594 100644
--- a/shared/models/main.py
+++ b/shared/models/main.py
@@ -2040,6 +2040,13 @@ class MainProgramPageMixin(
 
     settings_panels = []
 
+    edit_handler = TabbedInterface(
+        [
+            ObjectList(content_panels, heading="Obsah"),
+            ObjectList(promote_panels, heading="Metadata"),
+        ]
+    )
+
     ### RELATIONS
 
     # NOTE: Needs to be overridden
diff --git a/shared/templates/styleguide2/includes/organisms/header/simple_header.html b/shared/templates/styleguide2/includes/organisms/header/simple_header.html
index cb728a4e..ce420155 100644
--- a/shared/templates/styleguide2/includes/organisms/header/simple_header.html
+++ b/shared/templates/styleguide2/includes/organisms/header/simple_header.html
@@ -1,3 +1,5 @@
+{% load wagtailimages_tags %}
+
 {% if show_scroll_progress %}
   <div class="__js-root">
     <ui-scroll-indicator></ui-scroll-indicator>
@@ -33,6 +35,10 @@
     "
 
     {% if background_image %}
+      {% if not background_image.url %}
+        {% image background_image fill-1920x1080 as background_image %}
+      {% endif %}
+
       style="background-image:url('{{ background_image.url }}')"
     {% endif %}
   >
diff --git a/shared/templates/styleguide2/program_page.html b/shared/templates/styleguide2/program_page.html
index f4ebac4b..51363075 100644
--- a/shared/templates/styleguide2/program_page.html
+++ b/shared/templates/styleguide2/program_page.html
@@ -13,7 +13,7 @@
       :sync-location="true"
       v-slot="{ isCurrentView, toggleView }"
     >
-      {% include 'styleguide2/includes/organisms/header/simple_header_with_ui_switch.html' with title=page.title ui_switch_iterable=page.program %}
+      {% include 'styleguide2/includes/organisms/header/simple_header_with_ui_switch.html' with title=page.title ui_switch_iterable=page.program background_image=page.header_image %}
 
       <main role="main">
         {% for program in page.program %}
-- 
GitLab