diff --git a/donate/blocks.py b/donate/blocks.py index 304c126b21da297dfe8adc31adaffb05f215b550..1ac2a05518627e1b36da99fca4e2039d7380fb7c 100644 --- a/donate/blocks.py +++ b/donate/blocks.py @@ -6,12 +6,39 @@ from wagtail.blocks import ( RichTextBlock, StructBlock, URLBlock, + PageChooserBlock, ) from wagtail.images.blocks import ImageChooserBlock from donate.constants import RICH_TEXT_FEATURES +class ProjectIndexBlock(StructBlock): + page = PageChooserBlock(page_type="donate.DonateProjectIndexPage") + + class Meta: + template = "donate/blocks/project_index_block.html" + label = "Seznam projektů" + + +class DistrictDonationBlock(StructBlock): + heading = CharBlock(label="Nadpis") + description = RichTextBlock(label="Obsah", features=RICH_TEXT_FEATURES) + + class Meta: + template = "donate/blocks/district_donation_block.html" + label = "Seznam projektů" + + +class PartySupportFormBlock(StructBlock): + heading = CharBlock(label="Nadpis") + description = RichTextBlock(label="Obsah", features=RICH_TEXT_FEATURES) + + class Meta: + template = "donate/blocks/party_support_form_block.html" + label = "Seznam projektů" + + class CrowdfundingRewardBlock(StructBlock): title = CharBlock(label="Název odměny") description = CharBlock(label="Popis", max_length=255, required=False) diff --git a/donate/migrations/0035_remove_donatehomepage_project_body_and_more.py b/donate/migrations/0035_remove_donatehomepage_project_body_and_more.py new file mode 100644 index 0000000000000000000000000000000000000000..d8a9895f35aa30ab75a1313b37d5ef88e5f4cee6 --- /dev/null +++ b/donate/migrations/0035_remove_donatehomepage_project_body_and_more.py @@ -0,0 +1,28 @@ +# Generated by Django 4.1.10 on 2023-10-18 17:48 + +from django.db import migrations +import wagtail.blocks +import wagtail.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('donate', '0034_donatehomepage_menu'), + ] + + operations = [ + migrations.RemoveField( + model_name='donatehomepage', + name='project_body', + ), + migrations.RemoveField( + model_name='donatehomepage', + name='project_title', + ), + migrations.AddField( + model_name='donatehomepage', + name='content_blocks', + field=wagtail.fields.StreamField([('project_index', wagtail.blocks.StructBlock([('page', wagtail.blocks.PageChooserBlock(page_type=['donate.DonateProjectIndexPage']))]))], blank=True, use_json_field=True, verbose_name='Obsah'), + ), + ] diff --git a/donate/migrations/0036_remove_donateprojectindexpage_support_position_and_more.py b/donate/migrations/0036_remove_donateprojectindexpage_support_position_and_more.py new file mode 100644 index 0000000000000000000000000000000000000000..6863f5833f9b4b4e28df5cce0f6a3d12ae8dc003 --- /dev/null +++ b/donate/migrations/0036_remove_donateprojectindexpage_support_position_and_more.py @@ -0,0 +1,24 @@ +# Generated by Django 4.1.10 on 2023-10-18 19:40 + +from django.db import migrations +import wagtail.blocks +import wagtail.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('donate', '0035_remove_donatehomepage_project_body_and_more'), + ] + + operations = [ + migrations.RemoveField( + model_name='donateprojectindexpage', + name='support_position', + ), + migrations.AlterField( + model_name='donatehomepage', + name='content_blocks', + field=wagtail.fields.StreamField([('project_index', wagtail.blocks.StructBlock([('page', wagtail.blocks.PageChooserBlock(page_type=['donate.DonateProjectIndexPage']))])), ('district_donation', wagtail.blocks.StructBlock([]))], blank=True, use_json_field=True, verbose_name='Obsah'), + ), + ] diff --git a/donate/models.py b/donate/models.py index 2f667776051c3b4be61ee11db16455b14029f866..a042e8b1569c302f1ebbd2249b238bf3a287e5a4 100644 --- a/donate/models.py +++ b/donate/models.py @@ -29,7 +29,7 @@ from shared.models import ( from shared.utils import get_subpage_url, make_promote_panels from tuning import admin_help -from .blocks import CrowdfundingRewardBlock, CustomContentBlock +from .blocks import CrowdfundingRewardBlock, CustomContentBlock, ProjectIndexBlock, DistrictDonationBlock, PartySupportFormBlock from .forms import DonateForm from .menu import MenuMixin from .utils import get_donated_amount_from_api @@ -114,8 +114,6 @@ class DonateHomePage( verbose_name="náhled videa", ) # support section - support_title = models.CharField("podpoř stranu nadpis", max_length=250, blank=True) - support_body = models.TextField("podpoř stranu popis", blank=True) support_image = models.ForeignKey( "wagtailimages.Image", on_delete=models.PROTECT, @@ -125,13 +123,16 @@ class DonateHomePage( verbose_name="Obrázek k darovacímu widgetu", ) # projects section - project_title = models.CharField( - "podpoř projekt nadpis", max_length=250, blank=True + content_blocks = StreamField( + [ + ("project_index", ProjectIndexBlock()), + ("district_donation", DistrictDonationBlock()), + ("party_support_form", PartySupportFormBlock()) + ], + blank=True, + use_json_field=True, + verbose_name="Obsah", ) - project_body = models.TextField("podpoř projekt popis", blank=True) - # 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())], @@ -184,14 +185,7 @@ class DonateHomePage( ], "podpoř stranu", ), - MultiFieldPanel( - [FieldPanel("project_title"), FieldPanel("project_body")], - "podpoř projekt", - ), - MultiFieldPanel( - [FieldPanel("region_title"), FieldPanel("region_body")], - "podpoř kraj", - ), + FieldPanel("content_blocks"), FieldPanel("custom_blocks"), ] @@ -295,21 +289,6 @@ class DonateHomePage( self.get_descendants().type(DonateRegionPage).live().specific() ) - context["project_support_blocks"] = [] - - for project_index in self.project_indexes.order_by("support_position"): - block = {} - - block["index"] = project_index - block["projects"] = ( - DonateProjectPage.objects.child_of(project_index) - .live() - .specific() - .order_by("-date")[:3] - ) - - context["project_support_blocks"].append(block) - return context @@ -419,11 +398,6 @@ class DonateProjectIndexPage( support_heading = models.CharField("Podpoř projekt nadpis", max_length=32) support_description = RichTextField("Podpoř projekt popis") - support_position = models.IntegerField( - "Podpoř projekt pozice", - help_text="Čím nižší číslo, tím výš se seznam projektů zobrazí.", - default=0, - ) ### PANELS @@ -433,7 +407,6 @@ class DonateProjectIndexPage( [ FieldPanel("support_heading"), FieldPanel("support_description"), - FieldPanel("support_position"), ], "Informace v sekci 'podpoř projekt' na homepage", ), @@ -453,6 +426,16 @@ class DonateProjectIndexPage( # flag for rendering anchor links in menu is_home = False + @property + def projects(self): + return ( + DonateProjectPage. + objects. + child_of(self). + distinct(). + all() + ) + class Meta: verbose_name = "Přehled projektů" @@ -671,8 +654,8 @@ class DonateTextPage(Page, ExtendedMetadataPageMixin, SubpageMixin, MetadataPage ### RELATIONS - parent_page_types = ["donate.DonateHomePage", "donate.DonateTextPage"] - subpage_types = ["donate.DonateTextPage"] + parent_page_types = ["donate.DonateHomePage", "donate.DonateTextPage", "donate.DonateInfoPage"] + subpage_types = ["donate.DonateTextPage", "donate.DonateInfoPage"] ### OTHERS @@ -722,8 +705,8 @@ class DonateInfoPage( ### RELATIONS - parent_page_types = ["donate.DonateHomePage"] - subpage_types = [] + parent_page_types = ["donate.DonateHomePage", "donate.DonateTextPage", "donate.DonateInfoPage"] + subpage_types = ["donate.DonateTextPage", "donate.DonateInfoPage"] ### OTHERS diff --git a/donate/templates/donate/blocks/district_donation_block.html b/donate/templates/donate/blocks/district_donation_block.html new file mode 100644 index 0000000000000000000000000000000000000000..902ae6d54415495050c03c3f5f3c62a622633a11 --- /dev/null +++ b/donate/templates/donate/blocks/district_donation_block.html @@ -0,0 +1,12 @@ +<section class="section--{% get_section_kind %}" id="kraje"> + <div class="container"> + <h2 class="lead page-subheading mb-4">{{ self.heading }}</h2> + <p class="mb-4">{{ self.description|richtext }}</p> + <div class="row mb-4"> + + <!-- TODO --> + {% include "donate/region_map_snippet.html" with index_url=page.regions_page_url %} + + </div> <!-- /row --> + </div> <!-- /container --> +</section> diff --git a/donate/templates/donate/blocks/party_support_form_block.html b/donate/templates/donate/blocks/party_support_form_block.html new file mode 100644 index 0000000000000000000000000000000000000000..720764dd45ad557475ccb3ff30e6c84a111c7406 --- /dev/null +++ b/donate/templates/donate/blocks/party_support_form_block.html @@ -0,0 +1,60 @@ +<section class="section--{% get_section_kind %}" id="strana"> + <div class="container"> + <h2 class="lead page-subheading mb-4">{{ self.heading }}</h2> + <p class="mb-4">{{ self.description|richtext }}</p> + <div class="donate-form"> + {% if self.image %} + <div class="donate-form__left"> + <div class="donate-form__icon"> + {% image self.image fill-256x256 as img %} + <img data-src="{{ img.url }}" class="lazyload img-fluid" alt="{{ img.alt }}"> + </div><!-- /donate-form__icon --> + </div><!-- /donate-form__left --> + {% endif %} + <div class="donate-form__right"> + <form id="js-donate-form" method="post"> + {% csrf_token %} + <input type="hidden" name="portal_project_id" value="{{ self.portal_project_id }}"> + <div class="form-group row mb-4 align-items-center"> + <legend class="col-form-label col-md-4 col-form-label-lg">Typ příspěvku</legend> + <div class="col-md-8"> + <div class="custom-control custom-radio custom-control-inline"> + <input type="radio" id="periodicity1" name="periodicity" value="730" class="custom-control-input" checked required> + <label class="custom-control-label col-form-label-lg" for="periodicity1">Měsíční</label> + </div> + <div class="custom-control custom-radio custom-control-inline"> + <input type="radio" id="periodicity2" name="periodicity" value="99999" class="custom-control-input"> + <label class="custom-control-label col-form-label-lg" for="periodicity2">Jednorázový</label> + </div> + </div> + </div> + <div class="form-group row mb-4 align-items-center"> + <legend class="col-form-label col-md-4 col-form-label-lg">Částka</legend> + <div class="col-md-8"> + <div id="monthlyAmounts" data-default-selected="{{ self.form_monthly_preselected }}"> + {% include "donate/form_monthly_amounts_snippet.html" %} + </div> + <div id="oneTimeAmounts" style="display: None" data-default-selected="{{ self.form_preselected }}"> + {% include "donate/form_amounts_snippet.html" %} + </div> + </div> + </div> + <div class="form-group row mb-0 align-items-center" id="js-custom-amount-input"> + <div class="col-md-4 order-md-0 order-1"> + <button type="submit" class="btn btn-danger btn-lg">Darovat</button> + </div> + <div class="col-md-8 mb-4 mb-md-0"> + <div class="input-group input-group-lg mb-0 custom-amount"> + <input type="number" class="form-control" id="customamount" placeholder="Jiná částka" name="custom_amount" aria-describedby="customamount-currency"> + <div class="input-group-append"> + <span class="input-group-text" id="customamount-currency">Kč</span> + </div> + </div> + </div> + </div> + </form> + + </div><!-- /donate-form__right --> + </div><!-- /donate-form --> + </div> <!-- /container --> +</section> diff --git a/donate/templates/donate/blocks/project_index_block.html b/donate/templates/donate/blocks/project_index_block.html new file mode 100644 index 0000000000000000000000000000000000000000..69a128559386dd041741b031ec58a53405a4970d --- /dev/null +++ b/donate/templates/donate/blocks/project_index_block.html @@ -0,0 +1,16 @@ +{% load static wagtailimages_tags wagtailcore_tags donate_tags %} + +<section class="section--{% get_section_kind %}" id="projekty-{{ self.page.id }}"> + <div class="container"> + <h2 class="lead page-subheading mb-4">{{ self.page.support_heading }}</h2> + <p class="mb-4">{{ self.page.support_description|richtext }}</p> + + <div class="row projects mb-4"> + {% for project in self.page.projects %} + {% include "donate/project_snippet.html" %} + {% endfor %} + </div> <!-- /row --> + + <a href="{{ self.page.url }}" class="btn btn-dark btn-lg my-2">Všechny projekty a kampaně <i class="icon-chevron-right ml-2"></i></a> + </div> <!-- /container --> +</section> diff --git a/donate/templates/donate/donate_home_page.html b/donate/templates/donate/donate_home_page.html index 65c79984be6c4e577ee3940bf08b6bc8fb664670..62b7ace352c51b022d76405635f658e7b335c837 100644 --- a/donate/templates/donate/donate_home_page.html +++ b/donate/templates/donate/donate_home_page.html @@ -37,98 +37,8 @@ </div> <!-- /container --> </section> - {% if page.show_donate_form %} - <section class="section--{% get_section_kind %}" id="strana"> - <div class="container"> - <h2 class="lead page-subheading mb-4">{{ page.support_title }}</h2> - <p class="mb-4">{{ page.support_body }}</p> - <div class="donate-form"> - {% if page.support_image %} - <div class="donate-form__left"> - <div class="donate-form__icon"> - {% image page.support_image fill-256x256 as img %} - <img data-src="{{ img.url }}" class="lazyload img-fluid" alt="{{ img.alt }}"> - </div><!-- /donate-form__icon --> - </div><!-- /donate-form__left --> - {% endif %} - <div class="donate-form__right"> - <form id="js-donate-form" method="post"> - {% csrf_token %} - <input type="hidden" name="portal_project_id" value="{{ page.portal_project_id }}"> - <div class="form-group row mb-4 align-items-center"> - <legend class="col-form-label col-md-4 col-form-label-lg">Typ příspěvku</legend> - <div class="col-md-8"> - <div class="custom-control custom-radio custom-control-inline"> - <input type="radio" id="periodicity1" name="periodicity" value="730" class="custom-control-input" checked required> - <label class="custom-control-label col-form-label-lg" for="periodicity1">Měsíční</label> - </div> - <div class="custom-control custom-radio custom-control-inline"> - <input type="radio" id="periodicity2" name="periodicity" value="99999" class="custom-control-input"> - <label class="custom-control-label col-form-label-lg" for="periodicity2">Jednorázový</label> - </div> - </div> - </div> - <div class="form-group row mb-4 align-items-center"> - <legend class="col-form-label col-md-4 col-form-label-lg">Částka</legend> - <div class="col-md-8"> - <div id="monthlyAmounts" data-default-selected="{{ page.form_monthly_preselected }}"> - {% include "donate/form_monthly_amounts_snippet.html" %} - </div> - <div id="oneTimeAmounts" style="display: None" data-default-selected="{{ page.form_preselected }}"> - {% include "donate/form_amounts_snippet.html" %} - </div> - </div> - </div> - <div class="form-group row mb-0 align-items-center" id="js-custom-amount-input"> - <div class="col-md-4 order-md-0 order-1"> - <button type="submit" class="btn btn-danger btn-lg">Darovat</button> - </div> - <div class="col-md-8 mb-4 mb-md-0"> - <div class="input-group input-group-lg mb-0 custom-amount"> - <input type="number" class="form-control" id="customamount" placeholder="Jiná částka" name="custom_amount" aria-describedby="customamount-currency"> - <div class="input-group-append"> - <span class="input-group-text" id="customamount-currency">Kč</span> - </div> - </div> - </div> - </div> - </form> - - </div><!-- /donate-form__right --> - </div><!-- /donate-form --> - </div> <!-- /container --> - </section> - {% endif %} - - <section class="section--{% get_section_kind %}" id="kraje"> - <div class="container"> - <h2 class="lead page-subheading mb-4">{{ page.region_title }}</h2> - <p class="mb-4">{{ page.region_body }}</p> - <div class="row mb-4"> - - {% include "donate/region_map_snippet.html" with index_url=page.regions_page_url %} - - </div> <!-- /row --> - </div> <!-- /container --> - </section> - - {% for project_support_block in project_support_blocks %} - {% if project_support_block.projects|length != 0 %} - <section class="section--{% get_section_kind %}" id="projekty-{{ project_support_block.index.id }}"> - <div class="container"> - <h2 class="lead page-subheading mb-4">{{ project_support_block.index.support_heading }}</h2> - <p class="mb-4">{{ project_support_block.index.support_description|richtext }}</p> - - <div class="row projects mb-4"> - {% for project in project_support_block.projects %} - {% include "donate/project_snippet.html" %} - {% endfor %} - </div> <!-- /row --> - - <a href="{{ project_support_block.index.url }}" class="btn btn-dark btn-lg my-2">Všechny projekty a kampaně <i class="icon-chevron-right ml-2"></i></a> - </div> <!-- /container --> - </section> - {% endif %} + {% for block in page.content_blocks %} + {% include_block block %} {% endfor %} {% for content in page.custom_blocks %} diff --git a/donate/templatetags/donate_tags.py b/donate/templatetags/donate_tags.py index f0a5ab68256e0ff9c4e5978bb752dd10d705b0ba..0424fbc0d78d77dc0e2e1cffdf6504de00b99859 100644 --- a/donate/templatetags/donate_tags.py +++ b/donate/templatetags/donate_tags.py @@ -10,3 +10,8 @@ def get_section_kind(context): else: context["current_section"] = "primary" return context["current_section"] + + +@register.filter +def dire(item): + return str(item) + str(type(item))