From 15f4c152117fa5f422f7535e47cdb59f70d98f6b Mon Sep 17 00:00:00 2001
From: Jarmil <jarmil.halamicek@seznam.cz>
Date: Fri, 27 Nov 2020 11:36:39 +0100
Subject: [PATCH] PDP: FIX: topmenu

---
 pdp/migrations/0003_auto_20201127_1134.py     | 40 +++++++++++++++++++
 pdp/models.py                                 | 19 ++++++++-
 ...p_flexible_page.html => pdp_sub_page.html} |  0
 uniweb/models.py                              | 13 +-----
 4 files changed, 59 insertions(+), 13 deletions(-)
 create mode 100644 pdp/migrations/0003_auto_20201127_1134.py
 rename pdp/templates/pdp/{pdp_flexible_page.html => pdp_sub_page.html} (100%)

diff --git a/pdp/migrations/0003_auto_20201127_1134.py b/pdp/migrations/0003_auto_20201127_1134.py
new file mode 100644
index 00000000..7a483ef5
--- /dev/null
+++ b/pdp/migrations/0003_auto_20201127_1134.py
@@ -0,0 +1,40 @@
+# Generated by Django 3.1.2 on 2020-11-27 10:34
+
+import wagtail.core.blocks
+import wagtail.core.fields
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ("pdp", "0002_pdpsubpage"),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name="pdphomepage",
+            name="top_menu",
+            field=wagtail.core.fields.StreamField(
+                [
+                    (
+                        "item",
+                        wagtail.core.blocks.StructBlock(
+                            [
+                                ("name", wagtail.core.blocks.CharBlock(label="název")),
+                                (
+                                    "page",
+                                    wagtail.core.blocks.PageChooserBlock(
+                                        label="stránka",
+                                        page_type=["pdp.PdpHomePage", "pdp.PdpSubPage"],
+                                    ),
+                                ),
+                            ]
+                        ),
+                    )
+                ],
+                blank=True,
+                verbose_name="hornĂ­ menu",
+            ),
+        ),
+    ]
diff --git a/pdp/models.py b/pdp/models.py
index 98d52b97..589a6f2b 100644
--- a/pdp/models.py
+++ b/pdp/models.py
@@ -6,6 +6,7 @@ from wagtail.admin.edit_handlers import (
     MultiFieldPanel,
     StreamFieldPanel,
 )
+from wagtail.core import blocks
 from wagtail.core.fields import StreamField
 from wagtail.core.models import Page
 from wagtail.documents.blocks import DocumentChooserBlock
@@ -34,15 +35,29 @@ class PdpContentMixin(models.Model):
         abstract = True
 
 
+class MenuItemBlock(blocks.StructBlock):
+    name = blocks.CharBlock(label="název")
+    page = blocks.PageChooserBlock(
+        label="stránka",
+        page_type=["pdp.PdpHomePage", "pdp.PdpSubPage"],
+    )
+
+    class Meta:
+        label = "stránka"
+
+
 class PdpHomePage(
     Page,
     PdpContentMixin,
-    uniweb.UniwebTopmenuMixin,
     MetadataPageMixin,
     MatomoMixin,
 ):
 
-    ### PANELS
+    top_menu = StreamField(
+        [("item", MenuItemBlock())],
+        verbose_name="hornĂ­ menu",
+        blank=True,
+    )
 
     content_panels = Page.content_panels + [
         StreamFieldPanel("content"),
diff --git a/pdp/templates/pdp/pdp_flexible_page.html b/pdp/templates/pdp/pdp_sub_page.html
similarity index 100%
rename from pdp/templates/pdp/pdp_flexible_page.html
rename to pdp/templates/pdp/pdp_sub_page.html
diff --git a/uniweb/models.py b/uniweb/models.py
index ab2d3433..a9e571fa 100644
--- a/uniweb/models.py
+++ b/uniweb/models.py
@@ -220,23 +220,14 @@ class UniwebContentMixin(models.Model):
         abstract = True
 
 
-class UniwebTopmenuMixin(models.Model):
-
+class UniwebHomePage(Page, UniwebContentMixin, MetadataPageMixin, MatomoMixin):
+    ### FIELDS
     top_menu = StreamField(
         [("item", MenuItemBlock())],
         verbose_name="hornĂ­ menu",
         blank=True,
     )
 
-    class Meta:
-        abstract = True
-
-
-class UniwebHomePage(
-    Page, UniwebContentMixin, UniwebTopmenuMixin, MetadataPageMixin, MatomoMixin
-):
-    ### FIELDS
-
     # settings
     narrow_layout = models.BooleanField(
         "zúžený obsah stránky",
-- 
GitLab