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

Custom positions for people on people page, run hooks

parent 0d7f859b
No related branches found
No related tags found
2 merge requests!1047Uniweb redesign,!1045Uniweb redesign, minor district redesign fixes
......@@ -126,6 +126,17 @@ class NewsletterBlock(StructBlock):
template = "styleguide2/includes/organisms/main_section/newsletter_section.html"
class PersonCustomPositionBlock(StructBlock):
page = PageChooserBlock(
page_type="district.DistrictPersonPage", label="Detail osoby"
)
position = CharBlock(
label="Pozice",
help_text="Pokud není pozice vyplněná, použije se pozice ze stránky osoby.",
required=False,
)
class PeopleGroupBlock(StructBlock):
title = CharBlock(label="Titulek")
slug = CharBlock(
......@@ -133,9 +144,8 @@ class PeopleGroupBlock(StructBlock):
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",
person_list_with_custom_positions = ListBlock(
PersonCustomPositionBlock(), label="Skupina osob"
)
class Meta:
......
......@@ -2,11 +2,27 @@
import wagtail
from django.db import migrations, models
from district.blocks import PeopleGroupBlock
from wagtail.blocks import CharBlock, ListBlock, PageChooserBlock, StructBlock
def migrate_people_blocks(apps, schema_editor):
# Recreate here because this block has been changed in the future
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",
)
# Get the page model
DistrictPeoplePage = apps.get_model("district", "DistrictPeoplePage")
DistrictPersonPage = apps.get_model("district", "DistrictPersonPage")
......
......@@ -5,11 +5,57 @@ from django.apps import apps as base_apps
from django.contrib.contenttypes.management import create_contenttypes
from django.db import migrations, transaction
from district.blocks import ProgramGroupWithCandidatesBlock
from district.blocks import (
ProgramGroupBlock,
ProgramGroupBlockCrossroad,
ProgramGroupBlockPopout,
CarouselProgramBlock,
CandidateListBlock,
CandidateSecondaryListBlock
)
from wagtail.blocks import StructBlock, CharBlock, RichTextBlock, BooleanBlock, StreamBlock
from shared.blocks import SocialLinkBlock
def migrate_programs(apps, schema_editor):
# Copy this block manually here, as it has been changed in future migrations.
class ProgramGroupWithCandidatesBlock(StructBlock):
title = CharBlock(
label="Název programu",
help_text="Např. 'Krajské volby 2024', 'Evropské volby 2024', ...",
)
preamble_content = RichTextBlock(
label="Preambule",
help_text="Text, který se zobrazí před přepínačem mezi kandidáty a programem.",
required=False,
)
primary_candidates = CandidateListBlock(
label="Osoby na čele kandidátky",
help_text="Zobrazí se ve velkých blocích na začátku stránky.",
)
secondary_candidates = CandidateSecondaryListBlock(
label="Ostatní osoby na kandidátce",
help_text="Zobrazí se v kompaktním seznamu pod čelem kandidátky.",
)
program = StreamBlock(
[
("program_group", ProgramGroupBlock()),
("program_group_crossroad", ProgramGroupBlockCrossroad()),
("program_group_popout", ProgramGroupBlockPopout()),
(
"carousel_program",
CarouselProgramBlock(
template="styleguide2/includes/molecules/program/program_block.html"
),
),
]
)
# Get the models
DistrictHomePage = apps.get_model("district", "DistrictHomePage")
......
# Generated by Django 5.0.6 on 2024-06-20 08:39
import wagtail.blocks
import wagtail.fields
import wagtail.images.blocks
from django.db import migrations
from district.blocks import PeopleGroupBlock
def migrate_people(apps, schema_editor):
DistrictPeoplePage = apps.get_model("district", "DistrictPeoplePage")
DistrictPersonPage = apps.get_model("district", "DistrictPersonPage")
for page in DistrictPeoplePage.objects.all():
prep_value = page.people.get_prep_value()
people_group_blocks = []
for person_group in prep_value:
people = []
if person_group["type"] != "people_group":
continue
person_group["value"]["person_list_with_custom_positions"] = []
for person_page_block in person_group["value"]["person_list"]:
person_block = {
"page": person_page_block["value"],
"position": "",
}
people.append(person_block)
group_block = PeopleGroupBlock().to_python(
{
"title": person_group["value"]["title"],
"slug": person_group["value"]["title"],
"person_list_with_custom_positions": people,
}
)
people_group_blocks.append(group_block)
page.people = []
page.save()
for people_group_block in people_group_blocks:
page.people.append(("people_group", people_group_block))
page.save()
class Migration(migrations.Migration):
dependencies = [
('district', '0231_alter_districtnewprogrampage_program'),
]
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')), ('person_list_with_custom_positions', wagtail.blocks.ListBlock(wagtail.blocks.StructBlock([('page', wagtail.blocks.PageChooserBlock(label='Detail osoby', page_type=['district.DistrictPersonPage'])), ('position', wagtail.blocks.CharBlock(label='Pozice', required=False))]), label='Skupina osob (nastavitelné pozice)'))], 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.DistrictArticlesPage', 'district.DistrictCenterPage', 'district.DistrictContactPage', 'district.DistrictCrossroadPage', 'district.DistrictCustomPage', 'district.DistrictPeoplePage', 'district.DistrictGeoFeatureCollectionPage', 'district.DistrictCalendarPage', 'district.DistrictPdfPage', 'district.DistrictNewProgramPage'], 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)
]
# Generated by Django 5.0.6 on 2024-06-20 08:56
import wagtail.blocks
import wagtail.fields
import wagtail.images.blocks
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('district', '0232_alter_districtpeoplepage_people'),
]
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_with_custom_positions', wagtail.blocks.ListBlock(wagtail.blocks.StructBlock([('page', wagtail.blocks.PageChooserBlock(label='Detail osoby', page_type=['district.DistrictPersonPage'])), ('position', wagtail.blocks.CharBlock(label='Pozice', required=False))]), label='Skupina osob (nastavitelné pozice)'))], 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.DistrictArticlesPage', 'district.DistrictCenterPage', 'district.DistrictContactPage', 'district.DistrictCrossroadPage', 'district.DistrictCustomPage', 'district.DistrictPeoplePage', 'district.DistrictGeoFeatureCollectionPage', 'district.DistrictCalendarPage', 'district.DistrictPdfPage', 'district.DistrictNewProgramPage'], 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'),
),
]
# Generated by Django 5.0.6 on 2024-06-20 09:00
import wagtail.blocks
import wagtail.fields
import wagtail.images.blocks
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('district', '0233_alter_districtpeoplepage_people'),
]
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_with_custom_positions', wagtail.blocks.ListBlock(wagtail.blocks.StructBlock([('page', wagtail.blocks.PageChooserBlock(label='Detail osoby', page_type=['district.DistrictPersonPage'])), ('position', wagtail.blocks.CharBlock(help_text='Pokud není pozice vyplněná, použije se pozice ze stránky osoby.', label='Pozice', required=False))]), 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.DistrictArticlesPage', 'district.DistrictCenterPage', 'district.DistrictContactPage', 'district.DistrictCrossroadPage', 'district.DistrictCustomPage', 'district.DistrictPeoplePage', 'district.DistrictGeoFeatureCollectionPage', 'district.DistrictCalendarPage', 'district.DistrictPdfPage', 'district.DistrictNewProgramPage'], 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'),
),
]
......@@ -27,11 +27,22 @@
{% for block in page.people %}
{% if block.block_type == "people_group" %}
<template v-if="isCurrentView('{{ block.value.slug }}-{{ forloop.counter }}')">
{% for person_page in block.value.person_list %}
{% image person_page.profile_image fill-480x480 as profile_image %}
{% if block.value.person_list %}
{% for person_page in block.value.person_list %}
{% image person_page.profile_image fill-480x480 as profile_image %}
{% include 'styleguide2/includes/molecules/contact/contact_person_large_box.html' with image=profile_image name=person_page.title function=person_page.position telephone=person_page.phone mail=person_page.email url=person_page.url %}
{% endfor %}
{% include 'styleguide2/includes/molecules/contact/contact_person_large_box.html' with image=profile_image name=person_page.title function=person_page.position telephone=person_page.phone mail=person_page.email url=person_page.url %}
{% endfor %}
{% elif block.value.person_list_with_custom_positions %}
{% for person in block.value.person_list_with_custom_positions %}
{% with person.page as person_page %}
{% image person_page.profile_image fill-480x480 as profile_image %}
{% firstof person.position person_page.position as position %}
{% include 'styleguide2/includes/molecules/contact/contact_person_large_box.html' with image=profile_image name=person_page.title function=position telephone=person_page.phone mail=person_page.email url=person_page.url %}
{% endwith %}
{% endfor %}
{% endif %}
</template>
{% endif %}
{% endfor %}
......@@ -68,4 +79,4 @@
{% include 'styleguide2/includes/organisms/main_section/newsletter_section.html' %}
{% endblock %}
{% endblock content %}
{% endblock content %}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment