diff --git a/elections/blocks.py b/elections/blocks.py index 3e64aa1749c8d9cc0443bf921afa174f526dde98..80f372ff26b4d91b91630fb0e5390becd23079c2 100644 --- a/elections/blocks.py +++ b/elections/blocks.py @@ -53,6 +53,39 @@ class CandidateListBlock(StructBlock): label = "Seznam kandidátů" +class SecondaryCandidateBlock(StructBlock): + number = CharBlock(label="Číslo") + + page = PageChooserBlock( + label="Stránka", page_type=["elections.ElectionsCandidatePage"] + ) + + image = ImageChooserBlock( + label="Obrázek", + help_text="Pokud není vybrán, použije se obrázek ze stránky kandidáta", + required=False, + ) + + class Meta: + template = "styleguide2/includes/molecules/candidates/elections/candidate_primary_box.html" + icon = "form" + label = "Kandidát" + + +class CandidateSecondaryListBlock(StructBlock): + heading = CharBlock(label="Nadpis") + + candidates = ListBlock( + SecondaryCandidateBlock(), + label="Kandidáti", + ) + + class Meta: + template = "styleguide2/includes/organisms/candidates/elections/candidate_secondary_list.html" + icon = "form" + label = "Sekundární seznam kandidátů" + + class ProgramCategoryItemBlock(StructBlock): number = IntegerBlock(label="Číslo") diff --git a/elections/migrations/0007_alter_electionshomepage_content.py b/elections/migrations/0007_alter_electionshomepage_content.py new file mode 100644 index 0000000000000000000000000000000000000000..2e7ab39ca1b60ed7a8c34d79343315d71a5fd022 --- /dev/null +++ b/elections/migrations/0007_alter_electionshomepage_content.py @@ -0,0 +1,202 @@ +# Generated by Django 4.1.10 on 2024-01-17 11:38 + +from django.db import migrations +import wagtail.blocks +import wagtail.fields +import wagtail.images.blocks + + +class Migration(migrations.Migration): + dependencies = [ + ("elections", "0006_remove_electionscandidatepage_calendar_and_more"), + ] + + operations = [ + migrations.AlterField( + model_name="electionshomepage", + name="content", + field=wagtail.fields.StreamField( + [ + ( + "carousel", + wagtail.blocks.StructBlock( + [ + ( + "image", + wagtail.images.blocks.ImageChooserBlock( + label="Obrázek na pozadí" + ), + ) + ] + ), + ), + ( + "candidates", + wagtail.blocks.StructBlock( + [ + ( + "candidates", + wagtail.blocks.ListBlock( + wagtail.blocks.StructBlock( + [ + ( + "page", + wagtail.blocks.PageChooserBlock( + label="Stránka", + page_type=[ + "elections.ElectionsCandidatePage" + ], + ), + ), + ( + "image", + wagtail.images.blocks.ImageChooserBlock( + help_text="Pokud není vybrán, použije se obrázek ze stránky kandidáta", + label="Obrázek", + required=False, + ), + ), + ( + "description", + wagtail.blocks.TextBlock( + label="Popis" + ), + ), + ] + ), + label="Kandidáti", + ), + ) + ] + ), + ), + ( + "secondary_candidates", + wagtail.blocks.StructBlock( + [ + ("heading", wagtail.blocks.CharBlock(label="Nadpis")), + ( + "candidates", + wagtail.blocks.ListBlock( + wagtail.blocks.StructBlock( + [ + ( + "number", + wagtail.blocks.CharBlock( + label="Číslo" + ), + ), + ( + "page", + wagtail.blocks.PageChooserBlock( + label="Stránka", + page_type=[ + "elections.ElectionsCandidatePage" + ], + ), + ), + ( + "image", + wagtail.images.blocks.ImageChooserBlock( + help_text="Pokud není vybrán, použije se obrázek ze stránky kandidáta", + label="Obrázek", + required=False, + ), + ), + ] + ), + label="Kandidáti", + ), + ), + ] + ), + ), + ( + "program", + wagtail.blocks.StructBlock( + [ + ( + "categories", + wagtail.blocks.ListBlock( + wagtail.blocks.StructBlock( + [ + ( + "number", + wagtail.blocks.IntegerBlock( + label="Číslo" + ), + ), + ( + "name", + wagtail.blocks.CharBlock( + label="Název" + ), + ), + ( + "points", + wagtail.blocks.ListBlock( + wagtail.blocks.StructBlock( + [ + ( + "number", + wagtail.blocks.IntegerBlock( + label="Číslo" + ), + ), + ( + "content", + wagtail.blocks.TextBlock( + label="Obsah" + ), + ), + ] + ), + label="Body", + ), + ), + ] + ), + label="Kategorie", + ), + ), + ( + "long_version_url", + wagtail.blocks.URLBlock( + label="Odkaz na celou verzi programu" + ), + ), + ( + "long_version_text", + wagtail.blocks.CharBlock( + label="Nadpis odkazu na celou verzi programu" + ), + ), + ] + ), + ), + ( + "news", + wagtail.blocks.StructBlock( + [ + ( + "title", + wagtail.blocks.CharBlock( + help_text="Nejnovější články se načtou automaticky", + label="Titulek", + ), + ), + ( + "description", + wagtail.blocks.TextBlock(label="Popis"), + ), + ], + template="styleguide2/includes/organisms/articles/elections/articles_section.html", + ), + ), + ], + blank=True, + use_json_field=True, + verbose_name="Hlavní obsah", + ), + ), + ] diff --git a/elections/models.py b/elections/models.py index 2129b74cd66a1d58123e06f1ed2bca3c96029974..4d583300cfe4e820acf6f74d6a2198dec1d5bf3e 100644 --- a/elections/models.py +++ b/elections/models.py @@ -56,7 +56,8 @@ class ElectionsHomePage(MainHomePageMixin): content = StreamField( [ ("carousel", blocks.ElectionsCarouselBlock()), - ("candidate", blocks.CandidateListBlock()), + ("candidates", blocks.CandidateListBlock()), + ("secondary_candidates", blocks.CandidateSecondaryListBlock()), ("program", blocks.ProgramBlock()), ( "news", diff --git a/shared/templates/styleguide2/includes/molecules/candidates/elections/candidate_secondary_box.html b/shared/templates/styleguide2/includes/molecules/candidates/elections/candidate_secondary_box.html index 66e97766f1c9e8a71e20c7b2c60c4c9f597c8591..c5fac9ccded8510b20a0a105df5b5ab581fc4835 100644 --- a/shared/templates/styleguide2/includes/molecules/candidates/elections/candidate_secondary_box.html +++ b/shared/templates/styleguide2/includes/molecules/candidates/elections/candidate_secondary_box.html @@ -1,12 +1,14 @@ +{% load wagtailimages_tags %} + <li class="candidate-secondary-box"> <a - href="#" + href="{{ candidate.page.url }}" class=" container--wide py-2 flex gap-6 items-center underline-offset-2 " > <div class="font-bold text-xl"> - {{ number }} + {{ candidate.number }} </div> <div @@ -14,18 +16,24 @@ flex font-bold justify-center items-center rounded-full " > + {% if candidate.image %} + {% image candidate.image original as resized_candidate_image %} + {% else %} + {% image candidate.page.image original as resized_candidate_image %} + {% endif %} + <img - class="rounded-full w-12 h-12 object-cover" - src="{{ image_source }}" + class="w-12 object-cover" + src="{{ resized_candidate_image.url }}" > </div> <div class="flex flex-col lg:flex-row"> - <h4 class="text-xl font-bold">{{ name }}</h4> + <h4 class="text-xl font-bold">{{ candidate.page.title }}</h4> - {% if position %} + {% if candidate.page.position %} <p><span class="hidden lg:inline">,</span> - {{ position }} + {{ candidate.page.position }} </p> {% endif %} </div> diff --git a/shared/templates/styleguide2/includes/organisms/candidates/elections/candidate_secondary_list.html b/shared/templates/styleguide2/includes/organisms/candidates/elections/candidate_secondary_list.html index 178aaf08495eeaf3c8dd43a0b54b07c0f264b841..5fa9968daaeaededb819e174d9ab039e80e1c6da 100644 --- a/shared/templates/styleguide2/includes/organisms/candidates/elections/candidate_secondary_list.html +++ b/shared/templates/styleguide2/includes/organisms/candidates/elections/candidate_secondary_list.html @@ -1,12 +1,9 @@ <ul class="candidate-secondary-list pt-14 pb-16"> <div class="container--wide"> - <h2 class="head-7xl mb-3">Další kandidáti</h2> + <h2 class="head-7xl mb-3">{{ self.heading }}</h2> </div> - {% include "styleguide2/includes/molecules/candidates/elections/candidate_secondary_box.html" %} - {% include "styleguide2/includes/molecules/candidates/elections/candidate_secondary_box.html" %} - {% include "styleguide2/includes/molecules/candidates/elections/candidate_secondary_box.html" %} - {% include "styleguide2/includes/molecules/candidates/elections/candidate_secondary_box.html" %} - {% include "styleguide2/includes/molecules/candidates/elections/candidate_secondary_box.html" %} - {% include "styleguide2/includes/molecules/candidates/elections/candidate_secondary_box.html" %} + {% for candidate in self.candidates %} + {% include "styleguide2/includes/molecules/candidates/elections/candidate_secondary_box.html" %} + {% endfor %} </ul>