From 9f87632a76859c42d6208362c71dfb29d7a07d30 Mon Sep 17 00:00:00 2001
From: Jarmil <jarmil.halamicek@seznam.cz>
Date: Fri, 27 Nov 2020 11:32:30 +0100
Subject: [PATCH] WIP: PDP: FIX: subpage mixin

---
 pdp/models.py    |  4 ++--
 shared/mixins.py | 12 ++++++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/pdp/models.py b/pdp/models.py
index 304e2758..98d52b97 100644
--- a/pdp/models.py
+++ b/pdp/models.py
@@ -12,7 +12,7 @@ from wagtail.documents.blocks import DocumentChooserBlock
 from wagtail.images.edit_handlers import ImageChooserPanel
 from wagtailmetadata.models import MetadataPageMixin
 
-from shared.mixins import MatomoMixin
+from shared.mixins import MatomoMixin, SharedSubpageMixin
 from tuning import help
 from uniweb import models as uniweb
 
@@ -85,7 +85,7 @@ class PdpHomePage(
         return self
 
 
-class PdpSubPage(Page, PdpContentMixin, uniweb.SubpageMixin, MetadataPageMixin):
+class PdpSubPage(Page, PdpContentMixin, SharedSubpageMixin, MetadataPageMixin):
     ### FIELDS
 
     ### PANELS
diff --git a/shared/mixins.py b/shared/mixins.py
index a39f712f..5de63706 100644
--- a/shared/mixins.py
+++ b/shared/mixins.py
@@ -9,3 +9,15 @@ class MatomoMixin(models.Model):
 
     class Meta:
         abstract = True
+
+
+class SharedSubpageMixin:
+    """Must be used in class definition before MetadataPageMixin!"""
+
+    @property
+    def root_page(self):
+        if not hasattr(self, "_root_page"):
+            # Vypada to hackove ale lze takto pouzit: dle dokumentace get_ancestors vraci stranky v poradi
+            # od rootu, tedy domovska stranka je druha v poradi
+            self._root_page = self.get_ancestors().specific()[1]
+        return self._root_page
-- 
GitLab