from django.db import models from django.utils.translation import gettext_lazy from wagtail.admin.edit_handlers import ( FieldPanel, HelpPanel, MultiFieldPanel, StreamFieldPanel, ) from wagtail.core import blocks from wagtail.core.fields import StreamField from wagtail.core.models import Page from wagtail.images.blocks import ImageChooserBlock from wagtail.images.edit_handlers import ImageChooserPanel from wagtailmetadata.models import MetadataPageMixin from tuning import help RICH_TEXT_FEATURES = [ "h2", "h3", "h4", "h5", "bold", "italic", "ol", "ul", "hr", "link", "document-link", "image", "superscript", "subscript", "strikethrough", "blockquote", ] # TODO remove class TextSectionBlock(blocks.StructBlock): title = blocks.CharBlock(label="nadpis", required=False) text = blocks.RichTextBlock(label="text", features=RICH_TEXT_FEATURES) class Meta: label = "(deprecated) textová sekce" # TODO remove class ColumnsSectionBlock(blocks.StructBlock): title = blocks.CharBlock(label="nadpis", required=False) left_text = blocks.RichTextBlock(label="levý sloupec", features=RICH_TEXT_FEATURES) right_text = blocks.RichTextBlock( label="pravý sloupec", features=RICH_TEXT_FEATURES ) class Meta: label = "(deprecated) dvousloupcová textová sekce" class ColumnsTextBlock(blocks.StructBlock): left_text = blocks.RichTextBlock(label="levý sloupec", features=RICH_TEXT_FEATURES) right_text = blocks.RichTextBlock( label="pravý sloupec", features=RICH_TEXT_FEATURES ) class Meta: label = "text dva sloupce" icon = "doc-full" # TODO remove class GallerySectionBlock(blocks.StructBlock): title = blocks.CharBlock(label="nadpis", required=False) images = blocks.ListBlock(ImageChooserBlock(label="obrázek")) class Meta: label = "(deprecated) galerie obrázků" class MenuItemBlock(blocks.StructBlock): name = blocks.CharBlock(label="název") page = blocks.PageChooserBlock( label="stránka", page_type=["uniweb.UniwebHomePage", "uniweb.UniwebFlexiblePage"], ) class Meta: 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 UniwebHomePage(MetadataPageMixin, Page): ### FIELDS content = StreamField( [ ("title", blocks.CharBlock(label="nadpis", icon="title")), ("text", blocks.RichTextBlock(label="text")), ("text_columns", ColumnsTextBlock()), ( "gallery", blocks.ListBlock( ImageChooserBlock(label="obrázek"), label="galerie", icon="image" ), ), ("text_section", TextSectionBlock()), ("columns_section", ColumnsSectionBlock()), ("gallery_section", GallerySectionBlock()), ], verbose_name="obsah stránky", blank=True, ) # settings matomo_id = models.IntegerField( "Matomo ID pro sledování návštěvnosti", blank=True, null=True ) top_menu = StreamField( [("item", MenuItemBlock())], verbose_name="horní menu", blank=True, ) ### PANELS content_panels = Page.content_panels + [ StreamFieldPanel("content"), ] promote_panels = [ MultiFieldPanel( [ FieldPanel("seo_title"), FieldPanel("search_description"), ImageChooserPanel("search_image"), HelpPanel(help.build(help.IMPORTANT_TITLE)), ], gettext_lazy("Common page configuration"), ), ] settings_panels = [ FieldPanel("matomo_id"), StreamFieldPanel("top_menu"), ] ### RELATIONS subpage_types = [ "uniweb.UniwebFlexiblePage", ] ### OTHERS class Meta: verbose_name = "Univerzální web" @property def root_page(self): return self class UniwebFlexiblePage(Page, SubpageMixin, MetadataPageMixin): ### FIELDS content = StreamField( [ ("title", blocks.CharBlock(label="nadpis", icon="title")), ("text", blocks.RichTextBlock(label="text")), ("text_columns", ColumnsTextBlock()), ( "gallery", blocks.ListBlock( ImageChooserBlock(label="obrázek"), label="galerie", icon="image" ), ), ("text_section", TextSectionBlock()), ("columns_section", ColumnsSectionBlock()), ("gallery_section", GallerySectionBlock()), ], verbose_name="obsah stránky", blank=True, ) ### PANELS promote_panels = [ MultiFieldPanel( [ FieldPanel("slug"), FieldPanel("seo_title"), FieldPanel("search_description"), ImageChooserPanel("search_image"), HelpPanel(help.build(help.NO_SEO_TITLE, help.NO_SEARCH_IMAGE)), ], gettext_lazy("Common page configuration"), ), ] content_panels = Page.content_panels + [ StreamFieldPanel("content"), ] settings_panels = [] ### RELATIONS parent_page_types = ["uniweb.UniwebHomePage"] subpage_types = [] ### OTHERS class Meta: verbose_name = "Flexibilní stránka"