Skip to content
Snippets Groups Projects
Commit 02aff40d authored by jan.bednarik's avatar jan.bednarik
Browse files

shared: Refactor SubpageMixin usage

parent 9ac93177
No related branches found
No related tags found
2 merge requests!178Release,!177Upgrade
......@@ -20,28 +20,13 @@ from wagtail.images.blocks import ImageChooserBlock
from wagtail.images.edit_handlers import ImageChooserPanel
from wagtailmetadata.models import MetadataPageMixin
from shared.models import SubpageMixin
from tuning import help
from .forms import DonateForm
from .utils import get_donated_amount_from_api
class SubpageMixin:
"""Must be used in class definition before MetadataPageMixin!"""
# flag for rendering anchor links in menu
is_home = False
@property
def root_page(self):
if not hasattr(self, "_root_page"):
self._root_page = self.get_ancestors().type(DonateHomePage).specific().get()
return self._root_page
def get_meta_image(self):
return self.search_image or self.root_page.get_meta_image()
class DonateFormMixin(models.Model):
"""Pages which has donate form. Must be in class definition before Page!"""
......@@ -270,6 +255,9 @@ class DonateRegionIndexPage(Page, SubpageMixin, MetadataPageMixin):
### OTHERS
# flag for rendering anchor links in menu
is_home = False
class Meta:
verbose_name = "Přehled krajů"
......@@ -333,6 +321,9 @@ class DonateRegionPage(
### OTHERS
# flag for rendering anchor links in menu
is_home = False
class Meta:
verbose_name = "Kraj"
......@@ -373,6 +364,9 @@ class DonateProjectIndexPage(Page, SubpageMixin, MetadataPageMixin):
### OTHERS
# flag for rendering anchor links in menu
is_home = False
class Meta:
verbose_name = "Přehled projektů"
......@@ -479,6 +473,9 @@ class DonateProjectPage(
### OTHERS
# flag for rendering anchor links in menu
is_home = False
class Meta:
verbose_name = "Projekt"
......@@ -565,6 +562,9 @@ class DonateTextPage(Page, SubpageMixin, MetadataPageMixin):
### OTHERS
# flag for rendering anchor links in menu
is_home = False
class Meta:
verbose_name = "Stránka s textem"
......@@ -602,6 +602,9 @@ class DonateInfoPage(DonateFormMixin, Page, SubpageMixin, MetadataPageMixin):
### OTHERS
# flag for rendering anchor links in menu
is_home = False
class Meta:
verbose_name = "Infostránka s formulářem"
......@@ -674,6 +677,9 @@ class DonateTargetedDonationsPage(
### OTHERS
# flag for rendering anchor links in menu
is_home = False
class Meta:
verbose_name = "Adresné dary"
......
......@@ -17,6 +17,7 @@ from wagtail.images.edit_handlers import ImageChooserPanel
from wagtailmetadata.models import MetadataPageMixin
from calendar_utils.models import CalendarMixin
from shared.models import SubpageMixin
from tuning import help
HELP_COMBINED_TITLE = (
......@@ -25,18 +26,7 @@ HELP_COMBINED_TITLE = (
)
class SubpageMixin:
"""Must be used in class definition before MetadataPageMixin!"""
@property
def root_page(self):
if not hasattr(self, "_root_page"):
self._root_page = self.get_parent().specific
return self._root_page
def get_meta_image(self):
return self.search_image or self.root_page.get_meta_image()
class MetaMixin:
def get_meta_title(self):
if self.seo_title:
return self.seo_title
......@@ -288,7 +278,7 @@ class SenatCampaignHomePage(Page, MetadataPageMixin, CalendarMixin):
return context
class SenatCampaignNewsIndexPage(Page, SubpageMixin, MetadataPageMixin):
class SenatCampaignNewsIndexPage(Page, SubpageMixin, MetaMixin, MetadataPageMixin):
### FIELDS
### PANELS
......@@ -340,7 +330,7 @@ class SenatCampaignNewsIndexPage(Page, SubpageMixin, MetadataPageMixin):
return context
class SenatCampaignNewsPage(Page, SubpageMixin, MetadataPageMixin):
class SenatCampaignNewsPage(Page, SubpageMixin, MetaMixin, MetadataPageMixin):
### FIELDS
date = models.DateField("datum")
......@@ -436,7 +426,7 @@ class ProgramBlock(blocks.StructBlock):
label = "programový bod"
class SenatCampaignProgramPage(Page, SubpageMixin, MetadataPageMixin):
class SenatCampaignProgramPage(Page, SubpageMixin, MetaMixin, MetadataPageMixin):
### FIELDS
committee_preference = StreamField(
......@@ -484,7 +474,7 @@ class SenatCampaignProgramPage(Page, SubpageMixin, MetadataPageMixin):
verbose_name = "Program"
class SenatCampaignCookiesPage(Page, SubpageMixin, MetadataPageMixin):
class SenatCampaignCookiesPage(Page, SubpageMixin, MetaMixin, MetadataPageMixin):
### FIELDS
body = RichTextField("obsah", blank=True)
......
......@@ -15,11 +15,14 @@ class SubpageMixin:
@property
def root_page(self):
if not hasattr(self, "_root_page"):
# Vypada to hackove ale lze takto pouzit: dle dokumentace get_ancestors
# 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
def get_meta_image(self):
return self.search_image or self.root_page.get_meta_image()
class ArticleMixin(models.Model):
"""Common fields for articles"""
......
......@@ -11,11 +11,11 @@ from wagtail.contrib.table_block.blocks import TableBlock
from wagtail.core import blocks
from wagtail.core.fields import StreamField
from wagtail.core.models import Page
from wagtail.documents.blocks import DocumentChooserBlock
from wagtail.images.blocks import ImageChooserBlock
from wagtail.images.edit_handlers import ImageChooserPanel
from wagtailmetadata.models import MetadataPageMixin
from shared.models import SubpageMixin
from tuning import help
from .constants import (
......@@ -150,19 +150,6 @@ class MenuItemBlock(blocks.StructBlock):
label = "stránka"
class SubpageMixin:
"""Must be used in class definition before MetadataPageMixin!"""
@property
def root_page(self):
if not hasattr(self, "_root_page"):
self._root_page = self.get_ancestors().type(UniwebHomePage).specific().get()
return self._root_page
def get_meta_image(self):
return self.search_image or self.root_page.get_meta_image()
class UniwebContentMixin(models.Model):
content = StreamField(
[
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment