From 7d82314df9b159c252a63460049408af84dcc59a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20Farka?= <stepanfarka11@gmail.com> Date: Thu, 9 Jun 2022 15:03:20 +0200 Subject: [PATCH] [ADD] content to district HP --- .../0089_districthomepage_content.py | 122 ++++++++++++++++++ district/models.py | 17 +++ .../district/district_home_page.html | 38 ++++-- 3 files changed, 164 insertions(+), 13 deletions(-) create mode 100644 district/migrations/0089_districthomepage_content.py diff --git a/district/migrations/0089_districthomepage_content.py b/district/migrations/0089_districthomepage_content.py new file mode 100644 index 00000000..6cdefaa5 --- /dev/null +++ b/district/migrations/0089_districthomepage_content.py @@ -0,0 +1,122 @@ +# Generated by Django 4.0.4 on 2022-06-09 12:45 + +import wagtail.core.blocks +import wagtail.core.fields +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("district", "0088_delete_districttagspage"), + ] + + operations = [ + migrations.AddField( + model_name="districthomepage", + name="content", + field=wagtail.core.fields.StreamField( + [ + ( + "text", + wagtail.core.blocks.RichTextBlock( + features=[ + "h2", + "h3", + "h4", + "h5", + "bold", + "italic", + "ol", + "ul", + "hr", + "link", + "document-link", + "image", + "superscript", + "subscript", + "strikethrough", + "blockquote", + ], + label="Textový editor", + ), + ), + ( + "headline", + wagtail.core.blocks.StructBlock( + [ + ( + "headline", + wagtail.core.blocks.CharBlock( + label="Headline", max_length=300, required=True + ), + ), + ( + "style", + wagtail.core.blocks.ChoiceBlock( + choices=[ + ("head-alt-xl", "Bebas XL"), + ("head-alt-lg", "Bebas L"), + ("head-alt-md", "Bebas M"), + ("head-alt-base", "Bebas base"), + ("head-alt-sm", "Bebas SM"), + ("head-alt-xs", "Bebas XS"), + ("head-alt-2xs", "Bebas 2XS"), + ("head-heavy-base", "Roboto base"), + ("head-heavy-sm", "Roboto SM"), + ("head-heavy-xs", "Roboto XS"), + ("head-heavy-2xs", "Roboto 2XS"), + ("head-allcaps-2xs", "Allcaps 2XS"), + ("head-allcaps-3xs", "Allcaps 3XS"), + ("head-allcaps-4xs", "Allcaps 4XS"), + ( + "head-heavy-allcaps-2xs", + "Allcaps heavy 2XS", + ), + ( + "head-heavy-allcaps-3xs", + "Allcaps heavy 3XS", + ), + ( + "head-heavy-allcaps-4xs", + "Allcaps heavy 4XS", + ), + ], + help_text="Náhled si prohlédněte na https://styleguide.pir-test.eu/latest/?p=viewall-atoms-text.", + label="Styl", + ), + ), + ( + "tag", + wagtail.core.blocks.ChoiceBlock( + choices=[ + ("h1", "H1"), + ("h2", "H2"), + ("h3", "H3"), + ("h4", "H4"), + ("h5", "H5"), + ("h6", "H6"), + ], + help_text="Čím nižší číslo, tím vyšší úroveň.", + label="Úroveň nadpisu", + ), + ), + ( + "align", + wagtail.core.blocks.ChoiceBlock( + choices=[ + ("auto", "Automaticky"), + ("center", "Na střed"), + ], + label="Zarovnání", + ), + ), + ] + ), + ), + ], + blank=True, + verbose_name="Obsah stránky", + ), + ), + ] diff --git a/district/models.py b/district/models.py index 2f12b286..d7f79641 100644 --- a/district/models.py +++ b/district/models.py @@ -42,6 +42,7 @@ from shared.blocks import ( DEFAULT_CONTENT_BLOCKS, ButtonGroupBlock, FigureBlock, + HeadlineBlock, YouTubeVideoBlock, ) from shared.const import RICH_TEXT_DEFAULT_FEATURES @@ -72,6 +73,21 @@ class DistrictHomePage( verbose_name="Blok pod headerem", blank=True, ) + + content = StreamField( + [ + ( + "text", + blocks.RichTextBlock( + label="Textový editor", features=RICH_TEXT_DEFAULT_FEATURES + ), + ), + ("headline", HeadlineBlock()), + ], + verbose_name="Obsah stránky", + blank=True, + ) + articles_title = models.CharField("Nadpis článků", max_length=256) election_countdown_datetime = models.DateTimeField( "Datum a čas pro odpočet do voleb", @@ -179,6 +195,7 @@ class DistrictHomePage( content_panels = Page.content_panels + [ StreamFieldPanel("subheader"), + StreamFieldPanel("content"), FieldPanel("articles_title"), FieldPanel("election_countdown_datetime"), FieldPanel("show_calendar_on_hp"), diff --git a/district/templates/district/district_home_page.html b/district/templates/district/district_home_page.html index 315cddb7..9ff39931 100644 --- a/district/templates/district/district_home_page.html +++ b/district/templates/district/district_home_page.html @@ -10,19 +10,31 @@ {% block container_spacing %}pt-8 lg:py-16{% endblock %} {% block content %} - <h2 class="head-alt-md md:head-alt-lg pb-4 lg:pb-8"> - {{ page.articles_title }} - </h2> - <!-- list of articles --> - <div class="article-card-list grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4 lg:gap-8"> - {% for a in page.articles %} - {% include "shared/article_preview.html" with article=a %} - {% endfor %} - </div> - - <div class="mb-8 lg:mb-16"> - {% include "shared/more_articles_snippet.html" %} - </div> + + {% if page.content %} + <div class="mb-8"> + {% for block in page.content %} + {% include_block block %} + {% endfor %} + </div> + {% endif %} + {% if page.articles %} + <div class="content-block"> + <h2 class="clear-both head-alt-md md:head-alt-lg pb-4 lg:pb-8"> + {{ page.articles_title }} + </h2> + <!-- list of articles --> + <div class="article-card-list grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4 lg:gap-8"> + {% for a in page.articles %} + {% include "shared/article_preview.html" with article=a %} + {% endfor %} + </div> + + <div class="mb-8 lg:mb-16"> + {% include "shared/more_articles_snippet.html" %} + </div> + </div> + {% endif %} {% if page.election_countdown_datetime %} <section class="my-8 lg:my-16 container-padding--zero lg:container-padding--auto"> -- GitLab