diff --git a/elections/migrations/0009_remove_electionscandidatepage_related_candidates_and_more.py b/elections/migrations/0009_remove_electionscandidatepage_related_candidates_and_more.py new file mode 100644 index 0000000000000000000000000000000000000000..cdd1afb66f26dfa86347389f67963bfb73f76bbc --- /dev/null +++ b/elections/migrations/0009_remove_electionscandidatepage_related_candidates_and_more.py @@ -0,0 +1,209 @@ +# Generated by Django 4.1.10 on 2024-01-18 09:15 + +import wagtail.blocks +import wagtail.fields +import wagtail.images.blocks +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("elections", "0008_alter_electionshomepage_content"), + ] + + operations = [ + migrations.RemoveField( + model_name="electionscandidatepage", + name="related_candidates", + ), + 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( + help_text="Pro zobrazení odkazu na celou verzi programu musí být obě následující pole vyplněná.", + label="Odkaz na celou verzi programu", + required=False, + ), + ), + ( + "long_version_text", + wagtail.blocks.CharBlock( + label="Nadpis odkazu na celou verzi programu", + required=False, + ), + ), + ] + ), + ), + ( + "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 4d583300cfe4e820acf6f74d6a2198dec1d5bf3e..ee923ab6ecffcff5b4c50ecc01430c5bb015b42b 100644 --- a/elections/models.py +++ b/elections/models.py @@ -226,21 +226,6 @@ class ElectionsCandidatePage( help_text='Např. "Aktuality Mikuláše Peksy".', ) - related_candidates = StreamField( - [ - ( - "candidate", - PageChooserBlock( - page_type="elections.ElectionsCandidatePage", - label="Detail kandidáta", - ), - ) - ], - verbose_name="Další kandidáti", - blank=True, - use_json_field=True, - ) - ## PANELS content_panels = Page.content_panels + [ @@ -251,7 +236,6 @@ class ElectionsCandidatePage( FieldPanel("phone"), FieldPanel("social_links"), FieldPanel("articles_heading"), - FieldPanel("related_candidates"), ] promote_panels = make_promote_panels() @@ -271,6 +255,12 @@ class ElectionsCandidatePage( def get_context(self, request) -> dict: context = super().get_context(request) + context["related_candidates_list"] = ( + ElectionsCandidatePage.objects.filter(~models.Q(id=self.id)) + .order_by("?") + .live()[:3] + ) + context["article_data_list"] = ( ElectionsArticlePage.objects.filter(author_page=self.id) .order_by("-date") diff --git a/elections/templates/elections/elections_candidate_page.html b/elections/templates/elections/elections_candidate_page.html index 488a70e45d748dfc6a0276f1bfa0159158ad0ad0..28dfdfaeb0350d7b4173436f9a4640183355b062 100644 --- a/elections/templates/elections/elections_candidate_page.html +++ b/elections/templates/elections/elections_candidate_page.html @@ -10,8 +10,8 @@ {% include 'styleguide2/includes/organisms/articles/elections/candidate_articles_section.html' with title=page.articles_heading %} {% endif %} - {% if page.related_candidates %} - {% include 'styleguide2/includes/organisms/candidates/elections/candidate_footer_list.html' with candidates=page.related_candidates %} + {% if related_candidates_list %} + {% include 'styleguide2/includes/organisms/candidates/elections/candidate_footer_list.html' with candidates=related_candidates_list %} {% endif %} </main> {% endblock %} diff --git a/shared/templates/styleguide2/includes/organisms/candidates/elections/candidate_footer_list.html b/shared/templates/styleguide2/includes/organisms/candidates/elections/candidate_footer_list.html index 05b4ac76736843367eb7cd58811b13c72952f363..8ead341ba2517b9f608ee0894a5c55498999aca3 100644 --- a/shared/templates/styleguide2/includes/organisms/candidates/elections/candidate_footer_list.html +++ b/shared/templates/styleguide2/includes/organisms/candidates/elections/candidate_footer_list.html @@ -27,7 +27,7 @@ scroller-classes="!text-black" > {% for candidate in candidates %} - {% include 'styleguide2/includes/molecules/candidates/elections/candidate_footer_box.html' with candidate_page=candidate.value %} + {% include 'styleguide2/includes/molecules/candidates/elections/candidate_footer_box.html' with candidate_page=candidate %} {% endfor %} </ui-horizontal-scrollable> </div>