From e81758d8a2043670fc3f5234cda347cad3945771 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Valenta?= <git@imaniti.org> Date: Sun, 24 Sep 2023 21:53:38 +0200 Subject: [PATCH] Dary imrovements - add menu, uniweb-like subpage nesting, fix image styling, global styleguide URL --- .pre-commit-config.yaml | 2 +- donate/menu.py | 30 +++++++++++ ...tindexpage_support_description_and_more.py | 2 +- donate/migrations/0034_donatehomepage_menu.py | 50 ++++++++++++++++++ donate/models.py | 29 ++++++++--- donate/static/donate/assets/css/style.css | 52 +++++++++++++++++++ donate/templates/donate/base.html | 32 ++---------- donate/templates/donate/blocks/menu_item.html | 3 ++ majak/context_processors.py | 5 ++ majak/settings/base.py | 3 ++ shared/image_formats.py | 10 ++-- tuning/templates/tuning/sites_list.html | 8 +-- uniweb/templates/uniweb/base.html | 8 +-- uniweb/templates/uniweb/logo_snippet.html | 2 +- 14 files changed, 184 insertions(+), 52 deletions(-) create mode 100644 donate/menu.py create mode 100644 donate/migrations/0034_donatehomepage_menu.py create mode 100644 donate/templates/donate/blocks/menu_item.html create mode 100644 majak/context_processors.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 92d5dc4e..64d7afbf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,5 @@ default_language_version: - python: python3.10 + python: python3.11 exclude: snapshots/ repos: diff --git a/donate/menu.py b/donate/menu.py new file mode 100644 index 00000000..a97b73de --- /dev/null +++ b/donate/menu.py @@ -0,0 +1,30 @@ +from wagtail.fields import StreamField + +from shared.blocks import MenuItemBlock as MenuItemBlockBase +from shared.models import MenuMixin as MenuMixinBase + + +class MenuItemBlock(MenuItemBlockBase): + class Meta: + label = "Položka v menu" + template = "donate/blocks/menu_item.html" + + +# +# +# class MenuParentBlock(MenuParentBlockBase): +# class Meta: +# label = "Podmenu" +# template = "styleguide/2.3.x/menu_parent.html" + + +class MenuMixin(MenuMixinBase): + menu = StreamField( + [("menu_item", MenuItemBlock())], # , ("menu_parent", MenuParentBlock()) + verbose_name="Menu", + blank=True, + use_json_field=True, + ) + + class Meta: + abstract = True diff --git a/donate/migrations/0031_donateprojectindexpage_support_description_and_more.py b/donate/migrations/0031_donateprojectindexpage_support_description_and_more.py index f26d0ae6..2bc5a383 100644 --- a/donate/migrations/0031_donateprojectindexpage_support_description_and_more.py +++ b/donate/migrations/0031_donateprojectindexpage_support_description_and_more.py @@ -1,7 +1,7 @@ # Generated by Django 4.1.10 on 2023-09-13 18:47 -from django.db import migrations, models import wagtail.fields +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/donate/migrations/0034_donatehomepage_menu.py b/donate/migrations/0034_donatehomepage_menu.py new file mode 100644 index 00000000..dce15d59 --- /dev/null +++ b/donate/migrations/0034_donatehomepage_menu.py @@ -0,0 +1,50 @@ +# Generated by Django 4.1.10 on 2023-09-22 08:24 + +import wagtail.blocks +import wagtail.fields +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("donate", "0033_donateprojectindexpage_support_position"), + ] + + operations = [ + migrations.AddField( + model_name="donatehomepage", + name="menu", + field=wagtail.fields.StreamField( + [ + ( + "menu_item", + wagtail.blocks.StructBlock( + [ + ( + "title", + wagtail.blocks.CharBlock( + label="Titulek", required=True + ), + ), + ( + "page", + wagtail.blocks.PageChooserBlock( + label="Stránka", required=False + ), + ), + ( + "link", + wagtail.blocks.URLBlock( + label="Odkaz", required=False + ), + ), + ] + ), + ) + ], + blank=True, + use_json_field=True, + verbose_name="Menu", + ), + ), + ] diff --git a/donate/models.py b/donate/models.py index c64754da..2f667776 100644 --- a/donate/models.py +++ b/donate/models.py @@ -12,7 +12,9 @@ from wagtail.admin.panels import ( FieldPanel, InlinePanel, MultiFieldPanel, + ObjectList, PublishingPanel, + TabbedInterface, ) from wagtail.fields import RichTextField, StreamField from wagtail.images.blocks import ImageChooserBlock @@ -29,6 +31,7 @@ from tuning import admin_help from .blocks import CrowdfundingRewardBlock, CustomContentBlock from .forms import DonateForm +from .menu import MenuMixin from .utils import get_donated_amount_from_api @@ -90,6 +93,7 @@ class DonateFormAmountsMixin(models.Model): class DonateHomePage( + MenuMixin, DonateFormMixin, DonateFormAmountsMixin, Page, @@ -233,6 +237,17 @@ class DonateHomePage( FieldPanel("faq_page"), ] + ### EDIT HANDLERS + + edit_handler = TabbedInterface( + [ + ObjectList(content_panels, heading="Obsah"), + ObjectList(promote_panels, heading="Propagovat"), + ObjectList(settings_panels, heading="Nastavení"), + ObjectList(MenuMixin.menu_panels, heading="Menu"), + ] + ) + ### RELATIONS subpage_types = [ @@ -287,12 +302,10 @@ class DonateHomePage( block["index"] = project_index block["projects"] = ( - DonateProjectPage. - objects. - child_of(project_index). - live(). - specific(). - order_by("-date")[:3] + DonateProjectPage.objects.child_of(project_index) + .live() + .specific() + .order_by("-date")[:3] ) context["project_support_blocks"].append(block) @@ -658,8 +671,8 @@ class DonateTextPage(Page, ExtendedMetadataPageMixin, SubpageMixin, MetadataPage ### RELATIONS - parent_page_types = ["donate.DonateHomePage"] - subpage_types = [] + parent_page_types = ["donate.DonateHomePage", "donate.DonateTextPage"] + subpage_types = ["donate.DonateTextPage"] ### OTHERS diff --git a/donate/static/donate/assets/css/style.css b/donate/static/donate/assets/css/style.css index 4363a1cd..c85a1b81 100644 --- a/donate/static/donate/assets/css/style.css +++ b/donate/static/donate/assets/css/style.css @@ -596,6 +596,7 @@ footer h1, footer h2, footer h3, footer h4, footer h5, footer h6 { .project .card-body p { color: #797676; + white-space: pre-line; } .project .card-footer p { @@ -1213,3 +1214,54 @@ img.full-width { float: right; margin-left: 1.5rem; } + +/* BEGIN TailwindCSS-based image formatting */ + +.mx-auto { + margin-left: auto; + margin-right: auto +} + +.my-6 { + margin-top: 1.5rem; + margin-bottom: 1.5rem +} + +.max-w-\[800px\] { + max-width: 800px +} + +.lg\:max-w-full{ + max-width: 100% +} + +.float-left{ + float: left +} + +.max-w-\[400px\]{ + max-width: 400px +} + +.sm\:max-w-full{ + max-width: 100% +} + +.float-right{ + float: right +} + +.ml-4 { + margin-left: 1rem +} + +.mb-6{ + margin-bottom: 1.5rem +} + +.object-contain { + object-fit: contain; + -o-object-fit: contain +} + +/* END TailwindCSS-based image formatting */ diff --git a/donate/templates/donate/base.html b/donate/templates/donate/base.html index 0457be0e..06f4891c 100644 --- a/donate/templates/donate/base.html +++ b/donate/templates/donate/base.html @@ -6,20 +6,7 @@ <base target="_blank"> {% endif %} - <!-- Font loader --> - <script type="text/javascript"> - WebFontConfig = { - google: { families: ['Roboto+Condensed:300,300i,400,400i,700,700i:latin-ext', 'Bebas+Neue'] } - }; - (function () { - var wf = document.createElement('script'); - wf.src = 'https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js'; - wf.type = 'text/javascript'; - wf.async = 'true'; - var s = document.getElementsByTagName('script')[0]; - s.parentNode.insertBefore(wf, s); - })(); - </script> + <link href="https://gfonts.pirati.cz/css2?family=Bebas+Neue&family=Roboto+Condensed:wght@300;400;700&family=Roboto:wght@300;400;500&display=swap" rel="stylesheet"> <!-- Meta --> <meta charset="utf-8"> @@ -93,22 +80,11 @@ <!-- Navigation --> <div class="collapse navbar-collapse" id="mainNavigation"> <ul class="navbar-nav ml-auto"> - <li class="nav-item"> - {% if page.is_home %} - <a class="nav-link js-scroll-anchor" href="#strana">Podpoř Piráty</a> - {% else %} - <a class="nav-link" href="/#strana">Podpoř Piráty</a> - {% endif %} - </li> - {% for projects_page in page.root_page.project_indexes %} - <li class="nav-item"> - <a class="nav-link" href="{{ projects_page.url }}">{{ projects_page.title }}</a> - </li> + {% for block in page.root_page.menu %} + {% include_block block %} {% endfor %} - <li class="nav-item"> - <a class="nav-link" href="{{ page.root_page.regions_page_url }}">Kraje</a> - </li> </ul> + {% if page.root_page.custom_url_1 and page.root_page.custom_url_1_text %} <a href="{{ page.root_page.custom_url_1 }}" class="d-block d-lg-none mb-3 header_link header_link--desktop" target="_blank" rel="noreferrer"><i class="icon-external-link mr-2" title="Ikona odkazu"></i>{{ page.root_page.custom_url_1_text }}</a> diff --git a/donate/templates/donate/blocks/menu_item.html b/donate/templates/donate/blocks/menu_item.html new file mode 100644 index 00000000..e2af3c37 --- /dev/null +++ b/donate/templates/donate/blocks/menu_item.html @@ -0,0 +1,3 @@ +{% firstof self.page.url self.link as target %} + <a class="nav-link js-scroll-anchor" href="{{ target }}">{{ self.title }}</a> +</a> diff --git a/majak/context_processors.py b/majak/context_processors.py new file mode 100644 index 00000000..361bfebe --- /dev/null +++ b/majak/context_processors.py @@ -0,0 +1,5 @@ +from django.conf import settings + + +def styleguide_url_processor(request): + return {"styleguide_url": settings.STYLEGUIDE_URL} diff --git a/majak/settings/base.py b/majak/settings/base.py index 4542b8db..d42dcacc 100644 --- a/majak/settings/base.py +++ b/majak/settings/base.py @@ -149,6 +149,7 @@ TEMPLATES = [ "django.contrib.auth.context_processors.auth", "django.contrib.messages.context_processors.messages", "django_settings_export.settings_export", + "majak.context_processors.styleguide_url_processor", ], }, }, @@ -264,6 +265,8 @@ WAGTAILADMIN_BASE_URL = BASE_URL # CUSTOM SETTINGS # ------------------------------------------------------------------------------ +STYLEGUIDE_URL = env.str("STYLEGUIDE_URL", "https://styleguide.pirati.cz/2.16.x") + MAJAK_ENV = env.str("MAJAK_ENV", default="prod") SETTINGS_EXPORT = ["MAJAK_ENV"] diff --git a/shared/image_formats.py b/shared/image_formats.py index 25ae5e33..fc1a1a8f 100644 --- a/shared/image_formats.py +++ b/shared/image_formats.py @@ -4,7 +4,7 @@ register_image_format( Format( "tailwind_center_800", "šablona: Uprostřed (max 800px)", - "mx-auto my-6", + "mx-auto my-6 max-w-[800px] lg:max-w-full object-contain", "max-800x800", ) ) @@ -13,7 +13,7 @@ register_image_format( Format( "tailwind_left_400", "šablona: Vlevo (max 400px)", - "float-left mr-4 mb-6", + "float-left mr-4 mb-6 max-w-[400px] sm:max-w-full object-contain", "max-400x400", ) ) @@ -22,7 +22,7 @@ register_image_format( Format( "tailwind_left_200", "šablona: Vlevo (max 200px)", - "float-left mr-4 mb-6", + "float-left mr-4 mb-6 object-contain", "max-200x200", ) ) @@ -31,7 +31,7 @@ register_image_format( Format( "tailwind_right_400", "šablona: Vpravo (max 400px)", - "float-right ml-4 mb-6", + "float-right ml-4 mb-6 max-w-[400px] sm:max-w-full object-contain", "max-400x400", ) ) @@ -40,7 +40,7 @@ register_image_format( Format( "tailwind_right_200", "šablona: Vpravo (max 200px)", - "float-right ml-4 mb-6", + "float-right ml-4 mb-6 object-contain", "max-200x200", ) ) diff --git a/tuning/templates/tuning/sites_list.html b/tuning/templates/tuning/sites_list.html index c3fd57e5..cb4ef180 100644 --- a/tuning/templates/tuning/sites_list.html +++ b/tuning/templates/tuning/sites_list.html @@ -13,8 +13,8 @@ {% include "shared/favicon_snippet.html" %} <!-- Styles --> - <link href="https://styleguide.pirati.cz/2.3.x/css/styles.css" rel="stylesheet" media="all" /> - <link href="https://styleguide.pirati.cz/2.3.x/css/pattern-scaffolding.css" rel="stylesheet" media="all" /> + <link href="{{ styleguide_url }}/css/styles.css" rel="stylesheet" media="all" /> + <link href="{{ styleguide_url }}/css/pattern-scaffolding.css" rel="stylesheet" media="all" /> <style type="text/css"> .head-alt-md, .head-alt-lg { @@ -109,7 +109,7 @@ <section class="footer__brand"> {% if page.root_page.show_logo %} <a href="https://www.pirati.cz"> - <img src="https://styleguide.pirati.cz/2.3.x/images/logo-full-white.svg" alt="logo pirátské strany" class="w-32 md:w-40 pb-6" /> + <img src="{{ styleguide_url }}/images/logo-full-white.svg" alt="logo pirátské strany" class="w-32 md:w-40 pb-6" /> </a> {% endif %} <p class="para hidden md:block md:mb-4 lg:mb-0 text-grey-200"> @@ -128,7 +128,7 @@ </footer> <script src="{% static "shared/vendor/vue/vue.2.6.11.js" %}"></script> - <script src="https://styleguide.pirati.cz/2.3.x/js/main.bundle.js"></script> + <script src="{{ styleguide_url }}/js/main.bundle.js"></script> <script src="{% static "shared/vendor/jquery/jquery-3.4.1.min.js" %}"></script> <script src="{% static "shared/vendor/lazysizes/lazysizes.min.js" %}"></script> </body> diff --git a/uniweb/templates/uniweb/base.html b/uniweb/templates/uniweb/base.html index c99498b3..36cb6b92 100644 --- a/uniweb/templates/uniweb/base.html +++ b/uniweb/templates/uniweb/base.html @@ -17,8 +17,8 @@ {% include "shared/favicon_snippet.html" %} <!-- Styles --> - <link href="https://styleguide.pirati.cz/2.14.x/css/styles.css" rel="stylesheet" media="all" /> - <link href="https://styleguide.pirati.cz/2.14.x/css/pattern-scaffolding.css" rel="stylesheet" media="all" /> + <link href="{{ styleguide_url }}/css/styles.css" rel="stylesheet" media="all" /> + <link href="{{ styleguide_url }}/css/pattern-scaffolding.css" rel="stylesheet" media="all" /> <link href="{% static "shared/vendor/fancybox/jquery.fancybox.min.css" %}" rel="stylesheet"> <link rel="stylesheet" href="{% static "shared/vendor/vue-formulate-2.5.3/css/snow.min.css" %}"> <link rel="stylesheet" href="{% static "shared/css/helpers.css" %}"> @@ -95,7 +95,7 @@ <section class="footer__brand"> {% if page.root_page.show_logo %} <a href="https://www.pirati.cz"> - <img src="https://styleguide.pirati.cz/2.14.x/images/logo-full-white.svg" alt="logo pirátské strany" class="w-32 md:w-40 pb-6" /> + <img src="{{ styleguide_url }}/images/logo-full-white.svg" alt="logo pirátské strany" class="w-32 md:w-40 pb-6" /> </a> {% endif %} <p class="para hidden md:block md:mb-4 lg:mb-0 text-grey-200"> @@ -155,7 +155,7 @@ {% endif %} <script src="{% static "shared/vendor/vue/vue.2.6.11.js" %}"></script> - <script src="https://styleguide.pirati.cz/2.14.x/js/main.bundle.js"></script> + <script src="{{ styleguide_url }}/js/main.bundle.js"></script> <script src="{% static "shared/vendor/jquery/jquery-3.4.1.min.js" %}"></script> <script src="{% static "shared/vendor/lazysizes/lazysizes.min.js" %}"></script> <script src="{% static "shared/vendor/fancybox/jquery.fancybox.min.js" %}"></script> diff --git a/uniweb/templates/uniweb/logo_snippet.html b/uniweb/templates/uniweb/logo_snippet.html index 322713ad..754ee4b4 100644 --- a/uniweb/templates/uniweb/logo_snippet.html +++ b/uniweb/templates/uniweb/logo_snippet.html @@ -4,5 +4,5 @@ {% image page.root_page.logo original as logo %} <img src="{{ logo.full_url }}" class="w-8" /> {% else %} - <img src="https://styleguide.pirati.cz/2.14.x/images/logo-round-white.svg" class="w-8" /> + <img src="{{ styleguide_url }}/images/logo-round-white.svg" class="w-8" /> {% endif %} -- GitLab