From 93a64e29cb2bfb0a528215b97ba4202350c5f9b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Valenta?= <tomas@imaniti.org> Date: Fri, 15 Mar 2024 18:59:31 +0100 Subject: [PATCH] elections program on main page, allow missing icons, fix news anchor, add description to program popout category --- elections/models.py | 12 ++++++++++ main/blocks.py | 18 ++++++++++++++- .../0079_alter_mainprogrampage_program.py | 21 ++++++++++++++++++ main/models.py | 1 + main/templates/main/main_program_page.html | 4 ++++ shared/blocks/main.py | 2 ++ .../organisms/articles/articles_section.html | 1 + .../organisms/popouts/popout_list.html | 22 +++++++++++++------ 8 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 main/migrations/0079_alter_mainprogrampage_program.py diff --git a/elections/models.py b/elections/models.py index 8a0e4a6a..534729ec 100644 --- a/elections/models.py +++ b/elections/models.py @@ -6,6 +6,7 @@ from django.db import models from django.forms.models import model_to_dict from django.http import HttpResponseRedirect, JsonResponse from django.shortcuts import redirect, render +from django.template.loader import render_to_string from django.utils import timezone from modelcluster.contrib.taggit import ClusterTaggableManager from modelcluster.fields import ParentalKey @@ -360,3 +361,14 @@ class ElectionsFullProgramPage( class Meta: verbose_name = "Celá verze programu" + + ## OTHERS + def get_main_page_program_render(self): + for block in self.content: + if block.block_type == "popout_block": + return render_to_string( + "styleguide2/includes/organisms/popouts/popout_list.html", + {"categories": block.value["categories"]}, + ) + + return "" diff --git a/main/blocks.py b/main/blocks.py index adb791da..969ecd84 100644 --- a/main/blocks.py +++ b/main/blocks.py @@ -310,7 +310,23 @@ class FlipCardsBlock(StructBlock): template = "styleguide2/includes/organisms/cards/flip_card_list.html" -class ProgramGroupBlockPopout(SharedProgramGroupBlockPopout): +class ElectionsProgramBlock(StructBlock): + title = CharBlock(label="Titulek části programu") + + program_page = PageChooserBlock( + label="Stránka", + page_type=[ + "elections.ElectionsFullProgramPage", + ], + required=False, + ) + + class Meta: + icon = "view" + label = "Program z volebního webu" + + +class ProgramGroupBlockPopout(SharedProgramGroupBlockPopout, ProgramGroupBlockMixin): pass diff --git a/main/migrations/0079_alter_mainprogrampage_program.py b/main/migrations/0079_alter_mainprogrampage_program.py new file mode 100644 index 00000000..4acd4361 --- /dev/null +++ b/main/migrations/0079_alter_mainprogrampage_program.py @@ -0,0 +1,21 @@ +# Generated by Django 4.1.13 on 2024-03-15 16:48 + +from django.db import migrations +import wagtail.blocks +import wagtail.fields +import wagtail.images.blocks + + +class Migration(migrations.Migration): + + dependencies = [ + ('main', '0078_alter_mainprogrampage_program'), + ] + + operations = [ + migrations.AlterField( + model_name='mainprogrampage', + name='program', + field=wagtail.fields.StreamField([('program_group', wagtail.blocks.StructBlock([('title', wagtail.blocks.CharBlock(label='Titulek části programu')), ('point_list', wagtail.blocks.ListBlock(wagtail.blocks.StructBlock([('url', wagtail.blocks.URLBlock(label='Odkaz pokrývající celou tuto část', required=False)), ('icon', wagtail.images.blocks.ImageChooserBlock(label='Ikona', required=False)), ('title', wagtail.blocks.CharBlock(label='Titulek článku programu')), ('text', wagtail.blocks.RichTextBlock(features=['h3', 'h4', 'h5', 'bold', 'italic', 'ol', 'ul', 'hr', 'link', 'document-link', 'image', 'superscript', 'subscript', 'strikethrough', 'blockquote', 'embed'], label='Obsah'))]), label='Jednotlivé články programu'))])), ('program_group_crossroad', wagtail.blocks.StructBlock([('title', wagtail.blocks.CharBlock(label='Titulek části programu')), ('point_list', wagtail.blocks.ListBlock(wagtail.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock(label='Obrázek')), ('title', wagtail.blocks.CharBlock(label='Titulek', required=True)), ('text', wagtail.blocks.RichTextBlock(label='Krátký text pod nadpisem', required=False)), ('page', wagtail.blocks.PageChooserBlock(label='Stránka', page_type=['main.MainArticlesPage', 'main.MainArticlePage', 'main.MainProgramPage', 'main.MainPeoplePage', 'main.MainPersonPage', 'main.MainSimplePage', 'main.MainContactPage', 'main.MainCrossroadPage'], required=False)), ('link', wagtail.blocks.URLBlock(label='Odkaz', required=False))]), label='Karty programu'))])), ('program_group_popout', wagtail.blocks.StructBlock([('title', wagtail.blocks.CharBlock(label='Titulek části programu')), ('categories', wagtail.blocks.ListBlock(wagtail.blocks.StructBlock([('name', wagtail.blocks.CharBlock(label='Název')), ('icon', wagtail.images.blocks.ImageChooserBlock(label='Ikona', required=False)), ('point_list', wagtail.blocks.ListBlock(wagtail.blocks.StructBlock([('title', wagtail.blocks.CharBlock(label='Titulek vyskakovacího bloku')), ('content', wagtail.blocks.RichTextBlock(features=['h3', 'h4', 'h5', 'bold', 'italic', 'ol', 'ul', 'hr', 'link', 'document-link', 'image', 'superscript', 'subscript', 'strikethrough', 'blockquote', 'embed'], label='Obsah'))]), label='Jednotlivé bloky programu'))]), label='Kategorie programu'))]))], blank=True, use_json_field=True, verbose_name='Program'), + ), + ] diff --git a/main/models.py b/main/models.py index 09a4c0a7..45af703e 100644 --- a/main/models.py +++ b/main/models.py @@ -179,6 +179,7 @@ class MainProgramPage( ("program_group", blocks.ProgramGroupBlock()), ("program_group_crossroad", blocks.ProgramGroupBlockCrossroad()), ("program_group_popout", blocks.ProgramGroupBlockPopout()), + ("elections_program", blocks.ElectionsProgramBlock()), ], verbose_name="Program", blank=True, diff --git a/main/templates/main/main_program_page.html b/main/templates/main/main_program_page.html index 67b22811..a5820ecd 100644 --- a/main/templates/main/main_program_page.html +++ b/main/templates/main/main_program_page.html @@ -48,6 +48,10 @@ {% endfor %} </div> </div> + {% elif program.block_type == "elections_program" %} + <div class="mb-12"> + {{ program.value.program_page.get_main_page_program_render|safe }} + </div> {% endif %} </template> {% endfor %} diff --git a/shared/blocks/main.py b/shared/blocks/main.py index c2ebd694..63b88184 100644 --- a/shared/blocks/main.py +++ b/shared/blocks/main.py @@ -184,6 +184,8 @@ class ProgramPopoutCategory(StructBlock): name = CharBlock(label="Název") icon = ImageChooserBlock(label="Ikona", required=False) + description = RichTextBlock(label="Popis", required=False) + point_list = ListBlock(ProgramBlockPopout(), label="Jednotlivé bloky programu") class Meta: diff --git a/shared/templates/styleguide2/includes/organisms/articles/articles_section.html b/shared/templates/styleguide2/includes/organisms/articles/articles_section.html index 3ad61851..bd81692d 100644 --- a/shared/templates/styleguide2/includes/organisms/articles/articles_section.html +++ b/shared/templates/styleguide2/includes/organisms/articles/articles_section.html @@ -6,6 +6,7 @@ bg-black text-white {% endblock %} " + id="aktuality" > <div class="container--medium __js-root"> <div diff --git a/shared/templates/styleguide2/includes/organisms/popouts/popout_list.html b/shared/templates/styleguide2/includes/organisms/popouts/popout_list.html index 3875519d..19a59339 100644 --- a/shared/templates/styleguide2/includes/organisms/popouts/popout_list.html +++ b/shared/templates/styleguide2/includes/organisms/popouts/popout_list.html @@ -1,20 +1,28 @@ -{% load wagtailimages_tags %} +{% load wagtailcore_tags wagtailimages_tags %} <ul class="flex flex-col gap-6"> {% for category in categories %} <li class="grow"> <div class="flex gap-3 mb-3 items-center bg-grey-150 p-5"> - {% image category.icon max-75x75 as icon %} + {% if category.icon %} + {% image category.icon max-75x75 as icon %} - <img - src="{{ icon.url }}" - width="20" - height="20" - > + <img + src="{{ icon.url }}" + width="20" + height="20" + > + {% endif %} <h2 class="font-alt text-2xl">{{ category.name }}</h2> </div> + {% if category.description %} + <div class="prose max-w-screen-lg"> + {{ category.description|richtext }} + </div> + {% endif %} + {% for point in category.point_list %} {% include 'styleguide2/includes/molecules/popouts/popout_point.html' with name=point.title content=point.content %} {% endfor %} -- GitLab