diff --git a/district/models.py b/district/models.py index 684c5be73bed2bf8536128ca900dacaba0061afb..f2b8a6823f42fd7311feb9ce33380f1030d2ff19 100644 --- a/district/models.py +++ b/district/models.py @@ -7,19 +7,16 @@ from wagtail.core.fields import StreamField from wagtail.core.models import Page from wagtailmetadata.models import MetadataPageMixin -from shared.models import Article, PersonPage +from shared.models import Article, SharedSubpageMixin class SubpageMixin: - """Must be used in class definition before MetadataPageMixin!""" + """Must be used in class definition before MetadataPageMixin! + Obsolete, misto nej pouzivat SharedSubpageMixin + TODO je pouze v migracich, po odstraneni z nich lze smazat + """ - @property - def root_page(self): - if not hasattr(self, "_root_page"): - self._root_page = ( - self.get_ancestors().type(DistrictHomePage).specific().get() - ) - return self._root_page + pass class DistrictHomePage(MetadataPageMixin, Page): @@ -133,7 +130,7 @@ class DistrictHomePage(MetadataPageMixin, Page): return self -class DistrictArticles(SubpageMixin, MetadataPageMixin, Page): +class DistrictArticles(SharedSubpageMixin, MetadataPageMixin, Page): ### FIELDS max_items = models.IntegerField( @@ -162,7 +159,7 @@ class DistrictArticles(SubpageMixin, MetadataPageMixin, Page): return context -class DistrictContact(SubpageMixin, MetadataPageMixin, Page): +class DistrictContact(SharedSubpageMixin, MetadataPageMixin, Page): class ContactItemBlock(blocks.StructBlock): name = blocks.CharBlock(label="Role") person = blocks.PageChooserBlock( diff --git a/shared/models.py b/shared/models.py index 8a9768211e7fc217873ec5b7fef77ab0461b54e2..fcb488eeb2fd2090df516842c6cf5db2edbb9179 100644 --- a/shared/models.py +++ b/shared/models.py @@ -9,11 +9,23 @@ from wagtail.images.edit_handlers import ImageChooserPanel from wagtailmetadata.models import MetadataPageMixin +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 + + class ArticleTag(TaggedItemBase): content_object = ParentalKey("shared.Article", on_delete=models.CASCADE) -class Article(MetadataPageMixin, Page): +class Article(SharedSubpageMixin, MetadataPageMixin, Page): """ Univerzalni clanek pro vsechny weby """ ### FIELDS @@ -47,7 +59,7 @@ class Article(MetadataPageMixin, Page): verbose_name = "Článek" -class PersonPage(MetadataPageMixin, Page): +class PersonPage(SharedSubpageMixin, MetadataPageMixin, Page): """ Stranka Pirata. Snaha je zadavat tady minimum informaci o osobe a zbytek vytahovat via API z jinych zdroju, neb nechceme dalsi databazi lidi. @@ -114,7 +126,7 @@ class PersonPage(MetadataPageMixin, Page): return context -class PeoplePage(MetadataPageMixin, Page): +class PeoplePage(SharedSubpageMixin, MetadataPageMixin, Page): """ Stranka se zobrazenim lidi v dane organizaci TOOD: subpagemixin """