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 class ProgramBlock(StructBlock):
# NewsBlock icon = ImageChooserBlock()
# PeopleOverviewBlock title = CharBlock()
# RegionOverviewBlock text = TextBlock()
# LinkBoxBlock (mozna hardcoded do homepage?)
# WorkTimelineBlock
# ArticleLinkBlock class ProgramGroupBlock(StructBlock):
# ProgramBlock 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): class PersonContactBlock(StructBlock):
...@@ -24,12 +71,24 @@ class PersonContactBlock(StructBlock): ...@@ -24,12 +71,24 @@ class PersonContactBlock(StructBlock):
label = "Osoba s volitelnou pozicí" label = "Osoba s volitelnou pozicí"
class PersonContactBoxBlock(StructBlock): class PersonContactBoxBlock(CTAMixin, StructBlock):
title = CharBlock(label="Titulek") title = CharBlock(label="Titulek")
subtitle = CharBlock(label="Podtitulek") 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 # TwitterCarouselBlock
# ContactBlock
Source diff could not be displayed: it is too large. Options to address this: view the blob.
from django.core.paginator import Paginator
from django.db import models from django.db import models
from django.shortcuts import render 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.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.fields import RichTextField, StreamField
from wagtail.core.models import Page from wagtail.core.models import Page
from wagtailmetadata.models import MetadataPageMixin from wagtailmetadata.models import MetadataPageMixin
from shared.const import RICH_TEXT_DEFAULT_FEATURES from shared.const import RICH_TEXT_DEFAULT_FEATURES
from shared.models import ( from shared.models import (
ArticleMixin,
ExtendedMetadataHomePageMixin, ExtendedMetadataHomePageMixin,
ExtendedMetadataPageMixin, ExtendedMetadataPageMixin,
MenuMixin, MenuMixin,
SubpageMixin, SubpageMixin,
) )
from shared.utils import make_promote_panels from shared.utils import make_promote_panels
from tuning import admin_help
from . import blocks from . import blocks
...@@ -24,11 +32,54 @@ class MainHomePage(MenuMixin, ExtendedMetadataHomePageMixin, MetadataPageMixin, ...@@ -24,11 +32,54 @@ class MainHomePage(MenuMixin, ExtendedMetadataHomePageMixin, MetadataPageMixin,
"Matomo ID pro sledování návštěvnosti", blank=True, null=True "Matomo ID pro sledování návštěvnosti", blank=True, null=True
) )
# header - fb, twitter, insta, youtube, dary, nalodeni # header
footer = StreamField(
[("item", blocks.PersonContactBlock())], contact_newcomers = models.URLField(
verbose_name="Kontaktní boxy", "URL pro zájemce o členství",
blank=True, 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 + [] content_panels = Page.content_panels + []
...@@ -48,12 +99,12 @@ class MainHomePage(MenuMixin, ExtendedMetadataHomePageMixin, MetadataPageMixin, ...@@ -48,12 +99,12 @@ class MainHomePage(MenuMixin, ExtendedMetadataHomePageMixin, MetadataPageMixin,
### RELATIONS ### RELATIONS
subpage_types = [ subpage_types = [
# MainWorkTimelinePage "main.MainWorkPage",
# MainArticlePage "main.MainArticlesPage",
# MainProgramPage "main.MainProgramPage",
# MainPeoplePage "main.MainPeoplePage",
# MainPersonPage "main.MainPersonPage",
"main.MainContactPage" "main.MainContactPage",
] ]
### OTHERS ### OTHERS
...@@ -70,7 +121,197 @@ class MainHomePage(MenuMixin, ExtendedMetadataHomePageMixin, MetadataPageMixin, ...@@ -70,7 +121,197 @@ class MainHomePage(MenuMixin, ExtendedMetadataHomePageMixin, MetadataPageMixin,
return self 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): class MainContactPage(ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, Page):
### FIELDS ### FIELDS
contact_people = StreamField( contact_people = StreamField(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment