Skip to content
Snippets Groups Projects
Commit 3a414165 authored by xaralis's avatar xaralis Committed by jan.bednarik
Browse files

fix(district,region): center page spacing and conditional logic

parent 6c5e5b02
Branches
No related tags found
2 merge requests!473Release,!471district, region: UI improvements
Pipeline #7735 passed
...@@ -125,12 +125,14 @@ class CardLinkWithHeadlineBlock(StructBlock): ...@@ -125,12 +125,14 @@ class CardLinkWithHeadlineBlock(StructBlock):
label = "Karta odkazu s nadpisem" label = "Karta odkazu s nadpisem"
class CenterContactPersonBlock(StructBlock):
person = PageChooserBlock(label="Osoba", page_type=["district.DistrictPersonPage"])
position = CharBlock(label="Pozice", required=False)
class CenterContactBlock(StructBlock): class CenterContactBlock(StructBlock):
title = CharBlock(label="Titulek", required=True) title = CharBlock(label="Titulek", required=True)
contact_list = ListBlock( contact_list = ListBlock(CenterContactPersonBlock())
PageChooserBlock(label="Osoba", page_type=["district.DistrictPersonPage"]),
label="List kontaktů",
)
class Meta: class Meta:
template = "district/blocks/contact_block.html" template = "district/blocks/contact_block.html"
......
# Generated by Django 4.0.3 on 2022-04-25 08:24
import wagtail.core.blocks
import wagtail.core.fields
import wagtail.images.blocks
from django.db import migrations
from wagtail.core.blocks.stream_block import StreamValue
def plain_to_structured(block):
modified_items = []
for item in block["value"]["contact_list"]:
modified_items.append(
{
**item,
"value": {
"person": item["value"],
"position": "",
},
}
)
block["value"]["contact_list"] = modified_items
return block
def structured_to_plain(block):
modified_items = []
for item in block["value"]["contact_list"]:
modified_items.append({**item, "value": item["value"]["person"]})
block["value"]["contact_list"] = modified_items
return block
def get_sidebar_content(page, mapper):
stream_data = []
mapped = False
for block in page.sidebar_content.raw_data:
if block["type"] == "contact":
stream_data.append(mapper(block))
mapped = True
else:
stream_data.append(block)
return stream_data, mapped
def migrate(apps, mapper):
DistrictCenterPage = apps.get_model("district", "DistrictCenterPage")
for page in DistrictCenterPage.objects.all():
sidebar_content, mapped = get_sidebar_content(page, mapper)
if mapped:
page.sidebar_content = StreamValue(
page.sidebar_content, sidebar_content, is_lazy=True
)
page.save()
def forwards(apps, schema_editor):
migrate(apps, plain_to_structured)
def backwards(apps, schema_editor):
migrate(apps, structured_to_plain)
class Migration(migrations.Migration):
dependencies = [
("district", "0055_alter_districtcenterpage_content_and_more"),
]
operations = [
migrations.AlterField(
model_name="districtcenterpage",
name="sidebar_content",
field=wagtail.core.fields.StreamField(
[
(
"address",
wagtail.core.blocks.StructBlock(
[
(
"title",
wagtail.core.blocks.CharBlock(
label="Titulek", required=True
),
),
(
"map_image",
wagtail.images.blocks.ImageChooserBlock(
label="Obrázek mapy", required=False
),
),
(
"map_link",
wagtail.core.blocks.URLBlock(
label="Odkaz na detail mapy", required=False
),
),
(
"address",
wagtail.core.blocks.TextBlock(
label="Adresa", required=True
),
),
(
"address_info",
wagtail.core.blocks.TextBlock(
label="Info k adrese", required=False
),
),
]
),
),
(
"contact",
wagtail.core.blocks.StructBlock(
[
(
"title",
wagtail.core.blocks.CharBlock(
label="Titulek", required=True
),
),
(
"contact_list",
wagtail.core.blocks.ListBlock(
wagtail.core.blocks.StructBlock(
[
(
"person",
wagtail.core.blocks.PageChooserBlock(
label="Osoba",
page_type=[
"district.DistrictPersonPage"
],
),
),
(
"position",
wagtail.core.blocks.CharBlock(
label="Pozice", required=False
),
),
]
)
),
),
]
),
),
],
blank=True,
verbose_name="Obsah bočního panelu",
),
),
migrations.AlterField(
model_name="districtcenterpage",
name="text",
field=wagtail.core.fields.RichTextField(
blank=True, null=True, verbose_name="Text"
),
),
migrations.RunPython(forwards, backwards),
]
...@@ -899,7 +899,7 @@ class DistrictCenterPage(CalendarMixin, SubpageMixin, MetadataPageMixin, Page): ...@@ -899,7 +899,7 @@ class DistrictCenterPage(CalendarMixin, SubpageMixin, MetadataPageMixin, Page):
verbose_name="Obsah", verbose_name="Obsah",
blank=True, blank=True,
) )
text = RichTextField("Text", null=True) text = RichTextField("Text", blank=True, null=True)
sidebar_content = StreamField( sidebar_content = StreamField(
[("address", blocks.AddressBlock()), ("contact", blocks.CenterContactBlock())], [("address", blocks.AddressBlock()), ("contact", blocks.CenterContactBlock())],
verbose_name="Obsah bočního panelu", verbose_name="Obsah bočního panelu",
......
...@@ -2,8 +2,10 @@ ...@@ -2,8 +2,10 @@
{{ self.title }} {{ self.title }}
</h2> </h2>
{% for person_page in self.contact_list %} <div class="space-y-4">
<div class="{% if not forloop.last %}mb-4{% endif %}"> {% for contact_details in self.contact_list %}
{% include "shared/person_badge_snippet.html" %} {% with contact_details.person as person_page %}
</div> {% include "shared/person_badge_snippet.html" with title=contact_details.position|default:person_page.job_function %}
{% endwith %}
{% endfor %} {% endfor %}
</div>
...@@ -9,30 +9,35 @@ ...@@ -9,30 +9,35 @@
{{ page.title }} {{ page.title }}
</h1> </h1>
<h2 class="head-xs mt-2"> <h2 class="head-xs mt-2">
{{ page.subtitle }} {{ page.perex }}
</h2> </h2>
</div> </div>
</aside> </aside>
{% endblock %} {% endblock %}
{% block container_spacing %}pt-8 lg:pb-16{% endblock %}
{% block content %} {% block content %}
<article> <article>
<div class="lg:flex lg:space-x-8 xl:space-x-16"> <div class="lg:flex lg:space-x-8 xl:space-x-16">
<div class="lg:w-3/5 xl:w-2/3"> <div class="lg:w-3/5 xl:w-2/3">
<div class="content-block"> <div class="content-block">
{{ page.text | richtext }} {{ page.text | richtext }}
{% for block in page.content %} {% for block in page.content %}
{% include_block block %} {% include_block block %}
{% endfor %} {% endfor %}
</div> </div>
{% include "shared/small_calendar_snippet.html" %} {% include "shared/small_calendar_snippet.html" %}
</div> </div>
<div class="pt-8 lg:w-2/5 xl:w-1/3 lg:pt-0">
<div class="pt-8 lg:w-2/5 xl:w-1/3 lg:pt-0 space-y-4">
<div class="lg:card lg:elevation-10"> <div class="lg:card lg:elevation-10">
<div class="lg:card__body"> <div class="lg:card__body">
<div class="content-block"> <div class="content-block">
{% for block in page.sidebar_content %} {% for block in page.sidebar_content %}
{% include_block block %} {% include_block block %}
{% if not forloop.last %} {% if not forloop.last %}
<hr> <hr>
{% endif %} {% endif %}
......
...@@ -125,12 +125,14 @@ class CardLinkWithHeadlineBlock(StructBlock): ...@@ -125,12 +125,14 @@ class CardLinkWithHeadlineBlock(StructBlock):
label = "Karta odkazu s nadpisem" label = "Karta odkazu s nadpisem"
class CenterContactPersonBlock(StructBlock):
person = PageChooserBlock(label="Osoba", page_type=["region.RegionPersonPage"])
position = CharBlock(label="Pozice", required=False)
class CenterContactBlock(StructBlock): class CenterContactBlock(StructBlock):
title = CharBlock(label="Titulek", required=True) title = CharBlock(label="Titulek", required=True)
contact_list = ListBlock( contact_list = ListBlock(CenterContactPersonBlock())
PageChooserBlock(label="Osoba", page_type=["region.RegionPersonPage"]),
label="List kontaktů",
)
class Meta: class Meta:
template = "region/blocks/contact_block.html" template = "region/blocks/contact_block.html"
......
# Generated by Django 4.0.3 on 2022-04-25 09:18
import wagtail.core.blocks
import wagtail.core.fields
import wagtail.images.blocks
from django.db import migrations
from wagtail.core.blocks.stream_block import StreamValue
def plain_to_structured(block):
modified_items = []
for item in block["value"]["contact_list"]:
modified_items.append(
{
**item,
"value": {
"person": item["value"],
"position": "",
},
}
)
block["value"]["contact_list"] = modified_items
return block
def structured_to_plain(block):
modified_items = []
for item in block["value"]["contact_list"]:
modified_items.append({**item, "value": item["value"]["person"]})
block["value"]["contact_list"] = modified_items
return block
def get_sidebar_content(page, mapper):
stream_data = []
mapped = False
for block in page.sidebar_content.raw_data:
if block["type"] == "contact":
stream_data.append(mapper(block))
mapped = True
else:
stream_data.append(block)
return stream_data, mapped
def migrate(apps, mapper):
DistrictCenterPage = apps.get_model("region", "RegionCenterPage")
for page in DistrictCenterPage.objects.all():
sidebar_content, mapped = get_sidebar_content(page, mapper)
if mapped:
page.sidebar_content = StreamValue(
page.sidebar_content, sidebar_content, is_lazy=True
)
page.save()
def forwards(apps, schema_editor):
migrate(apps, plain_to_structured)
def backwards(apps, schema_editor):
migrate(apps, structured_to_plain)
class Migration(migrations.Migration):
dependencies = [
("region", "0030_alter_regioncenterpage_content_and_more"),
]
operations = [
migrations.AlterField(
model_name="regioncenterpage",
name="sidebar_content",
field=wagtail.core.fields.StreamField(
[
(
"address",
wagtail.core.blocks.StructBlock(
[
(
"title",
wagtail.core.blocks.CharBlock(
label="Titulek", required=True
),
),
(
"map_image",
wagtail.images.blocks.ImageChooserBlock(
label="Obrázek mapy", required=False
),
),
(
"map_link",
wagtail.core.blocks.URLBlock(
label="Odkaz na detail mapy", required=False
),
),
(
"address",
wagtail.core.blocks.TextBlock(
label="Adresa", required=True
),
),
(
"address_info",
wagtail.core.blocks.TextBlock(
label="Info k adrese", required=False
),
),
]
),
),
(
"contact",
wagtail.core.blocks.StructBlock(
[
(
"title",
wagtail.core.blocks.CharBlock(
label="Titulek", required=True
),
),
(
"contact_list",
wagtail.core.blocks.ListBlock(
wagtail.core.blocks.StructBlock(
[
(
"person",
wagtail.core.blocks.PageChooserBlock(
label="Osoba",
page_type=[
"region.RegionPersonPage"
],
),
),
(
"position",
wagtail.core.blocks.CharBlock(
label="Pozice", required=False
),
),
]
)
),
),
]
),
),
],
blank=True,
verbose_name="Obsah bočního panelu",
),
),
migrations.AlterField(
model_name="regioncenterpage",
name="text",
field=wagtail.core.fields.RichTextField(
blank=True, null=True, verbose_name="Text"
),
),
migrations.RunPython(forwards, backwards),
]
...@@ -885,7 +885,7 @@ class RegionCenterPage(CalendarMixin, SubpageMixin, MetadataPageMixin, Page): ...@@ -885,7 +885,7 @@ class RegionCenterPage(CalendarMixin, SubpageMixin, MetadataPageMixin, Page):
verbose_name="Obsah", verbose_name="Obsah",
blank=True, blank=True,
) )
text = RichTextField("Text", null=True) text = RichTextField("Text", blank=True, null=True)
sidebar_content = StreamField( sidebar_content = StreamField(
[("address", blocks.AddressBlock()), ("contact", blocks.CenterContactBlock())], [("address", blocks.AddressBlock()), ("contact", blocks.CenterContactBlock())],
verbose_name="Obsah bočního panelu", verbose_name="Obsah bočního panelu",
......
...@@ -2,8 +2,10 @@ ...@@ -2,8 +2,10 @@
{{ self.title }} {{ self.title }}
</h2> </h2>
{% for person_page in self.contact_list %} <div class="space-y-4">
<div class="{% if not forloop.last %}mb-4{% endif %}"> {% for contact_details in self.contact_list %}
{% include "shared/person_badge_snippet.html" %} {% with contact_details.person as person_page %}
</div> {% include "shared/person_badge_snippet.html" with title=contact_details.position|default:person_page.job_function %}
{% endwith %}
{% endfor %} {% endfor %}
</div>
...@@ -9,30 +9,35 @@ ...@@ -9,30 +9,35 @@
{{ page.title }} {{ page.title }}
</h1> </h1>
<h2 class="head-xs mt-2"> <h2 class="head-xs mt-2">
{{ page.subtitle }} {{ page.perex }}
</h2> </h2>
</div> </div>
</aside> </aside>
{% endblock %} {% endblock %}
{% block container_spacing %}pt-8 lg:pb-16{% endblock %}
{% block content %} {% block content %}
<article> <article>
<div class="lg:flex lg:space-x-8 xl:space-x-16"> <div class="lg:flex lg:space-x-8 xl:space-x-16">
<div class="lg:w-3/5 xl:w-2/3"> <div class="lg:w-3/5 xl:w-2/3">
<div class="content-block"> <div class="content-block">
{{ page.text | richtext }} {{ page.text | richtext }}
{% for block in page.content %} {% for block in page.content %}
{% include_block block %} {% include_block block %}
{% endfor %} {% endfor %}
</div> </div>
{% include "shared/small_calendar_snippet.html" %} {% include "shared/small_calendar_snippet.html" %}
</div> </div>
<div class="pt-8 lg:w-2/5 xl:w-1/3 lg:pt-0">
<div class="pt-8 lg:w-2/5 xl:w-1/3 lg:pt-0 space-y-4">
<div class="lg:card lg:elevation-10"> <div class="lg:card lg:elevation-10">
<div class="lg:card__body"> <div class="lg:card__body">
<div class="content-block"> <div class="content-block">
{% for block in page.sidebar_content %} {% for block in page.sidebar_content %}
{% include_block block %} {% include_block block %}
{% if not forloop.last %} {% if not forloop.last %}
<hr> <hr>
{% endif %} {% endif %}
......
<div class="flex flex-col"> <div class="flex flex-col lg:space-y-4">
<a href="{% firstof page.facebook page.root_page.facebook %}" <a href="{% firstof page.facebook page.root_page.facebook %}"
class="super-button bg-brands-facebook text-white container-padding--zero lg:container-padding--auto m-2"> class="super-button bg-brands-facebook text-white container-padding--zero lg:container-padding--auto lg:w-full">
<span class="super-button__body">Sledujte nás na Facebooku</span> <span class="super-button__body">Sledujte nás na Facebooku</span>
<i class="super-button__icon ico--facebook"></i> <i class="super-button__icon ico--facebook"></i>
</a> </a>
<a href="{% firstof page.forum page.root_page.forum %}" <a href="{% firstof page.forum page.root_page.forum %}"
class="super-button bg-black text-white container-padding--zero lg:container-padding--auto m-2"> class="super-button bg-black text-white container-padding--zero lg:container-padding--auto lg:w-full">
<span class="super-button__body">Sledujte naše fórum</span> <span class="super-button__body">Sledujte naše fórum</span>
<i class="super-button__icon ico--bubbles"></i> <i class="super-button__icon ico--bubbles"></i>
</a> </a>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment