diff --git a/donate/blocks.py b/donate/blocks.py index e69ae07b892a4cfa748d654ac97ae4b500fdc7f7..304c126b21da297dfe8adc31adaffb05f215b550 100644 --- a/donate/blocks.py +++ b/donate/blocks.py @@ -9,6 +9,8 @@ from wagtail.blocks import ( ) from wagtail.images.blocks import ImageChooserBlock +from donate.constants import RICH_TEXT_FEATURES + class CrowdfundingRewardBlock(StructBlock): title = CharBlock(label="Název odměny") @@ -33,7 +35,7 @@ class CrowdfundingRewardBlock(StructBlock): class CustomContentBlock(StructBlock): title = CharBlock(label="Nadpis") - content = RichTextBlock(label="Obsah") + content = RichTextBlock(label="Obsah", features=RICH_TEXT_FEATURES) link = URLBlock(label="Odkaz") class Meta: diff --git a/donate/constants.py b/donate/constants.py new file mode 100644 index 0000000000000000000000000000000000000000..f6464ce4495d44205eae78fcc81f65696a6596f1 --- /dev/null +++ b/donate/constants.py @@ -0,0 +1,16 @@ +from shared.const import RICH_TEXT_DEFAULT_FEATURES + +# Select colors for rich text editors font color from style guide +font_colors = [ + ("Green", "#4ca971"), + ("Yellow", "#fde119"), + ("Blue", "#027da8"), + ("Cyan", "#004958"), + ("Violet", "#670047"), + ("Red", "#d60d53"), + ("Grey", "#262626"), +] + +RICH_TEXT_FEATURES = RICH_TEXT_DEFAULT_FEATURES + list( + map(lambda color: "font_color_" + color[1], font_colors) +) diff --git a/donate/migrations/0028_donatehomepage_faq_page.py b/donate/migrations/0028_donatehomepage_faq_page.py new file mode 100644 index 0000000000000000000000000000000000000000..fe5a3dd601f3c7fa515c51da7bfc4fd63a271dae --- /dev/null +++ b/donate/migrations/0028_donatehomepage_faq_page.py @@ -0,0 +1,25 @@ +# Generated by Django 4.1.8 on 2023-07-01 00:13 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("donate", "0027_donatehomepage_custom_blocks"), + ] + + operations = [ + migrations.AddField( + model_name="donatehomepage", + name="faq_page", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="FAQ", + to="donate.donatetextpage", + verbose_name="Stránka s FAQ", + ), + ), + ] diff --git a/donate/models.py b/donate/models.py index 1b908295ff6885880b3374e32444e5f7c9a55d86..7d7f9a42cd874e4146cf1ba6097732a0ed9c81f9 100644 --- a/donate/models.py +++ b/donate/models.py @@ -136,6 +136,14 @@ class DonateHomePage( verbose_name="Obecné bloky", ) # settings + faq_page = models.ForeignKey( + "donate.DonateTextPage", + on_delete=models.PROTECT, + blank=True, + null=True, + related_name="FAQ", + verbose_name="Stránka s FAQ", + ) custom_url_1 = models.URLField("Vlastní odkaz 1", blank=True, null=True) custom_url_1_text = models.CharField( "Text vlastního odkazu 1", max_length=128, blank=True @@ -222,6 +230,7 @@ class DonateHomePage( ], "nastavení darů", ), + FieldPanel("faq_page"), ] ### RELATIONS diff --git a/donate/static/donate/assets/css/style.css b/donate/static/donate/assets/css/style.css index 9a2b66acc99065ef01e75e98df281dd59698f491..f63d0d4460948b06e08cca3a7e733ade66e9228f 100644 --- a/donate/static/donate/assets/css/style.css +++ b/donate/static/donate/assets/css/style.css @@ -213,6 +213,10 @@ h3.page-subheading { color: #ffffff; } +.section--custom { + display: flow-root; +} + /* SECTION SIZING */ section { @@ -1199,3 +1203,13 @@ img.full-width { font-style: italic; font-weight: inherit; } + +/* OVERRIDE RICHTEXT IMAGES FOR MAIN PAGE (TODO: find out if we can apply this to all richtext images in donate */ +.section--custom .richtext-image.left { + float: left; + margin-right: 1.5rem; +} +.section--custom .richtext-image.right { + float: right; + margin-left: 1.5rem; +} diff --git a/donate/templates/donate/base.html b/donate/templates/donate/base.html index ebe83001416a47e005c5c925982b157af90d0332..15e12f64055d7a61b12365d8bd4630ad7bf16bbd 100644 --- a/donate/templates/donate/base.html +++ b/donate/templates/donate/base.html @@ -139,6 +139,9 @@ <img src="{% static "donate/img/logo_napis_white.svg" %}" alt="Logo podpoř piráty"> </div> <ul class="footer__menu mt-5"> + {% if page.root_page.faq_page %} + <li><a href={{ page.root_page.faq_page.url }}>FAQ - pravidla pro přijímání darů</a></li> + {% endif %} <li><a href="/osobni-udaje/">Zásady zpracování osobních údajů</a></li> <li><a href="/obchodni-podminky/">Obchodní podmínky</a></li> </ul> diff --git a/donate/templates/donate/blocks/custom_content_block.html b/donate/templates/donate/blocks/custom_content_block.html index 09f278dd46d83d1df4803d5a619d18cecd642745..774224f5afda824d963891dc5c8cc1667fd2d374 100644 --- a/donate/templates/donate/blocks/custom_content_block.html +++ b/donate/templates/donate/blocks/custom_content_block.html @@ -1,9 +1,9 @@ {% load wagtailcore_tags wagtailimages_tags %} -<div class="container mt-5"> +<div class="container"> <h2 class="lead page-subheading mb-4">{{ self.title }}</h2> - <p class="mb-4"> + <div class="mb-4 clearfix"> {{ self.content|richtext }} - </p> + </div> <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 d335a2368063b8f972da1c754ee4e82e39f7740b..9e4e1c9d127afbd0249da24f71624364ceaa2a2e 100644 --- a/donate/templates/donate/donate_home_page.html +++ b/donate/templates/donate/donate_home_page.html @@ -1,12 +1,11 @@ {% extends "donate/base.html" %} -{% load static wagtailimages_tags wagtailcore_tags %} +{% load static wagtailimages_tags wagtailcore_tags donate_tags %} {% block content %} <!-- CONTENT --> <main role="main"> - - <section class="section--alternate section--lead" id="uvod"> + <section class="section--{% get_section_kind %} section--lead" id="uvod"> <div class="container"> <div class="row align-items-center"> @@ -39,7 +38,7 @@ </section> {% if page.show_donate_form %} - <section class="section--primary" id="strana"> + <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> @@ -101,8 +100,20 @@ </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> + {% if page.has_projects %} - <section class="section--alternate" id="projekty"> + <section class="section--{% get_section_kind %}" id="projekty"> <div class="container"> <h2 class="lead page-subheading mb-4">{{ page.project_title }}</h2> @@ -118,25 +129,13 @@ <a href="{{ page.projects_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> - - <section class="section--primary" id="kraje"> - {% else %} - <section class="section--alternate" id="kraje"> {% endif %} - <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 --> - {% for content in page.custom_blocks %} + {% for content in page.custom_blocks %} + <section class="section--{% get_section_kind %} section--custom" id="custom"> {% include_block content %} - {% endfor %} - </section> - + </section> + {% endfor %} </main> <!-- /CONTENT --> diff --git a/donate/templatetags/__init__.py b/donate/templatetags/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/donate/templatetags/donate_tags.py b/donate/templatetags/donate_tags.py new file mode 100644 index 0000000000000000000000000000000000000000..f0a5ab68256e0ff9c4e5978bb752dd10d705b0ba --- /dev/null +++ b/donate/templatetags/donate_tags.py @@ -0,0 +1,12 @@ +from django import template + +register = template.Library() + + +@register.simple_tag(takes_context=True) +def get_section_kind(context): + if "current_section" not in context or context["current_section"] == "primary": + context["current_section"] = "alternate" + else: + context["current_section"] = "primary" + return context["current_section"] diff --git a/donate/wagtail_hooks.py b/donate/wagtail_hooks.py index f4afab3a245381d0789b8a37c92b947f02a884ed..3730252243f1baf2220beeeb514f95a146a595b8 100644 --- a/donate/wagtail_hooks.py +++ b/donate/wagtail_hooks.py @@ -1,7 +1,13 @@ +import wagtail.admin.rich_text.editors.draftail.features as draftail_features from django.utils.html import escape from wagtail import hooks +from wagtail.admin.rich_text.converters.html_to_contentstate import ( + InlineStyleElementHandler, +) from wagtail.rich_text import LinkHandler +from donate.constants import font_colors + class ExternalLinkHandler(LinkHandler): identifier = "external" @@ -15,3 +21,33 @@ class ExternalLinkHandler(LinkHandler): @hooks.register("register_rich_text_features") def register_external_link(features): features.register_link_type(ExternalLinkHandler) + + +@hooks.register("register_rich_text_features") +def register_font_color_feature(features): + for color_name, color_value in font_colors: + feature_name = "font_color_" + color_value + type_ = "FONT_COLOR_" + color_value + tag = "span" + + control = { + "type": type_, + "label": color_name, + "description": color_name + " text color", + "style": {"color": color_value}, + } + + features.register_editor_plugin( + "draftail", feature_name, draftail_features.InlineStyleFeature(control) + ) + + db_conversion = { + "from_database_format": {tag: InlineStyleElementHandler(type_)}, + "to_database_format": { + "style_map": { + type_: {"element": tag, "props": {"style": "color: " + color_value}} + } + }, + } + + features.register_converter_rule("contentstate", feature_name, db_conversion)