Skip to content
Snippets Groups Projects
Commit 83f53e08 authored by Ondrej Rehounek's avatar Ondrej Rehounek
Browse files

main: models and blocks skeletons

parent 9a2a6fd6
Branches
No related tags found
2 merge requests!607Pirati.cz,!575Feature/pirati cz
from wagtail.core.blocks import CharBlock, PageChooserBlock, StructBlock, URLBlock
from wagtail.core.blocks import (
CharBlock,
ListBlock,
PageChooserBlock,
StructBlock,
TextBlock,
URLBlock,
)
from wagtail.images.blocks import ImageChooserBlock
class CTAMixin:
button_link = URLBlock(label="Odkaz tlačítka")
button_text = CharBlock(label="Text tlačítka")
class BoxBlock(CTAMixin, StructBlock):
image = ImageChooserBlock(label="Logo/obrázek")
title = CharBlock(label="Nadpis")
class BoxesBlock(StructBlock):
title = CharBlock(label="Nadpis")
list = ListBlock(BoxBlock, label="Boxíky")
class HomePageCarouseSlideBlock(CTAMixin, StructBlock):
line_1 = CharBlock()
line_2 = CharBlock()
class HomePageCarouselBlock(StructBlock):
slides = ListBlock(HomePageCarouseSlideBlock)
class PeopleGroupBlock(StructBlock):
title = CharBlock()
person_list = ListBlock(PageChooserBlock(page_type="main.MainPersonPage"))
# HomePageCarouselBlock
# RecentWork/TweetsBlock
# NewsBlock
# PeopleOverviewBlock
# RegionOverviewBlock
# LinkBoxBlock (mozna hardcoded do homepage?)
# WorkTimelineBlock
# ArticleLinkBlock
# ProgramBlock
class ProgramBlock(StructBlock):
icon = ImageChooserBlock()
title = CharBlock()
text = TextBlock()
class ProgramGroupBlock(StructBlock):
title = CharBlock()
person_list = ListBlock(ProgramBlock())
class TweetsBlock(StructBlock):
title = CharBlock()
# NewsBlock - zatím asi hardcoded
# PeopleOverviewBlock - zatím asi hardcoded
# RegionOverviewBlock - zatím asi hardcoded
class PersonContactBlock(StructBlock):
......@@ -24,12 +71,24 @@ class PersonContactBlock(StructBlock):
label = "Osoba s volitelnou pozicí"
class PersonContactBoxBlock(StructBlock):
class PersonContactBoxBlock(CTAMixin, StructBlock):
title = CharBlock(label="Titulek")
subtitle = CharBlock(label="Podtitulek")
button_link = URLBlock()
button_text = CharBlock(label="Text tlačítka")
# Footer
class LinkBlock(StructBlock):
text = CharBlock()
link = URLBlock()
class OtherLinksBlock(StructBlock):
title = CharBlock()
list = ListBlock(LinkBlock)
class SocialLinkBlock(LinkBlock):
icon = CharBlock() # TODO CSS class name or somthing better?
# TwitterCarouselBlock
# ContactBlock
This diff is collapsed.
from django.core.paginator import Paginator
from django.db import models
from django.shortcuts import render
from modelcluster.contrib.taggit import ClusterTaggableManager
from modelcluster.fields import ParentalKey
from taggit.models import TaggedItemBase
from wagtail.admin.edit_handlers import FieldPanel, ObjectList, TabbedInterface
from wagtail.contrib.routable_page.models import RoutablePageMixin, route
from wagtail.core.blocks import PageChooserBlock
from wagtail.core.fields import RichTextField, StreamField
from wagtail.core.models import Page
from wagtailmetadata.models import MetadataPageMixin
from shared.const import RICH_TEXT_DEFAULT_FEATURES
from shared.models import (
ArticleMixin,
ExtendedMetadataHomePageMixin,
ExtendedMetadataPageMixin,
MenuMixin,
SubpageMixin,
)
from shared.utils import make_promote_panels
from tuning import admin_help
from . import blocks
......@@ -24,11 +32,54 @@ class MainHomePage(MenuMixin, ExtendedMetadataHomePageMixin, MetadataPageMixin,
"Matomo ID pro sledování návštěvnosti", blank=True, null=True
)
# header - fb, twitter, insta, youtube, dary, nalodeni
footer = StreamField(
[("item", blocks.PersonContactBlock())],
verbose_name="Kontaktní boxy",
# header
contact_newcomers = models.URLField(
"URL pro zájemce o členství",
blank=True,
null=True,
default="https://nalodeni.pirati.cz",
)
donation_page = models.URLField(
"URL pro příjem darů (tlačítko Dary)",
blank=True,
null=True,
default="https://dary.pirati.cz",
)
# content
content = StreamField(
[
("carousel", blocks.HomePageCarouselBlock()),
("boxes", blocks.BoxesBlock()),
],
verbose_name="Hlavní obsah",
blank=True,
)
# footer
footer_social_links = StreamField(
[
("social_links", blocks.SocialLinkBlock()),
],
verbose_name="Odkazy na sociální sítě v zápatí webu",
blank=True,
)
footer_other_links = StreamField(
[
("other_links", blocks.OtherLinksBlock()),
],
verbose_name="Bloky dalších odkazů v zápatí webu",
blank=True,
)
footer_person_list = StreamField(
[("person", blocks.PersonContactBlock())],
verbose_name="Osoby v zápatí webu",
blank=True,
max_num=6,
)
content_panels = Page.content_panels + []
......@@ -48,12 +99,12 @@ class MainHomePage(MenuMixin, ExtendedMetadataHomePageMixin, MetadataPageMixin,
### RELATIONS
subpage_types = [
# MainWorkTimelinePage
# MainArticlePage
# MainProgramPage
# MainPeoplePage
# MainPersonPage
"main.MainContactPage"
"main.MainWorkPage",
"main.MainArticlesPage",
"main.MainProgramPage",
"main.MainPeoplePage",
"main.MainPersonPage",
"main.MainContactPage",
]
### OTHERS
......@@ -70,7 +121,197 @@ class MainHomePage(MenuMixin, ExtendedMetadataHomePageMixin, MetadataPageMixin,
return self
class MainWorkPage(ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, Page):
perex = models.TextField()
timeline = StreamField(
[("article_list", PageChooserBlock(page_type="main.MainArticlePage"))],
verbose_name="Timeline",
blank=True,
)
### RELATIONS
parent_page_types = ["main.MainHomePage"]
subpage_types = []
### OTHERS
class Meta:
verbose_name = "Piráti pracují"
class MainArticleTag(TaggedItemBase):
content_object = ParentalKey("main.MainArticlePage", on_delete=models.CASCADE)
class MainArticlePage(
ArticleMixin, ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, Page
):
### FIELDS
author_page = models.ForeignKey(
"main.MainPersonPage", on_delete=models.SET_NULL, null=True, blank=True
)
tags = ClusterTaggableManager(through=MainArticleTag, blank=True)
### PANELS
content_panels = ArticleMixin.content_panels + [
FieldPanel("author_page"),
FieldPanel("tags"),
]
promote_panels = make_promote_panels(
admin_help.build(admin_help.NO_SEO_TITLE, admin_help.NO_DESCRIPTION_USE_PEREX),
search_image=False,
)
### RELATIONS
parent_page_types = ["main.MainArticlesPage"]
subpage_types = []
### OTHERS
class Meta:
verbose_name = "Aktualita"
# def get_context(self, request): chceme/nechceme?
# context = super().get_context(request)
# context["related_articles"] = (
# self.get_siblings(inclusive=False)
# .live()
# .specific()
# .order_by("-mainarticlepage__date")[:3]
# )
# return context
class MainArticlesPage(
RoutablePageMixin, ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, Page
):
def get_context(self, request):
context = super().get_context(request)
context["articles"] = Paginator(
self.get_children().live().specific().order_by("-mainarticlepage__date"),
12, # nevím, návrh nemáme
).get_page(request.GET.get("page"))
return context
@route(r"^tagy/$", name="tags")
def tags(self, request):
return render(
request,
"main/main_tags_page.html",
context=self.get_tags_page_context(request=request),
)
### RELATIONS
parent_page_types = ["main.MainHomePage"]
subpage_types = ["main.MainArticlePage"]
### OTHERS
class Meta:
verbose_name = "Aktuality"
class MainProgramPage(ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, Page):
### FIELDS
perex = models.TextField()
program = StreamField(
[("program_group", blocks.ProgramGroupBlock())],
verbose_name="Program",
blank=True,
)
### PANELS
content_panels = Page.content_panels + [FieldPanel("perex"), FieldPanel("program")]
promote_panels = make_promote_panels()
settings_panels = []
### RELATIONS
parent_page_types = ["main.MainHomePage"]
subpage_types = []
### OTHERS
class Meta:
verbose_name = "Program"
class MainPeoplePage(ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, Page):
### FIELDS
perex = models.TextField()
people = StreamField(
[("people_group", blocks.PeopleGroupBlock())],
verbose_name="Lidé",
blank=True,
)
### PANELS
content_panels = Page.content_panels + [FieldPanel("perex"), FieldPanel("people")]
promote_panels = make_promote_panels()
settings_panels = []
### RELATIONS
parent_page_types = ["main.MainHomePage"]
subpage_types = ["main.MainPersonPage"]
### OTHERS
class Meta:
verbose_name = "Lidé"
class MainPersonPage(ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, Page):
### FIELDS
perex = models.TextField()
text = RichTextField()
settings_panels = []
### RELATIONS
parent_page_types = ["main.MainPeoplePage"]
subpage_types = []
### OTHERS
class Meta:
verbose_name = "Detail osoby"
# ordering = ("title",)
def get_background_photo(self):
"""
Vrací background_photo pro pozadí na stránce, pokud není nastaveno,
vezme falbback z homepage
"""
return (
self.background_photo
if self.background_photo
else self.root_page.fallback_image
)
class MainContactPage(ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, Page):
### FIELDS
contact_people = StreamField(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment