Skip to content
Snippets Groups Projects
Commit 523c0bca authored by Tomáš Valenta's avatar Tomáš Valenta
Browse files

wip - moveable sections

parent f56a0e07
No related branches found
No related tags found
2 merge requests!836Release,!832Add moveable sections to Dary
Pipeline #15098 passed
......@@ -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)
......
# 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'),
),
]
# 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'),
),
]
......@@ -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
......
<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>
<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"></span>
</div>
</div>
</div>
</div>
</form>
</div><!-- /donate-form__right -->
</div><!-- /donate-form -->
</div> <!-- /container -->
</section>
{% 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>
......@@ -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"></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 %}
......
......@@ -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))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment