diff --git a/district/blocks.py b/district/blocks.py index 60d1573bb93e19bf5491cabbdbb2fb9855933e5c..294e7930dac23354afe3adb488c78aba8fc45379 100644 --- a/district/blocks.py +++ b/district/blocks.py @@ -125,12 +125,14 @@ class CardLinkWithHeadlineBlock(StructBlock): 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): title = CharBlock(label="Titulek", required=True) - contact_list = ListBlock( - PageChooserBlock(label="Osoba", page_type=["district.DistrictPersonPage"]), - label="List kontaktů", - ) + contact_list = ListBlock(CenterContactPersonBlock()) class Meta: template = "district/blocks/contact_block.html" diff --git a/district/migrations/0056_alter_districtcenterpage_sidebar_content_and_more.py b/district/migrations/0056_alter_districtcenterpage_sidebar_content_and_more.py new file mode 100644 index 0000000000000000000000000000000000000000..47b03cf8ed433bc333d0486197b0ecc6f9820fc3 --- /dev/null +++ b/district/migrations/0056_alter_districtcenterpage_sidebar_content_and_more.py @@ -0,0 +1,175 @@ +# 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), + ] diff --git a/district/models.py b/district/models.py index e08306c850220293b62631f7340e9388a011428f..2d51744f97f4bdf724faa4918e0184299f2df390 100644 --- a/district/models.py +++ b/district/models.py @@ -899,7 +899,7 @@ class DistrictCenterPage(CalendarMixin, SubpageMixin, MetadataPageMixin, Page): verbose_name="Obsah", blank=True, ) - text = RichTextField("Text", null=True) + text = RichTextField("Text", blank=True, null=True) sidebar_content = StreamField( [("address", blocks.AddressBlock()), ("contact", blocks.CenterContactBlock())], verbose_name="Obsah bočního panelu", diff --git a/district/templates/district/blocks/contact_block.html b/district/templates/district/blocks/contact_block.html index 55406a14140e676dc5cb9586635eae17e884da80..162d56baa64a2843fc9046006f39c2acaea76d7a 100644 --- a/district/templates/district/blocks/contact_block.html +++ b/district/templates/district/blocks/contact_block.html @@ -2,8 +2,10 @@ {{ self.title }} </h2> -{% for person_page in self.contact_list %} - <div class="{% if not forloop.last %}mb-4{% endif %}"> - {% include "shared/person_badge_snippet.html" %} - </div> -{% endfor %} +<div class="space-y-4"> + {% for contact_details in self.contact_list %} + {% with contact_details.person as person_page %} + {% include "shared/person_badge_snippet.html" with title=contact_details.position|default:person_page.job_function %} + {% endwith %} + {% endfor %} +</div> diff --git a/district/templates/district/district_center_page.html b/district/templates/district/district_center_page.html index a4c194bd948ce00f1bc8d63f334235684233af7b..488d677872f4295cf5e8d4f4ca8acd1cb9d2004e 100644 --- a/district/templates/district/district_center_page.html +++ b/district/templates/district/district_center_page.html @@ -9,30 +9,35 @@ {{ page.title }} </h1> <h2 class="head-xs mt-2"> - {{ page.subtitle }} + {{ page.perex }} </h2> </div> </aside> {% endblock %} +{% block container_spacing %}pt-8 lg:pb-16{% endblock %} + {% block content %} <article> <div class="lg:flex lg:space-x-8 xl:space-x-16"> <div class="lg:w-3/5 xl:w-2/3"> <div class="content-block"> {{ page.text | richtext }} - {% for block in page.content %} - {% include_block block %} - {% endfor %} + + {% for block in page.content %} + {% include_block block %} + {% endfor %} </div> {% include "shared/small_calendar_snippet.html" %} </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__body"> <div class="content-block"> {% for block in page.sidebar_content %} {% include_block block %} + {% if not forloop.last %} <hr> {% endif %} diff --git a/region/blocks.py b/region/blocks.py index 9513750f4468d947bb68d7bfb4114759de0ed239..feb697d799ede3f47dd5d622382a81eaa180115f 100644 --- a/region/blocks.py +++ b/region/blocks.py @@ -125,12 +125,14 @@ class CardLinkWithHeadlineBlock(StructBlock): 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): title = CharBlock(label="Titulek", required=True) - contact_list = ListBlock( - PageChooserBlock(label="Osoba", page_type=["region.RegionPersonPage"]), - label="List kontaktů", - ) + contact_list = ListBlock(CenterContactPersonBlock()) class Meta: template = "region/blocks/contact_block.html" diff --git a/region/migrations/0031_alter_regioncenterpage_sidebar_content.py b/region/migrations/0031_alter_regioncenterpage_sidebar_content.py new file mode 100644 index 0000000000000000000000000000000000000000..0fe7cbd7c176a811da70f2673b59f9e86c0d48b0 --- /dev/null +++ b/region/migrations/0031_alter_regioncenterpage_sidebar_content.py @@ -0,0 +1,175 @@ +# 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), + ] diff --git a/region/models.py b/region/models.py index 15bf1bdf12826af564040891aa026ce88a23a2c9..434ed8deb13b605a45c15ce9adc5d07dfdc527bb 100644 --- a/region/models.py +++ b/region/models.py @@ -885,7 +885,7 @@ class RegionCenterPage(CalendarMixin, SubpageMixin, MetadataPageMixin, Page): verbose_name="Obsah", blank=True, ) - text = RichTextField("Text", null=True) + text = RichTextField("Text", blank=True, null=True) sidebar_content = StreamField( [("address", blocks.AddressBlock()), ("contact", blocks.CenterContactBlock())], verbose_name="Obsah bočního panelu", diff --git a/region/templates/region/blocks/contact_block.html b/region/templates/region/blocks/contact_block.html index 55406a14140e676dc5cb9586635eae17e884da80..162d56baa64a2843fc9046006f39c2acaea76d7a 100644 --- a/region/templates/region/blocks/contact_block.html +++ b/region/templates/region/blocks/contact_block.html @@ -2,8 +2,10 @@ {{ self.title }} </h2> -{% for person_page in self.contact_list %} - <div class="{% if not forloop.last %}mb-4{% endif %}"> - {% include "shared/person_badge_snippet.html" %} - </div> -{% endfor %} +<div class="space-y-4"> + {% for contact_details in self.contact_list %} + {% with contact_details.person as person_page %} + {% include "shared/person_badge_snippet.html" with title=contact_details.position|default:person_page.job_function %} + {% endwith %} + {% endfor %} +</div> diff --git a/region/templates/region/region_center_page.html b/region/templates/region/region_center_page.html index 5206ea08ffd029e2fc4f864ec02c447c40f79ea8..74d3c2e028bf30625067f00ab014a341baa26aa9 100644 --- a/region/templates/region/region_center_page.html +++ b/region/templates/region/region_center_page.html @@ -9,30 +9,35 @@ {{ page.title }} </h1> <h2 class="head-xs mt-2"> - {{ page.subtitle }} + {{ page.perex }} </h2> </div> </aside> {% endblock %} +{% block container_spacing %}pt-8 lg:pb-16{% endblock %} + {% block content %} <article> <div class="lg:flex lg:space-x-8 xl:space-x-16"> <div class="lg:w-3/5 xl:w-2/3"> <div class="content-block"> {{ page.text | richtext }} - {% for block in page.content %} - {% include_block block %} - {% endfor %} + + {% for block in page.content %} + {% include_block block %} + {% endfor %} </div> {% include "shared/small_calendar_snippet.html" %} </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__body"> <div class="content-block"> {% for block in page.sidebar_content %} {% include_block block %} + {% if not forloop.last %} <hr> {% endif %} diff --git a/shared/templates/shared/followus_snippet_column.html b/shared/templates/shared/followus_snippet_column.html index fead8e5412647420126c60a0db2e935af563dfb4..1834a2382d1dea0d5ea84fcc0a87f98f57f6f0ab 100644 --- a/shared/templates/shared/followus_snippet_column.html +++ b/shared/templates/shared/followus_snippet_column.html @@ -1,12 +1,12 @@ -<div class="flex flex-col"> +<div class="flex flex-col lg:space-y-4"> <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> <i class="super-button__icon ico--facebook"></i> </a> <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> <i class="super-button__icon ico--bubbles"></i> </a>