diff --git a/elections/models.py b/elections/models.py index 8a0e4a6a9dcafafbf49b21cbc7e0550ce71512fa..534729eca8e84d1d8cf254186e0fe32e84426bd6 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 adb791dab3b5668cdfe169e98bf140af22c71b88..969ecd8498781f9e3c37906a9bed0e72c71befbc 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 0000000000000000000000000000000000000000..4acd436175c84026f22c6f406eccd8ff10781abc --- /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 09a4c0a7df8b457667647d700629828f9fc83215..45af703ecf7080b3fdc64bcb13ffd4288946e5a6 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 67b22811127a911b5e26bbad1ce02ce77e1f20d6..a5820ecd2ed637be52e4ddfe1a2243e6d2a37a54 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 c2ebd6942a978fe02472b7ce348e0c926c8c4ca6..63b88184ffeea85301f1336b90f4606f62169e02 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 3ad618519e56de72d20dacef45dccb3e8973a20a..bd81692d87a27725702381a12ca55562370f9ae4 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 3875519ddc729adfef4d7654b616e3d086521909..19a59339ba8f253f6b5d37afaccec3ba45169029 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 %}