From 49d4ebf3098d049bdca081946a150a9ab3e3d38d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Valenta?= <git@imaniti.org> Date: Fri, 5 Jan 2024 21:12:18 +0100 Subject: [PATCH] add program & news section --- elections/blocks.py | 47 +++++++++++++++++++ .../0012_alter_electionshomepage_content.py | 21 +++++++++ elections/models.py | 4 +- elections/templatetags/rawtext.py | 8 ++++ main/blocks.py | 13 ----- main/models.py | 2 +- shared/blocks/main.py | 13 +++++ .../molecules/program/card_program.html | 39 +++++++++++++++ .../organisms/articles/articles_section.html | 14 ++++-- .../elections/candidate_primary_list.html | 6 +-- 10 files changed, 146 insertions(+), 21 deletions(-) create mode 100644 elections/migrations/0012_alter_electionshomepage_content.py create mode 100644 elections/templatetags/rawtext.py create mode 100644 shared/templates/styleguide2/includes/molecules/program/card_program.html diff --git a/elections/blocks.py b/elections/blocks.py index 46fb15f7..dca84ab9 100644 --- a/elections/blocks.py +++ b/elections/blocks.py @@ -3,7 +3,10 @@ from wagtail.images.blocks import ImageChooserBlock from wagtail.blocks import ( RichTextBlock, TextBlock, + CharBlock, + IntegerBlock, PageChooserBlock, + URLBlock, ListBlock ) @@ -53,3 +56,47 @@ class CandidateListBlock(StructBlock): template = "styleguide2/includes/organisms/candidates/elections/candidate_primary_list.html" icon = "form" label = "Seznam kandidátů" + + +class ProgramCategoryItemBlock(StructBlock): + number = IntegerBlock(label="Číslo") + + content = TextBlock(label="Obsah") + + class Meta: + icon = "form" + label = "Bod" + + +class ProgramCategoryBlock(StructBlock): + number = IntegerBlock( + label="Číslo" + ) + + name = CharBlock( + label="Název" + ) + + points = ListBlock( + ProgramCategoryItemBlock(), + label="Body" + ) + + class Meta: + icon = "form" + label = "Kategorie" + + +class ProgramBlock(StructBlock): + categories = ListBlock( + ProgramCategoryBlock(), + label="Kategorie" + ) + + long_version_url = URLBlock(label="Odkaz na celou verzi programu") + long_version_text = CharBlock(label="Nadpis odkazu na celou verzi programu") + + class Meta: + icon = "form" + label = "Vyskakovací program" + template = "styleguide2/includes/molecules/program/card_program.html" diff --git a/elections/migrations/0012_alter_electionshomepage_content.py b/elections/migrations/0012_alter_electionshomepage_content.py new file mode 100644 index 00000000..f87db9df --- /dev/null +++ b/elections/migrations/0012_alter_electionshomepage_content.py @@ -0,0 +1,21 @@ +# Generated by Django 4.1.10 on 2024-01-05 19:47 + +from django.db import migrations +import wagtail.blocks +import wagtail.fields +import wagtail.images.blocks + + +class Migration(migrations.Migration): + + dependencies = [ + ('elections', '0011_alter_electionshomepage_content'), + ] + + 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í'))])), ('candidate', 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(help_text='Pokud zůstane prázdné, použije se popis ze stránky kandidáta', label='Popis', 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.RichTextBlock(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'))]))], blank=True, use_json_field=True, verbose_name='Hlavní obsah'), + ), + ] diff --git a/elections/models.py b/elections/models.py index 405a7424..6e3b52c4 100644 --- a/elections/models.py +++ b/elections/models.py @@ -55,7 +55,9 @@ class ElectionsHomePage(MainHomePageMixin): content = StreamField( [ ("carousel", blocks.ElectionsCarouselBlock()), - ("candidate", blocks.CandidateListBlock()) + ("candidate", blocks.CandidateListBlock()), + ("program", blocks.ProgramBlock()), + ("news", shared_blocks.NewsBlock(template="styleguide2/includes/organisms/articles/elections/articles_section.html")), ], verbose_name="Hlavní obsah", blank=True, diff --git a/elections/templatetags/rawtext.py b/elections/templatetags/rawtext.py new file mode 100644 index 00000000..252fe722 --- /dev/null +++ b/elections/templatetags/rawtext.py @@ -0,0 +1,8 @@ +from django import template + +register = template.Library() + + +@register.filter +def rawtext(source_text_block) -> str: + return str(source_text_block) diff --git a/main/blocks.py b/main/blocks.py index e3778a26..975b3cdc 100644 --- a/main/blocks.py +++ b/main/blocks.py @@ -103,19 +103,6 @@ class HomePageCarouseSlideBlock(StructBlock): label = "Carousel" -class NewsBlock(StructBlock): - title = CharBlock( - label="Titulek", - help_text="Nejnovější články se načtou automaticky", - ) - description = TextBlock(label="Popis") - - class Meta: - template = "styleguide2/includes/organisms/articles/articles_section.html" - icon = "doc-full-inverse" - label = "Novinky" - - class EuroparlNewsBlock(StructBlock): class Meta: template = ( diff --git a/main/models.py b/main/models.py index 726eb1d8..9b2f29f5 100644 --- a/main/models.py +++ b/main/models.py @@ -55,7 +55,7 @@ class MainHomePage(MainHomePageMixin): content = StreamField( [ ("carousel", blocks.HomePageCarouseSlideBlock()), - ("news", blocks.NewsBlock()), + ("news", shared_blocks.NewsBlock(template="styleguide2/includes/organisms/articles/articles_section.html")), ("europarl_news", blocks.EuroparlNewsBlock()), ("people", blocks.PeopleOverviewBlock()), ("regions", blocks.RegionsBlock()), diff --git a/shared/blocks/main.py b/shared/blocks/main.py index 60483e8e..3a5cbbe8 100644 --- a/shared/blocks/main.py +++ b/shared/blocks/main.py @@ -5,6 +5,7 @@ from wagtail.blocks import ( PageChooserBlock, RichTextBlock, StructBlock, + TextBlock, URLBlock, ) from wagtail.documents.blocks import DocumentChooserBlock @@ -68,6 +69,18 @@ class SocialLinkBlock(LinkBlock): # Articles +class NewsBlock(StructBlock): + title = CharBlock( + label="Titulek", + help_text="Nejnovější články se načtou automaticky", + ) + description = TextBlock(label="Popis") + + class Meta: + icon = "doc-full-inverse" + label = "Novinky" + + class ArticleQuoteBlock(StructBlock): quote = CharBlock(label="Citace") autor_name = CharBlock(label="Jméno autora") diff --git a/shared/templates/styleguide2/includes/molecules/program/card_program.html b/shared/templates/styleguide2/includes/molecules/program/card_program.html new file mode 100644 index 00000000..fae1fd84 --- /dev/null +++ b/shared/templates/styleguide2/includes/molecules/program/card_program.html @@ -0,0 +1,39 @@ +{% load rawtext %} + +<div class="bg-pirati-yellow"> + <div + class="__js-root container--wide" + id="program" + > + <ui-card-program + :points=" + [ + {% for category in self.categories %} + { + slug: '{{ category.number }}', + number: {{ category.number }}, + title: '{{ category.name }}', + points: [ + {% for point in category.points %} + { + number: '{{ point.number }}', + content: '{{ point.content|rawtext }}' + }{% if not forloop.last %},{% endif %} + {% endfor %} + ] + }{% if not forloop.last %},{% endif %} + {% endfor %} + ] + " + ></ui-card-program> + + <!-- Make this accessible without JS, at least --> + <a + class="text-xl font-bold pl-4" + href="{{ self.long_version_url }}" + > + <i class="ico--chevron-right"></i> + {{ self.long_version_text }} + </a> + </div> +</div> diff --git a/shared/templates/styleguide2/includes/organisms/articles/articles_section.html b/shared/templates/styleguide2/includes/organisms/articles/articles_section.html index 56b9b04e..50649d85 100644 --- a/shared/templates/styleguide2/includes/organisms/articles/articles_section.html +++ b/shared/templates/styleguide2/includes/organisms/articles/articles_section.html @@ -1,6 +1,12 @@ {% load wagtailcore_tags wagtailimages_tags shared_perex %} -<div class="bg-black text-white"> +<div + class=" + {% block wrapper_classes %} + bg-black text-white + {% endblock %} + " +> <div class="container--medium __js-root"> <div class=" @@ -33,9 +39,11 @@ <div class=" - flex justify-center pb-0 pt-12 + {% block button_wrapper_classes %} + flex justify-center pt-12 - xl:py-24 + xl:py-24 + {% endblock %} " > {% include "styleguide2/includes/atoms/buttons/round_button.html" with button_text="Více článků" classes="bg-white text-black" url=page.root_page.articles_page.url %} diff --git a/shared/templates/styleguide2/includes/organisms/candidates/elections/candidate_primary_list.html b/shared/templates/styleguide2/includes/organisms/candidates/elections/candidate_primary_list.html index d87a6a69..8c8c8ef3 100644 --- a/shared/templates/styleguide2/includes/organisms/candidates/elections/candidate_primary_list.html +++ b/shared/templates/styleguide2/includes/organisms/candidates/elections/candidate_primary_list.html @@ -1,11 +1,11 @@ -{% load wagtailimages_tags %} +{% load wagtailimages_tags wagtailcore_tags %} <ul class="candidate-primary-list __js-root" - id="{{ id }}" + id="kandidati" > {% for candidate in self.candidates %} - {% firstof candidate.description candidate.page.description as description %} + {% firstof candidate.description candidate.page.perex as description %} {% if candidate.image %} {% image candidate.image original as resized_candidate_image %} -- GitLab