From 2d685fc204f9358caca7263651873d23d2ccd7f0 Mon Sep 17 00:00:00 2001 From: "jindra12.underdark" <jindra12.underdark@gmail.com> Date: Wed, 14 Jun 2023 00:40:27 +0200 Subject: [PATCH] Add custom block creator to main page gifts #205 --- donate/blocks.py | 21 +++++++++- .../0027_donatehomepage_custom_blocks.py | 38 +++++++++++++++++++ donate/models.py | 10 ++++- .../donate/blocks/custom_content_block.html | 9 +++++ donate/templates/donate/donate_home_page.html | 3 ++ 5 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 donate/migrations/0027_donatehomepage_custom_blocks.py create mode 100644 donate/templates/donate/blocks/custom_content_block.html diff --git a/donate/blocks.py b/donate/blocks.py index 9bbeb34b..e69ae07b 100644 --- a/donate/blocks.py +++ b/donate/blocks.py @@ -1,4 +1,12 @@ -from wagtail.blocks import CharBlock, DateBlock, IntegerBlock, ListBlock, StructBlock +from wagtail.blocks import ( + CharBlock, + DateBlock, + IntegerBlock, + ListBlock, + RichTextBlock, + StructBlock, + URLBlock, +) from wagtail.images.blocks import ImageChooserBlock @@ -21,3 +29,14 @@ class CrowdfundingRewardBlock(StructBlock): template = "donate/blocks/crowdfunding_reward_block.html" icon = "pick" label = "Odměna" + + +class CustomContentBlock(StructBlock): + title = CharBlock(label="Nadpis") + content = RichTextBlock(label="Obsah") + link = URLBlock(label="Odkaz") + + class Meta: + template = "donate/blocks/custom_content_block.html" + icon = "doc-full" + label = "Obecný blok" diff --git a/donate/migrations/0027_donatehomepage_custom_blocks.py b/donate/migrations/0027_donatehomepage_custom_blocks.py new file mode 100644 index 00000000..af574911 --- /dev/null +++ b/donate/migrations/0027_donatehomepage_custom_blocks.py @@ -0,0 +1,38 @@ +# Generated by Django 4.1.8 on 2023-06-13 22:19 + +import wagtail.blocks +import wagtail.fields +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("donate", "0026_donateprojectpage_until"), + ] + + operations = [ + migrations.AddField( + model_name="donatehomepage", + name="custom_blocks", + field=wagtail.fields.StreamField( + [ + ( + "content", + wagtail.blocks.StructBlock( + [ + ("title", wagtail.blocks.CharBlock(label="Nadpis")), + ( + "content", + wagtail.blocks.RichTextBlock(label="Obsah"), + ), + ("link", wagtail.blocks.URLBlock(label="Odkaz")), + ] + ), + ) + ], + blank=True, + use_json_field=True, + verbose_name="Obecné bloky", + ), + ), + ] diff --git a/donate/models.py b/donate/models.py index 6a2adcf0..1b908295 100644 --- a/donate/models.py +++ b/donate/models.py @@ -27,7 +27,7 @@ from shared.models import ( from shared.utils import get_subpage_url, make_promote_panels from tuning import admin_help -from .blocks import CrowdfundingRewardBlock +from .blocks import CrowdfundingRewardBlock, CustomContentBlock from .forms import DonateForm from .utils import get_donated_amount_from_api @@ -128,6 +128,13 @@ class DonateHomePage( # regions section region_title = models.CharField("podpoř kraj nadpis", max_length=250, blank=True) region_body = models.TextField("podpoř kraj popis", blank=True) + # custom section + custom_blocks = StreamField( + [("content", CustomContentBlock())], + blank=True, + use_json_field=True, + verbose_name="Obecné bloky", + ) # settings custom_url_1 = models.URLField("Vlastní odkaz 1", blank=True, null=True) custom_url_1_text = models.CharField( @@ -173,6 +180,7 @@ class DonateHomePage( [FieldPanel("region_title"), FieldPanel("region_body")], "podpoř kraj", ), + FieldPanel("custom_blocks"), ] promote_panels = make_promote_panels(admin_help.build(admin_help.IMPORTANT_TITLE)) diff --git a/donate/templates/donate/blocks/custom_content_block.html b/donate/templates/donate/blocks/custom_content_block.html new file mode 100644 index 00000000..09f278dd --- /dev/null +++ b/donate/templates/donate/blocks/custom_content_block.html @@ -0,0 +1,9 @@ +{% load wagtailcore_tags wagtailimages_tags %} + +<div class="container mt-5"> + <h2 class="lead page-subheading mb-4">{{ self.title }}</h2> + <p class="mb-4"> + {{ self.content|richtext }} + </p> + <a href="{{ self.link }}" class="btn btn-dark btn-lg my-2">Chci vědět více <i class="icon-chevron-right ml-2"></i></a> +</div> diff --git a/donate/templates/donate/donate_home_page.html b/donate/templates/donate/donate_home_page.html index bff9be7f..d335a236 100644 --- a/donate/templates/donate/donate_home_page.html +++ b/donate/templates/donate/donate_home_page.html @@ -132,6 +132,9 @@ </div> <!-- /row --> </div> <!-- /container --> + {% for content in page.custom_blocks %} + {% include_block content %} + {% endfor %} </section> </main> -- GitLab