Skip to content
Snippets Groups Projects
Verified Commit a53561a0 authored by Alexa Valentová's avatar Alexa Valentová
Browse files

people page migrations + progressive, non-month based news page loading

parent f5529bc1
No related branches found
No related tags found
2 merge requests!994Release,!988Redesign
Pipeline #18252 passed
Showing
with 775 additions and 413 deletions
from django.forms.utils import ErrorList
from django.utils.text import slugify
from wagtail import blocks
from wagtail.blocks import (
BooleanBlock,
......@@ -112,6 +113,81 @@ class NewsletterBlock(StructBlock):
template = "styleguide2/includes/organisms/main_section/newsletter_section.html"
class PeopleGroupBlock(StructBlock):
title = CharBlock(label="Titulek")
slug = CharBlock(
label="Slug skupiny",
required=False,
help_text="Není třeba vyplňovat, bude automaticky vyplněno",
)
person_list = ListBlock(
PageChooserBlock(page_type="district.DistrictPersonPage", label="Detail osoby"),
label="Skupina osob",
)
class Meta:
icon = "group"
label = "Slug skupiny"
def get_prep_value(self, value):
value = super().get_prep_value(value)
value["slug"] = slugify(value["title"])
return value
class CardLinkBlock(CardLinkBlockMixin):
page = PageChooserBlock(
label="Stránka",
page_type=[
"district.DistrictHomepage",
],
required=False,
)
class Meta:
template = "styleguide2/includes/molecules/boxes/card_box_block.html"
icon = "link"
label = "Karta s odkazem"
class CardLinkWithHeadlineBlock(CardLinkWithHeadlineBlockMixin):
card_items = ListBlock(
CardLinkBlock(
template="styleguide2/includes/molecules/boxes/card_box_block.html"
),
label="Karty s odkazy",
)
class Meta:
template = (
"styleguide2/includes/molecules/boxes/card_box_with_headline_block.html"
)
icon = "link"
label = "Karty odkazů s nadpisem"
class TeamBlock(StructBlock):
title = CharBlock(label="Název sekce týmů")
slug = CharBlock(
label="Slug sekce",
required=False,
help_text="Není třeba vyplňovat, bude automaticky vyplněno",
)
team_list = ListBlock(
CardLinkWithHeadlineBlock(label="Karta týmu"),
label="Týmy",
)
class Meta:
icon = "group"
label = "Týmy"
def get_prep_value(self, value):
value = super().get_prep_value(value)
value["slug"] = slugify(value["title"])
return value
# --- END New blocks ---
......
import os
from django import forms
from shared.forms import JekyllImportForm as SharedJekyllImportForm
from .tasks import import_jekyll_articles
class JekyllImportForm(SharedJekyllImportForm):
use_git = forms.BooleanField(
initial=False,
required=False,
label="Použít Git",
help_text="Umožňuje jednodušší zpracování, ale vyžaduje nainstalovaný Git.",
)
def clean(self):
cleaned_data = super().clean()
if not cleaned_data.get("do_import"):
return cleaned_data
if cleaned_data.get("use_git"):
if cleaned_data.get("jekyll_repo_url", "").endswith(".zip"):
self.add_error(
"jekyll_repo_url", "Vložte odkaz pouze na repozitář, ne na zip"
)
elif cleaned_data.get("jekyll_repo_url", "").endswith(".git"):
self.add_error(
"jekyll_repo_url",
"Vložte odkaz pouze na repozitář, ne na '.git' soubor",
)
else:
if not cleaned_data.get("jekyll_repo_url", "").endswith(".zip"):
self.add_error("jekyll_repo_url", "Odkaz nesměřuje na soubor '.zip'")
return cleaned_data
def handle_import(self):
lock_file_name = f"/tmp/.{self.instance.id}.import-lock"
......
......@@ -33,6 +33,9 @@ def merge_blocks(apps, schema_editor):
desktop_image = None
mobile_image = None
button_url = None
button_text = None
# Titles
if old_block["type"] in (
"header_full_size",
......@@ -105,8 +108,28 @@ def merge_blocks(apps, schema_editor):
"button_text": button_text,
}
)
merged_blocks.append(merged_block_data)
if len(merged_blocks) == 0:
merged_blocks = [
FullscreenHeaderBlock().to_python(
{
"desktop_line_1": home_page.title,
"desktop_line_2": "",
"mobile_line_1": home_page.title,
"mobile_line_2": "",
"mobile_line_3": "",
"desktop_image": None,
"mobile_image": None,
"desktop_video_url": None,
"mobile_video_url": None,
"button_url": None,
"button_text": None,
}
)
]
for block in merged_blocks:
home_page.content.append(("fullscreen_header_block", block))
......
# Generated by Django 5.0.4 on 2024-05-10 08:49
from django.db import migrations
from django.db import models
import wagtail
import django
import wagtail
from django.db import migrations, models
from shared.blocks import NavbarMenuItemBlock
......@@ -54,11 +54,8 @@ def add_navbar_menu_items(apps, schema_editor):
class Migration(migrations.Migration):
dependencies = [
('district', '0147_remove_districthomepage_contact_email_and_more'),
("district", "0147_remove_districthomepage_contact_email_and_more"),
]
operations = [
migrations.RunPython(add_navbar_menu_items)
]
operations = [migrations.RunPython(add_navbar_menu_items)]
......@@ -4,26 +4,25 @@ from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('district', '0148_auto_20240510_1049'),
("district", "0148_auto_20240510_1049"),
]
operations = [
migrations.RemoveField(
model_name='districthomepage',
name='contact_newcomers',
model_name="districthomepage",
name="contact_newcomers",
),
migrations.RemoveField(
model_name='districthomepage',
name='donation_page',
model_name="districthomepage",
name="donation_page",
),
migrations.RemoveField(
model_name='districthomepage',
name='show_eshop_link',
model_name="districthomepage",
name="show_eshop_link",
),
migrations.RemoveField(
model_name='districthomepage',
name='show_magazine_link',
model_name="districthomepage",
name="show_magazine_link",
),
]
# Generated by Django 5.0.4 on 2024-05-10 10:33
import shared.blocks.main
import wagtail.blocks
import wagtail.fields
from django.db import migrations
import shared.blocks.main
class Migration(migrations.Migration):
dependencies = [
('district', '0149_remove_districthomepage_contact_newcomers_and_more'),
("district", "0149_remove_districthomepage_contact_newcomers_and_more"),
]
operations = [
migrations.RemoveField(
model_name='districthomepage',
name='footer_links',
model_name="districthomepage",
name="footer_links",
),
migrations.AddField(
model_name='districthomepage',
name='footer_other_links',
field=wagtail.fields.StreamField([('other_links', wagtail.blocks.StructBlock([('title', wagtail.blocks.CharBlock(label='Titulek')), ('list', wagtail.blocks.ListBlock(shared.blocks.main.LinkBlock, label='Seznam odkazů s titulkem'))]))], blank=True, verbose_name='Odkazy v zápatí webu'),
model_name="districthomepage",
name="footer_other_links",
field=wagtail.fields.StreamField(
[
(
"other_links",
wagtail.blocks.StructBlock(
[
("title", wagtail.blocks.CharBlock(label="Titulek")),
(
"list",
wagtail.blocks.ListBlock(
shared.blocks.main.LinkBlock,
label="Seznam odkazů s titulkem",
),
),
]
),
)
],
blank=True,
verbose_name="Odkazy v zápatí webu",
),
),
migrations.AlterField(
model_name='districthomepage',
name='footer_extra_content',
field=wagtail.fields.RichTextField(blank=True, verbose_name='Extra obsah na začátku patičky'),
model_name="districthomepage",
name="footer_extra_content",
field=wagtail.fields.RichTextField(
blank=True, verbose_name="Extra obsah na začátku patičky"
),
),
]
# Generated by Django 5.0.4 on 2024-05-10 10:35
import shared.blocks.main
import wagtail.blocks
import wagtail.fields
from django.db import migrations
import shared.blocks.main
class Migration(migrations.Migration):
dependencies = [
('district', '0150_remove_districthomepage_footer_links_and_more'),
("district", "0150_remove_districthomepage_footer_links_and_more"),
]
operations = [
migrations.AlterField(
model_name='districthomepage',
name='footer_other_links',
field=wagtail.fields.StreamField([('other_links', wagtail.blocks.StructBlock([('title', wagtail.blocks.CharBlock(label='Titulek')), ('list', wagtail.blocks.ListBlock(shared.blocks.main.LinkBlock, label='Seznam odkazů'))]))], blank=True, verbose_name='Odkazy v zápatí webu'),
model_name="districthomepage",
name="footer_other_links",
field=wagtail.fields.StreamField(
[
(
"other_links",
wagtail.blocks.StructBlock(
[
("title", wagtail.blocks.CharBlock(label="Titulek")),
(
"list",
wagtail.blocks.ListBlock(
shared.blocks.main.LinkBlock,
label="Seznam odkazů",
),
),
]
),
)
],
blank=True,
verbose_name="Odkazy v zápatí webu",
),
),
]
# Generated by Django 5.0.4 on 2024-05-12 11:36
from django.db import migrations
def update_title_suffix(apps, schema_editor):
DistrictHomePage = apps.get_model("district", "DistrictHomePage")
for home_page in DistrictHomePage.objects.all():
if not home_page.title_suffix:
home_page.title_suffix = home_page.title
home_page.title_suffix = home_page.title_suffix.replace("MS ", "").replace(
"KS ", ""
)
home_page.save()
class Migration(migrations.Migration):
dependencies = [
("district", "0151_alter_districthomepage_footer_other_links"),
]
operations = [migrations.RunPython(update_title_suffix)]
# Generated by Django 5.0.4 on 2024-05-12 11:54
from django.db import migrations
from district.blocks import NewsletterBlock
def add_newsletter_blocks(apps, schema_editor):
DistrictHomePage = apps.get_model("district", "DistrictHomePage")
for home_page in DistrictHomePage.objects.all():
if not home_page.newsletter_list_id:
continue
home_page.content.append(("newsletter_block", NewsletterBlock().to_python({})))
home_page.save()
class Migration(migrations.Migration):
dependencies = [
("district", "0152_auto_20240512_1336"),
]
operations = [migrations.RunPython(add_newsletter_blocks)]
# Generated by Django 5.0.4 on 2024-05-12 12:23
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("district", "0153_auto_20240512_1354"),
]
operations = [
migrations.AlterModelOptions(
name="districtarticlespage",
options={"verbose_name": "Rozcestník článků"},
),
migrations.RemoveField(
model_name="districtarticlespage",
name="max_items",
),
migrations.AddField(
model_name="districtarticlespage",
name="perex",
field=models.TextField(default=""),
preserve_default=False,
),
]
# Generated by Django 5.0.4 on 2024-05-13 09:39
import wagtail.blocks
import wagtail.documents.blocks
import wagtail.fields
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("district", "0154_alter_districtarticlespage_options_and_more"),
]
operations = [
migrations.RemoveField(
model_name="districtarticlepage",
name="is_black",
),
migrations.AddField(
model_name="districtarticlepage",
name="show_initial_image",
field=models.BooleanField(
default=True,
help_text="Pokud je tato volba zaškrtnutá, obrázek nastavený u tohoto článku se automaticky vloží do prvního odstavce.",
verbose_name="Ukázat obrázek v textu",
),
),
migrations.AlterField(
model_name="districtarticlepage",
name="content",
field=wagtail.fields.StreamField(
[
(
"text",
wagtail.blocks.RichTextBlock(
template="styleguide2/includes/atoms/text/prose_richtext.html"
),
),
(
"quote",
wagtail.blocks.StructBlock(
[
("quote", wagtail.blocks.CharBlock(label="Citace")),
(
"autor_name",
wagtail.blocks.CharBlock(label="Jméno autora"),
),
]
),
),
(
"download",
wagtail.blocks.StructBlock(
[
(
"file",
wagtail.documents.blocks.DocumentChooserBlock(
label="Stáhnutelný soubor"
),
)
]
),
),
],
blank=True,
verbose_name="Článek",
),
),
]
# Generated by Django 5.0.4 on 2024-05-13 15:18
import wagtail.blocks
import wagtail.fields
import wagtail.images.blocks
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("district", "0155_remove_districtarticlepage_is_black_and_more"),
]
operations = [
migrations.AlterModelOptions(
name="districtpeoplepage",
options={"verbose_name": "Lidé a týmy"},
),
migrations.AddField(
model_name="districtpeoplepage",
name="people",
field=wagtail.fields.StreamField(
[
(
"people_group",
wagtail.blocks.StructBlock(
[
("title", wagtail.blocks.CharBlock(label="Titulek")),
(
"slug",
wagtail.blocks.CharBlock(
help_text="Není třeba vyplňovat, bude automaticky vyplněno",
label="Slug skupiny",
required=False,
),
),
(
"person_list",
wagtail.blocks.ListBlock(
wagtail.blocks.PageChooserBlock(
label="Detail osoby",
page_type=["main.MainPersonPage"],
),
label="Skupina osob",
),
),
],
label="Seznam osob",
),
),
(
"team_group",
wagtail.blocks.StructBlock(
[
(
"title",
wagtail.blocks.CharBlock(label="Název sekce týmů"),
),
(
"slug",
wagtail.blocks.CharBlock(
help_text="Není třeba vyplňovat, bude automaticky vyplněno",
label="Slug sekce",
required=False,
),
),
(
"team_list",
wagtail.blocks.ListBlock(
wagtail.blocks.StructBlock(
[
(
"headline",
wagtail.blocks.CharBlock(
label="Titulek bloku",
required=False,
),
),
(
"card_items",
wagtail.blocks.ListBlock(
wagtail.blocks.StructBlock(
[
(
"image",
wagtail.images.blocks.ImageChooserBlock(
label="Obrázek"
),
),
(
"title",
wagtail.blocks.CharBlock(
label="Titulek",
required=True,
),
),
(
"text",
wagtail.blocks.RichTextBlock(
label="Krátký text pod nadpisem",
required=False,
),
),
(
"page",
wagtail.blocks.PageChooserBlock(
label="Stránka",
page_type=[
"district.DistrictHomePage"
],
required=False,
),
),
(
"link",
wagtail.blocks.URLBlock(
label="Odkaz",
required=False,
),
),
],
template="styleguide2/includes/molecules/boxes/card_box_block.html",
),
label="Karty s odkazy",
),
),
],
label="Karta týmu",
),
label="Týmy",
),
),
]
),
),
],
blank=True,
verbose_name="Lidé a týmy",
),
),
migrations.AddField(
model_name="districtpeoplepage",
name="perex_col_1",
field=models.TextField(default="", verbose_name="Perex - první sloupec"),
preserve_default=False,
),
migrations.AddField(
model_name="districtpeoplepage",
name="perex_col_2",
field=models.TextField(default="", verbose_name="Perex - druhý sloupec"),
preserve_default=False,
),
]
# Generated by Django 5.0.4 on 2024-05-13 16:48
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("district", "0156_alter_districtpeoplepage_options_and_more"),
]
operations = [
migrations.RenameField(
model_name="districtpersonpage",
old_name="profile_photo",
new_name="main_image",
),
]
# Generated by Django 5.0.4 on 2024-05-13 16:52
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("district", "0158_rename_profile_photo_districtpersonpage_main_image"),
]
operations = [
migrations.RenameField(
model_name="districtpersonpage",
old_name="main_image",
new_name="profile_image",
),
]
# Generated by Django 5.0.4 on 2024-05-13 16:52
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("district", "0159_rename_main_image_districtpersonpage_profile_image"),
]
operations = [
migrations.RenameField(
model_name="districtpersonpage",
old_name="background_photo",
new_name="main_image",
),
]
# Generated by Django 5.0.4 on 2024-05-13 15:33
import wagtail
from django.db import migrations
from wagtail.blocks import PageChooserBlock
from district.blocks import PeopleGroupBlock
def migrate_people_blocks(apps, schema_editor):
# Get the page model
DistrictPeoplePage = apps.get_model("district", "DistrictPeoplePage")
DistrictPersonPage = apps.get_model("district", "DistrictPersonPage")
# Iterate over all pages that have the StreamField you want to update
for number, people_page in enumerate(DistrictPeoplePage.objects.all()):
# Get the old content
old_content = people_page.content.get_prep_value()
# Create a new list to store the merged blocks
merged_blocks = []
# Iterate over the old blocks and extract common fields
for old_block in old_content:
if old_block["type"] != "people_group":
continue
title = old_block["value"]["group_title"]
people = []
for person in old_block["value"]["person_list"]:
person_id = DistrictPersonPage.objects.filter(
id=person["value"]["person"]
).values_list("id", flat=True).first()
if person_id is None:
continue
people.append(person_id)
person_block_list = []
for person_id in people:
person_block_list.append(person_id)
merged_blocks.append(
PeopleGroupBlock().to_python(
{
"title": title,
"slug": str(number),
"person_list": person_block_list,
}
)
)
for block in merged_blocks:
people_page.people.append(("people_group", block))
people_page.save()
class Migration(migrations.Migration):
dependencies = [
("district", "0160_rename_background_photo_districtpersonpage_main_image"),
]
operations = [
migrations.AlterField(
model_name="districtpeoplepage",
name="people",
field=wagtail.fields.StreamField(
[
(
"people_group",
wagtail.blocks.StructBlock(
[
("title", wagtail.blocks.CharBlock(label="Titulek")),
(
"slug",
wagtail.blocks.CharBlock(
help_text="Není třeba vyplňovat, bude automaticky vyplněno",
label="Slug skupiny",
required=False,
),
),
(
"person_list",
wagtail.blocks.ListBlock(
wagtail.blocks.PageChooserBlock(
label="Detail osoby",
page_type=["district.DistrictPersonPage"],
),
label="Skupina osob",
),
),
],
label="Seznam osob",
),
),
(
"team_group",
wagtail.blocks.StructBlock(
[
(
"title",
wagtail.blocks.CharBlock(label="Název sekce týmů"),
),
(
"slug",
wagtail.blocks.CharBlock(
help_text="Není třeba vyplňovat, bude automaticky vyplněno",
label="Slug sekce",
required=False,
),
),
(
"team_list",
wagtail.blocks.ListBlock(
wagtail.blocks.StructBlock(
[
(
"headline",
wagtail.blocks.CharBlock(
label="Titulek bloku",
required=False,
),
),
(
"card_items",
wagtail.blocks.ListBlock(
wagtail.blocks.StructBlock(
[
(
"image",
wagtail.images.blocks.ImageChooserBlock(
label="Obrázek"
),
),
(
"title",
wagtail.blocks.CharBlock(
label="Titulek",
required=True,
),
),
(
"text",
wagtail.blocks.RichTextBlock(
label="Krátký text pod nadpisem",
required=False,
),
),
(
"page",
wagtail.blocks.PageChooserBlock(
label="Stránka",
page_type=[
"district.DistrictHomePage"
],
required=False,
),
),
(
"link",
wagtail.blocks.URLBlock(
label="Odkaz",
required=False,
),
),
],
template="styleguide2/includes/molecules/boxes/card_box_block.html",
),
label="Karty s odkazy",
),
),
],
label="Karta týmu",
),
label="Týmy",
),
),
]
),
),
],
blank=True,
verbose_name="Lidé a týmy",
),
),
migrations.RunPython(migrate_people_blocks),
]
......@@ -56,8 +56,11 @@ from shared.models import (
ExtendedMetadataHomePageMixin,
ExtendedMetadataPageMixin,
FooterMixin,
MainArticlePageMixin,
MainArticlesPageMixin,
MainFooterMixin,
MainMenuMixin,
MainPeoplePageMixin,
MenuMixin,
PdfPageMixin,
SharedTaggedDistrictArticle,
......@@ -306,9 +309,17 @@ class DistrictHomePage(
)[:6]
)
@property
def articles_page_model(self):
return DistrictArticlesPage
@property
def article_page_model(self):
return DistrictArticlePage
@property
def articles_page(self):
return self._first_subpage_of_type(DistrictArticlesPage)
return self._first_subpage_of_type(self.articles_page_model)
@property
def center_page(self):
......@@ -364,15 +375,12 @@ class DistrictArticleTag(TaggedItemBase):
)
class DistrictArticlePage(
ArticleMixin, ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, Page
):
class DistrictArticlePage(MainArticlePageMixin):
### FIELDS
author_page = models.ForeignKey(
"district.DistrictPersonPage", on_delete=models.SET_NULL, null=True, blank=True
)
is_black = models.BooleanField("Má tmavé pozadí?", default=False)
tags = ClusterTaggableManager(through=DistrictArticleTag, blank=True)
shared_tags = ClusterTaggableManager(
verbose_name="Tagy pro sdílení mezi weby",
......@@ -388,216 +396,20 @@ class DistrictArticlePage(
related_name="thumb_image",
)
search_fields = ArticleMixin.search_fields + [
index.SearchField("author_page"),
index.FilterField("slug"),
]
### PANELS
content_panels = ArticleMixin.content_panels + [
FieldPanel("author_page"),
FieldPanel("is_black"),
FieldPanel("tags"),
FieldPanel("shared_tags"),
FieldPanel("thumb_image"),
]
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 = ["district.DistrictArticlesPage"]
subpage_types = ["district.DistrictPdfPage"]
### OTHERS
class Meta:
verbose_name = "Aktualita"
def clean(self):
cleaned_data = super().clean()
if not self.image and not self.thumb_image:
raise ValidationError("Musí být nahraný buď obrázek nebo náhledový obrázek")
return cleaned_data
def get_context(self, request):
context = super().get_context(request)
context["related_articles"] = (
(
self.get_siblings(inclusive=False)
.live() # TODO? filtrovat na stejné tagy? nebo sdílené články?
.specific()
.order_by("-districtarticlepage__timestamp")[:3]
)
if self.shared_from is None
else []
)
return context
class DistrictArticlesPage(MainArticlesPageMixin):
base_form_class = JekyllImportForm
class DistrictArticlesPage(
RoutablePageMixin,
ExtendedMetadataPageMixin,
SubpageMixin,
MetadataPageMixin,
ArticlesPageMixin,
Page,
):
### FIELDS
last_import_log = models.TextField(
"Výstup z posledního importu", null=True, blank=True
)
max_items = models.IntegerField("Počet článků na stránce", default=12)
### PANELS
content_panels = ArticlesPageMixin.content_panels + [
FieldPanel("max_items"),
]
promote_panels = make_promote_panels()
import_panels = [
MultiFieldPanel(
[
FieldPanel("do_import"),
FieldPanel("collection"),
FieldPanel("dry_run"),
FieldPanel("use_git"),
FieldPanel("jekyll_repo_url"),
FieldPanel("readonly_log"),
HelpPanel(
mark_safe(
"Import provádějte vždy až po vytvoření stránky aktualit. "
"Pro uložení logu je nutné volit možnost <strong>Publikovat</strong>, nikoliv "
"pouze <strong>Uložit koncept</strong>. "
"Import proběhne na pozadí a může trvat až několik minut. "
"Dejte si po spuštění importu kávu a potom obnovte stránku pro "
"zobrazení výsledku importu."
)
),
],
"import z Jekyll repozitáře",
),
]
### EDIT HANDLERS
edit_handler = TabbedInterface(
[
ObjectList(content_panels, heading="Obsah"),
ObjectList(promote_panels, heading="Propagovat"),
ObjectList(import_panels, heading="Import"),
]
)
### RELATIONS
parent_page_types = ["district.DistrictHomePage"]
subpage_types = ["district.DistrictArticlePage"]
### OTHERS
base_form_class = JekyllImportForm
class Meta:
verbose_name = "Aktuality"
def get_context(self, request):
context = super().get_context(request)
context["articles"] = self.get_page_with_shared_articles(
self.append_all_shared_articles_query(
DistrictArticlePage.objects.child_of(self)
),
self.max_items,
request.GET.get("page", 1),
)
return context
@route(r"^tagy/$", name="tags")
def tags(self, request):
return render(
request,
"district/district_tags_page.html",
context=self.get_tags_page_context(request=request),
)
@route(r"^sdilene/$", name="shared")
def shared(self, request):
return self.setup_article_page_context(request)
def get_tags_page_context(self, request) -> dict:
# Potřebujeme IDčka článků pro správnou root_page pro filtrování zobrazených
# tagů i samotných stránek, protože se filtrují přes specifický field
# (tags__slug)
context = super().get_context(request)
articles = self.materialize_articles_as_id_only(
self.append_all_shared_articles_query(
DistrictArticlePage.objects.child_of(self)
)
)
page_ids = list(map(lambda article: article.page_ptr.id, articles))
# Naplním "tag" a "article_page_list" parametry
context.update(**self.get_tag_and_articles(request, page_ids))
context["tag_list"] = self.get_tag_qs(articles)
# Pro obecnou paginaci posílám "extra_query", abych si podržel tag pro další GET
context["extra_query"] = "&tag={}".format(request.GET.get("tag", ""))
return context
def get_tag_and_articles(self, request, page_ids: list) -> dict:
"""
Vrátí vyfiltrované články podle tagu a page query pro z daného "výběru"
pro danou stránku (site_article_ids). Lepší by bylo články a tag řešit
separátně, ale pak by se musel rozpadnout ten try/except na více bloků.
"""
article_page_qs = None
tag = None
try:
tag = Tag.objects.filter(slug=request.GET["tag"])[0]
article_page_qs = self.append_all_shared_articles_query(
DistrictArticlePage.objects.filter(
page_ptr_id__in=page_ids, tags__slug=tag.slug
),
custom_article_query=lambda shared: shared.filter(
page_ptr_id__in=page_ids, tags__slug=tag.slug
),
)
except (KeyError, IndexError):
tag = None
article_page_qs = self.append_all_shared_articles_query(
DistrictArticlePage.objects.filter(page_ptr_id__in=page_ids),
custom_article_query=lambda shared: shared.filter(
page_ptr_id__in=page_ids
),
)
return {
"article_page_list": self.get_page_with_shared_articles(
article_page_qs, self.max_items, request.GET.get("page", 1)
),
"tag": tag,
}
def get_tag_qs(self, articles: list) -> models.QuerySet:
"""
Getuje Tagy pouze pro DistrictArticlePage omezeno IDčky getnutých přes
root_page. Počítá, kolik článků je s daným tagem.
"""
return self.search_tags_with_count(articles)
class DistrictContactPage(
ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, Page
......@@ -660,7 +472,7 @@ class DistrictPersonPage(
job_function = models.CharField(
"Funkce", max_length=128, blank=True, null=True, help_text="Např. 'Předseda'"
)
background_photo = models.ForeignKey(
main_image = models.ForeignKey(
"wagtailimages.Image",
on_delete=models.PROTECT,
blank=True,
......@@ -668,7 +480,7 @@ class DistrictPersonPage(
related_name="+",
verbose_name="obrázek do záhlaví",
)
profile_photo = models.ForeignKey(
profile_image = models.ForeignKey(
"wagtailimages.Image",
on_delete=models.PROTECT,
blank=True,
......@@ -726,8 +538,8 @@ class DistrictPersonPage(
),
MultiFieldPanel(
[
FieldPanel("profile_photo"),
FieldPanel("background_photo"),
FieldPanel("profile_image"),
FieldPanel("main_image"),
],
"Fotky",
),
......@@ -807,11 +619,7 @@ class DistrictPersonPage(
return None
class DistrictPeoplePage(
ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, Page
):
### FIELDS
class DistrictPeoplePage(MainPeoplePageMixin):
content = StreamField(
[
(
......@@ -827,24 +635,26 @@ class DistrictPeoplePage(
use_json_field=True,
)
### PANELS
content_panels = Page.content_panels + [FieldPanel("content")]
promote_panels = make_promote_panels()
settings_panels = []
people = StreamField(
[
("people_group", blocks.PeopleGroupBlock(label="Seznam osob")),
("team_group", blocks.TeamBlock()),
],
verbose_name="Lidé a týmy",
blank=True,
use_json_field=True,
)
### RELATIONS
content_panels = Page.content_panels + [
FieldPanel("perex_col_1"),
FieldPanel("perex_col_2"),
FieldPanel("people"),
FieldPanel("content"),
]
parent_page_types = ["district.DistrictHomePage"]
subpage_types = ["district.DistrictPersonPage"]
### OTHERS
class Meta:
verbose_name = "Lidé"
class DistrictElectionBasePage(
ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, Page
......
{% extends "district/base.html" %}
{% load static wagtailcore_tags wagtailimages_tags wagtailroutablepage_tags %}
{% block content %}
{% if page.root_page.articles_page %}
{% routablepageurl page.root_page.articles_page "tags" as articles_tag_page_url %}
{% endif %}
<article>
<link itemprop="mainEntityOfPage" href="{{ page.url }}">
<meta itemprop="datePublished" content="{{ page.last_published_at }}">
<meta itemprop="dateModified" content="{{ page.latest_revision_created_at }}">
<h1 class="head-alt-md md:head-alt-lg max-w-5xl mb-4">
{{ page.title }}
</h1>
<div class="flex flex-col md:flex-row md:items-center">
<div class="inline-flex divide-x flex-grow">
<span class="pr-2">{{ page.date|date:"DATE_FORMAT" }}</span>
<span class="pl-2" itemprop="author" itemtype="http://schema.org/Person" itemscope="">
{% if page.author_page %}
<a href="{{ page.author_page.url }}" itemprop="name">{{ page.author }}</a>
{% else %}
<span itemprop="name">{{ page.author|default_if_none:'' }}</span>
{% endif %}
</span>
</div>
<div class="my-4">
{% for tag in page.get_tags %}
<a href="{{ articles_tag_page_url }}?tag={{ tag.slug }}" class="btn btn--grey-125 btn--condensed">
<div class="btn__body ">{{ tag }}</div>
</a>
{% endfor %}
</div>
</div>
{% if page.image %}
<figure class="figure">
{% image page.image width-2000 as img %}
<img src="{{ img.url }}" alt="{{ page.title }}"/>
</figure>
{% endif %}
<div class="lg:flex mt-8 lg:space-x-16">
<div class="lg:w-2/3">
<div itemprop="description" class="w-full space-y-8">
{% for block in page.content %}
{% include_block block %}
{% endfor %}
{% if page.author_page %}
{% include "shared/person_badge_snippet.html" with person_page=page.author_page title="Autor" %}
{% endif %}
</div>
</div>
<div class="pt-8 lg:w-1/3 md:pt-0">
<div class="sharebox md:card md:elevation-10 ">
<div class="md:card__body">
<span class="head-alt-base md:head-alt-md">Sdílení je aktem lásky</span>
<div class="flex w-full space-x-4 pt-4 md:pt-8 text-center text-white">
<a
href="https://www.facebook.com/sharer/sharer.php?u={{ page.full_url|urlencode }}"
onclick="window.open(this.href, 'pop-up', 'left=20,top=20,width=500,height=500,toolbar=1,resizable=0'); return false;"
class="bg-brands-facebook px-8 py-3 text-2xl w-full"
><i class="ico--facebook"></i></a>
<a
href="https://twitter.com/intent/tweet?text={{ page.title|urlencode }}&url={{ page.full_url|urlencode }}"
onclick="window.open(this.href, 'pop-up', 'left=20,top=20,width=500,height=500,toolbar=1,resizable=0'); return false;"
class="bg-brands-twitter px-8 py-3 text-2xl w-full"
><i class="ico--twitter"></i></a>
</div>
</div>
<div class="h-52 overflow-hidden hidden md:block">
<img src="{% static "shared/img/flag.png" %}" alt="Pirátská strana" class="w-80 object-cover m-auto"/>
</div>
</div>
</div>
</div>
{% include "shared/article_shared_link.html" %}
</article>
{% if related_articles|length %}
<section class="mt-16 md:mt-24">
<h1 class="head-alt-base md:head-alt-md pb-4">
Další podobné články
</h1>
<div class="article-card-list grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4 lg:gap-8">
{% for article in related_articles %}
{% include "shared/article_preview.html" %}
{% endfor %}
</div>
{% include "shared/more_articles_snippet.html" %}
</section>
{% endif %}
{% endblock %}
{% extends "styleguide2/article_page.html" %}
{% extends "district/base.html" %}
{% load wagtailcore_tags wagtailimages_tags shared_filters %}
{% block content %}
<header>
<h1 itemprop="headline" class="head-alt-md md:head-alt-lg max-w-5xl mb-8">
{{ page.title }}
</h1>
</header>
{% for block in page.content %}
{% include_block block %}
{% if not forloop.last %}
<hr class="hr--big">
{% endif %}
{% endfor %}
{% endblock %}
{% extends "styleguide2/people_page.html" %}
# Generated by Django 5.0.4 on 2024-05-10 10:35
import shared.blocks.main
import wagtail.blocks
import wagtail.fields
from django.db import migrations
import shared.blocks.main
class Migration(migrations.Migration):
dependencies = [
('elections', '0027_alter_electionshomepage_content'),
("elections", "0027_alter_electionshomepage_content"),
]
operations = [
migrations.AlterField(
model_name='electionshomepage',
name='footer_other_links',
field=wagtail.fields.StreamField([('other_links', wagtail.blocks.StructBlock([('title', wagtail.blocks.CharBlock(label='Titulek')), ('list', wagtail.blocks.ListBlock(shared.blocks.main.LinkBlock, label='Seznam odkazů'))]))], blank=True, verbose_name='Odkazy v zápatí webu'),
model_name="electionshomepage",
name="footer_other_links",
field=wagtail.fields.StreamField(
[
(
"other_links",
wagtail.blocks.StructBlock(
[
("title", wagtail.blocks.CharBlock(label="Titulek")),
(
"list",
wagtail.blocks.ListBlock(
shared.blocks.main.LinkBlock,
label="Seznam odkazů",
),
),
]
),
)
],
blank=True,
verbose_name="Odkazy v zápatí webu",
),
),
]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment