Skip to content
Snippets Groups Projects
Commit 2b883b87 authored by Štěpán Farka's avatar Štěpán Farka Committed by jan.bednarik
Browse files

[FIX] ContactItemBlock to PersonCustomPositionBlock

parent 8a7ab4a7
No related branches found
No related tags found
2 merge requests!550Release,!542[ADD] footer person list
......@@ -137,18 +137,6 @@ class CenterContactBlock(StructBlock):
label = "Kontakt"
class ContactItemBlock(StructBlock):
name = CharBlock(label="Role")
person = PageChooserBlock(
label="Osoba",
page_type=["district.DistrictPersonPage"],
)
class Meta:
icon = "mail"
label = "Kontakt"
class HomepageHeaderBlock(StructBlock):
title = CharBlock(label="Titulek", required=False, help_text="Nap")
image = ImageChooserBlock()
......
# Generated by Django 4.0.4 on 2022-06-02 14:33
import wagtail.core.blocks
import wagtail.core.fields
from django.db import migrations
from wagtail.core.blocks import StreamValue
def name_to_position(block):
block["value"]["position"] = block["value"]["name"]
del block["value"]["name"]
return block
def position_to_name(block):
block["value"]["name"] = block["value"]["position"]
del block["value"]["position"]
return block
def get_content(page, mapper):
stream_data = []
mapped = False
for block in page.contact_people.raw_data:
if block["type"] == "item":
stream_data.append(mapper(block))
mapped = True
else:
stream_data.append(block)
return stream_data, mapped
def migrate(apps, mapper):
DistrictContactPage = apps.get_model("district", "DistrictContactPage")
for page in DistrictContactPage.objects.all():
contact_people, mapped = get_content(page, mapper)
if mapped:
page.contact_people = StreamValue(
page.contact_people, contact_people, is_lazy=True
)
page.save()
def forwards(apps, schema_editor):
migrate(apps, name_to_position)
def backwards(apps, schema_editor):
migrate(apps, position_to_name)
class Migration(migrations.Migration):
dependencies = [
("district", "0082_alter_districtcenterpage_sidebar_content_and_more"),
]
operations = [
migrations.AlterField(
model_name="districtcontactpage",
name="contact_people",
field=wagtail.core.fields.StreamField(
[
(
"item",
wagtail.core.blocks.StructBlock(
[
(
"position",
wagtail.core.blocks.CharBlock(
label="Název pozice", required=False
),
),
(
"person",
wagtail.core.blocks.PageChooserBlock(
label="Osoba",
page_type=["district.DistrictPersonPage"],
),
),
]
),
)
],
blank=True,
verbose_name="Kontakty",
),
),
migrations.RunPython(forwards, backwards),
]
......@@ -450,7 +450,7 @@ class DistrictContactPage(
### FIELDS
contact_people = StreamField(
[("item", blocks.ContactItemBlock())],
[("item", blocks.PersonCustomPositionBlock())],
verbose_name="Kontakty",
blank=True,
)
......
......@@ -17,12 +17,18 @@
{% for item in page.contact_people %}
<div>
{% if item.value.position %}
<h2 class="head-heavy-sm mb-2 lg:mb-4">
{{ item.value.name }}
{{ item.value.position }}
</h2>
{% elif item.value.person.job_function %}
<h2 class="head-heavy-sm mb-2 lg:mb-4">
{{ item.value.person.job_function }}
</h2>
{% endif %}
<div class="card elevation-3">
<div class="card__body">
{% include "shared/person_badge_wide_snippet.html" with person_page=item.value.person %}
{% include "shared/person_badge_wide_snippet.html" with person_page=item.value.person title=item.value.position %}
</div>
</div>
</div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment