From 29f4bf4fe1727b327538ae771667c888073aa274 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Valenta?= <git@imaniti.org> Date: Wed, 17 Jan 2024 12:17:46 +0100 Subject: [PATCH] add button to homepage --- district/forms.py | 5 +- district/tasks.py | 1 + elections/forms.py | 4 +- elections/models.py | 2 +- elections/tasks.py | 1 + main/blocks.py | 9 + main/forms.py | 4 +- .../0066_alter_mainhomepage_content.py | 155 ++++++++++++++++ .../0067_alter_mainhomepage_content.py | 155 ++++++++++++++++ .../0068_alter_mainhomepage_content.py | 169 ++++++++++++++++++ main/models.py | 2 +- main/tasks.py | 1 + shared/forms.py | 1 - shared/jekyll_import.py | 6 +- shared/models/main.py | 37 ++-- .../buttons/round_button_without_url.html | 6 + .../includes/molecules/menus/carousel.html | 35 +++- 17 files changed, 564 insertions(+), 29 deletions(-) create mode 100644 main/migrations/0066_alter_mainhomepage_content.py create mode 100644 main/migrations/0067_alter_mainhomepage_content.py create mode 100644 main/migrations/0068_alter_mainhomepage_content.py create mode 100644 shared/templates/styleguide2/includes/atoms/buttons/round_button_without_url.html diff --git a/district/forms.py b/district/forms.py index 48600686..37b237fb 100644 --- a/district/forms.py +++ b/district/forms.py @@ -1,6 +1,9 @@ -from shared.forms import JekyllImportForm as SharedJekyllImportForm import os + from django import forms + +from shared.forms import JekyllImportForm as SharedJekyllImportForm + from .tasks import import_jekyll_articles diff --git a/district/tasks.py b/district/tasks.py index 8162ecb0..4870b702 100644 --- a/district/tasks.py +++ b/district/tasks.py @@ -1,6 +1,7 @@ import logging from celery import shared_task + from shared.jekyll_import import JekyllArticleImporter logger = logging.getLogger(__name__) diff --git a/elections/forms.py b/elections/forms.py index b252a89a..45b12efa 100644 --- a/elections/forms.py +++ b/elections/forms.py @@ -1,5 +1,7 @@ -from shared.forms import JekyllImportForm as SharedJekyllImportForm import os + +from shared.forms import JekyllImportForm as SharedJekyllImportForm + from .tasks import import_jekyll_articles diff --git a/elections/models.py b/elections/models.py index 72222927..2129b74c 100644 --- a/elections/models.py +++ b/elections/models.py @@ -46,9 +46,9 @@ from shared.models import ( # MenuMixin, ) from shared.utils import make_promote_panels, subscribe_to_newsletter from tuning import admin_help -from .forms import JekyllImportForm from . import blocks +from .forms import JekyllImportForm class ElectionsHomePage(MainHomePageMixin): diff --git a/elections/tasks.py b/elections/tasks.py index f3cce43e..7e71537e 100644 --- a/elections/tasks.py +++ b/elections/tasks.py @@ -1,6 +1,7 @@ import logging from celery import shared_task + from shared.jekyll_import import JekyllArticleImporter logger = logging.getLogger(__name__) diff --git a/main/blocks.py b/main/blocks.py index 975b3cdc..02b100d5 100644 --- a/main/blocks.py +++ b/main/blocks.py @@ -97,6 +97,15 @@ class HomePageCarouseSlideBlock(StructBlock): mobile_line_2 = TextBlock(label="Druhý mobilní řádek") mobile_line_3 = TextBlock(label="Třetí mobilní řádek") + image = ImageChooserBlock(label="Obrázek nahrazující animaci", required=False) + + button_url = URLBlock( + label="Odkaz tlačítka", + help_text="Bez odkazu tlačítko nebude viditelné.", + required=False, + ) + button_text = CharBlock(label="Text tlačítka", required=False) + class Meta: template = "styleguide2/includes/molecules/menus/carousel.html" icon = "form" diff --git a/main/forms.py b/main/forms.py index b252a89a..45b12efa 100644 --- a/main/forms.py +++ b/main/forms.py @@ -1,5 +1,7 @@ -from shared.forms import JekyllImportForm as SharedJekyllImportForm import os + +from shared.forms import JekyllImportForm as SharedJekyllImportForm + from .tasks import import_jekyll_articles diff --git a/main/migrations/0066_alter_mainhomepage_content.py b/main/migrations/0066_alter_mainhomepage_content.py new file mode 100644 index 00000000..3f3f034c --- /dev/null +++ b/main/migrations/0066_alter_mainhomepage_content.py @@ -0,0 +1,155 @@ +# Generated by Django 4.1.10 on 2024-01-17 10:49 + +import wagtail.blocks +import wagtail.fields +import wagtail.images.blocks +from django.db import migrations + +import main.blocks + + +class Migration(migrations.Migration): + dependencies = [ + ("main", "0065_alter_mainarticlepage_content_and_more"), + ] + + operations = [ + migrations.AlterField( + model_name="mainhomepage", + name="content", + field=wagtail.fields.StreamField( + [ + ( + "carousel", + wagtail.blocks.StructBlock( + [ + ( + "image", + wagtail.images.blocks.ImageChooserBlock( + label="Obrázek nahrazující animaci", + required=False, + ), + ), + ( + "desktop_line_1", + wagtail.blocks.TextBlock( + label="Desktop první řádek" + ), + ), + ( + "desktop_line_2", + wagtail.blocks.TextBlock( + label="Desktop druhý řádek" + ), + ), + ( + "mobile_line_1", + wagtail.blocks.TextBlock( + label="První mobilní řádek" + ), + ), + ( + "mobile_line_2", + wagtail.blocks.TextBlock( + label="Druhý mobilní řádek" + ), + ), + ( + "mobile_line_3", + wagtail.blocks.TextBlock( + label="Třetí mobilní řádek" + ), + ), + ] + ), + ), + ( + "news", + wagtail.blocks.StructBlock( + [ + ( + "title", + wagtail.blocks.CharBlock( + help_text="Nejnovější články se načtou automaticky", + label="Titulek", + ), + ), + ( + "description", + wagtail.blocks.TextBlock(label="Popis"), + ), + ], + template="styleguide2/includes/organisms/articles/articles_section.html", + ), + ), + ("europarl_news", wagtail.blocks.StructBlock([])), + ( + "people", + wagtail.blocks.StructBlock( + [ + ( + "title_line_1", + wagtail.blocks.CharBlock( + label="První řádek titulku" + ), + ), + ( + "title_line_2", + wagtail.blocks.CharBlock( + label="Druhý řádek titulku" + ), + ), + ( + "description", + wagtail.blocks.TextBlock(label="Popis"), + ), + ( + "list", + wagtail.blocks.ListBlock( + main.blocks.BoxBlock, label="Boxíky" + ), + ), + ] + ), + ), + ( + "regions", + wagtail.blocks.StructBlock( + [ + ( + "title", + wagtail.blocks.CharBlock( + help_text="Články pro regiony se načtou automaticky", + label="Titulek", + ), + ) + ] + ), + ), + ( + "boxes", + wagtail.blocks.StructBlock( + [ + ("title", wagtail.blocks.CharBlock(label="Nadpis")), + ( + "list", + wagtail.blocks.ListBlock( + main.blocks.BoxBlock, label="Boxíky" + ), + ), + ( + "image", + wagtail.images.blocks.ImageChooserBlock( + label="Obrázek pozadí", required=False + ), + ), + ] + ), + ), + ], + blank=True, + use_json_field=True, + verbose_name="Hlavní obsah", + ), + ), + ] diff --git a/main/migrations/0067_alter_mainhomepage_content.py b/main/migrations/0067_alter_mainhomepage_content.py new file mode 100644 index 00000000..a6ae9762 --- /dev/null +++ b/main/migrations/0067_alter_mainhomepage_content.py @@ -0,0 +1,155 @@ +# Generated by Django 4.1.10 on 2024-01-17 10:52 + +import wagtail.blocks +import wagtail.fields +import wagtail.images.blocks +from django.db import migrations + +import main.blocks + + +class Migration(migrations.Migration): + dependencies = [ + ("main", "0066_alter_mainhomepage_content"), + ] + + operations = [ + migrations.AlterField( + model_name="mainhomepage", + name="content", + field=wagtail.fields.StreamField( + [ + ( + "carousel", + wagtail.blocks.StructBlock( + [ + ( + "desktop_line_1", + wagtail.blocks.TextBlock( + label="Desktop první řádek" + ), + ), + ( + "desktop_line_2", + wagtail.blocks.TextBlock( + label="Desktop druhý řádek" + ), + ), + ( + "mobile_line_1", + wagtail.blocks.TextBlock( + label="První mobilní řádek" + ), + ), + ( + "mobile_line_2", + wagtail.blocks.TextBlock( + label="Druhý mobilní řádek" + ), + ), + ( + "mobile_line_3", + wagtail.blocks.TextBlock( + label="Třetí mobilní řádek" + ), + ), + ( + "image", + wagtail.images.blocks.ImageChooserBlock( + label="Obrázek nahrazující animaci", + required=False, + ), + ), + ] + ), + ), + ( + "news", + wagtail.blocks.StructBlock( + [ + ( + "title", + wagtail.blocks.CharBlock( + help_text="Nejnovější články se načtou automaticky", + label="Titulek", + ), + ), + ( + "description", + wagtail.blocks.TextBlock(label="Popis"), + ), + ], + template="styleguide2/includes/organisms/articles/articles_section.html", + ), + ), + ("europarl_news", wagtail.blocks.StructBlock([])), + ( + "people", + wagtail.blocks.StructBlock( + [ + ( + "title_line_1", + wagtail.blocks.CharBlock( + label="První řádek titulku" + ), + ), + ( + "title_line_2", + wagtail.blocks.CharBlock( + label="Druhý řádek titulku" + ), + ), + ( + "description", + wagtail.blocks.TextBlock(label="Popis"), + ), + ( + "list", + wagtail.blocks.ListBlock( + main.blocks.BoxBlock, label="Boxíky" + ), + ), + ] + ), + ), + ( + "regions", + wagtail.blocks.StructBlock( + [ + ( + "title", + wagtail.blocks.CharBlock( + help_text="Články pro regiony se načtou automaticky", + label="Titulek", + ), + ) + ] + ), + ), + ( + "boxes", + wagtail.blocks.StructBlock( + [ + ("title", wagtail.blocks.CharBlock(label="Nadpis")), + ( + "list", + wagtail.blocks.ListBlock( + main.blocks.BoxBlock, label="Boxíky" + ), + ), + ( + "image", + wagtail.images.blocks.ImageChooserBlock( + label="Obrázek pozadí", required=False + ), + ), + ] + ), + ), + ], + blank=True, + use_json_field=True, + verbose_name="Hlavní obsah", + ), + ), + ] diff --git a/main/migrations/0068_alter_mainhomepage_content.py b/main/migrations/0068_alter_mainhomepage_content.py new file mode 100644 index 00000000..480603f2 --- /dev/null +++ b/main/migrations/0068_alter_mainhomepage_content.py @@ -0,0 +1,169 @@ +# Generated by Django 4.1.10 on 2024-01-17 11:05 + +import wagtail.blocks +import wagtail.fields +import wagtail.images.blocks +from django.db import migrations + +import main.blocks + + +class Migration(migrations.Migration): + dependencies = [ + ("main", "0067_alter_mainhomepage_content"), + ] + + operations = [ + migrations.AlterField( + model_name="mainhomepage", + name="content", + field=wagtail.fields.StreamField( + [ + ( + "carousel", + wagtail.blocks.StructBlock( + [ + ( + "desktop_line_1", + wagtail.blocks.TextBlock( + label="Desktop první řádek" + ), + ), + ( + "desktop_line_2", + wagtail.blocks.TextBlock( + label="Desktop druhý řádek" + ), + ), + ( + "mobile_line_1", + wagtail.blocks.TextBlock( + label="První mobilní řádek" + ), + ), + ( + "mobile_line_2", + wagtail.blocks.TextBlock( + label="Druhý mobilní řádek" + ), + ), + ( + "mobile_line_3", + wagtail.blocks.TextBlock( + label="Třetí mobilní řádek" + ), + ), + ( + "image", + wagtail.images.blocks.ImageChooserBlock( + label="Obrázek nahrazující animaci", + required=False, + ), + ), + ( + "button_url", + wagtail.blocks.URLBlock( + help_text="Bez odkazu tlačítko nebude viditelné.", + label="Odkaz tlačítka", + required=False, + ), + ), + ( + "button_text", + wagtail.blocks.CharBlock( + label="Text tlačítka", required=False + ), + ), + ] + ), + ), + ( + "news", + wagtail.blocks.StructBlock( + [ + ( + "title", + wagtail.blocks.CharBlock( + help_text="Nejnovější články se načtou automaticky", + label="Titulek", + ), + ), + ( + "description", + wagtail.blocks.TextBlock(label="Popis"), + ), + ], + template="styleguide2/includes/organisms/articles/articles_section.html", + ), + ), + ("europarl_news", wagtail.blocks.StructBlock([])), + ( + "people", + wagtail.blocks.StructBlock( + [ + ( + "title_line_1", + wagtail.blocks.CharBlock( + label="První řádek titulku" + ), + ), + ( + "title_line_2", + wagtail.blocks.CharBlock( + label="Druhý řádek titulku" + ), + ), + ( + "description", + wagtail.blocks.TextBlock(label="Popis"), + ), + ( + "list", + wagtail.blocks.ListBlock( + main.blocks.BoxBlock, label="Boxíky" + ), + ), + ] + ), + ), + ( + "regions", + wagtail.blocks.StructBlock( + [ + ( + "title", + wagtail.blocks.CharBlock( + help_text="Články pro regiony se načtou automaticky", + label="Titulek", + ), + ) + ] + ), + ), + ( + "boxes", + wagtail.blocks.StructBlock( + [ + ("title", wagtail.blocks.CharBlock(label="Nadpis")), + ( + "list", + wagtail.blocks.ListBlock( + main.blocks.BoxBlock, label="Boxíky" + ), + ), + ( + "image", + wagtail.images.blocks.ImageChooserBlock( + label="Obrázek pozadí", required=False + ), + ), + ] + ), + ), + ], + blank=True, + use_json_field=True, + verbose_name="Hlavní obsah", + ), + ), + ] diff --git a/main/models.py b/main/models.py index 9f4cc167..511d37c4 100644 --- a/main/models.py +++ b/main/models.py @@ -46,9 +46,9 @@ from shared.models import ( # MenuMixin, ) from shared.utils import make_promote_panels, subscribe_to_newsletter from tuning import admin_help -from .forms import JekyllImportForm from . import blocks +from .forms import JekyllImportForm class MainHomePage(MainHomePageMixin): diff --git a/main/tasks.py b/main/tasks.py index 7d90d645..231899f1 100644 --- a/main/tasks.py +++ b/main/tasks.py @@ -1,6 +1,7 @@ import logging from celery import shared_task + from shared.jekyll_import import JekyllArticleImporter logger = logging.getLogger(__name__) diff --git a/shared/forms.py b/shared/forms.py index 90972843..464b10da 100644 --- a/shared/forms.py +++ b/shared/forms.py @@ -1,7 +1,6 @@ from django import forms from wagtail.admin.forms import WagtailAdminPageForm from wagtail.models.collections import Collection -import os class SubscribeForm(forms.Form): diff --git a/shared/jekyll_import.py b/shared/jekyll_import.py index 1d5baffa..f95d2c45 100644 --- a/shared/jekyll_import.py +++ b/shared/jekyll_import.py @@ -13,7 +13,6 @@ from io import StringIO from typing import List from urllib.error import HTTPError from uuid import uuid4 -import os import bleach import markdown.serializers @@ -344,9 +343,12 @@ class JekyllArticleImporter: # Computed proprs import time + time.sleep(5) - self.article_parent_page = self.article_parent_page_model.objects.filter(id=self.article_parent_page_id).first() + self.article_parent_page = self.article_parent_page_model.objects.filter( + id=self.article_parent_page_id + ).first() self.path, self.repo_name = get_path_and_repo_name(self.url, self.use_git) self.site = self.article_parent_page.get_site() diff --git a/shared/models/main.py b/shared/models/main.py index 7f4848c6..b5926588 100644 --- a/shared/models/main.py +++ b/shared/models/main.py @@ -266,8 +266,7 @@ class MainHomePageMixin( context["article_data_list"] = self.materialize_shared_articles_query( self.append_all_shared_articles_query( self.article_page_model.objects.live().all() - ) - .order_by("-union_date")[:3] + ).order_by("-union_date")[:3] ) return context @@ -446,8 +445,7 @@ class MainArticlesPageMixin( return self.materialize_shared_articles_query( self.append_all_shared_articles_query( self.root_page.article_page_model.objects.filter(filter).live().all() - ) - .order_by("-union_date") + ).order_by("-union_date") ) def get_article_data_list( @@ -458,17 +456,16 @@ class MainArticlesPageMixin( if search_filter is None: search_filter = models.Q() - target_date_list = ( - self.append_all_shared_articles_query( - self.root_page.article_page_model.objects.filter(search_filter).live() - ) - .order_by("-union_date") - ) + target_date_list = self.append_all_shared_articles_query( + self.root_page.article_page_model.objects.filter(search_filter).live() + ).order_by("-union_date") if not target_date_list: return [] - target_date = target_date_list[0]["union_date"] - relativedelta(months=months_back) + target_date = target_date_list[0]["union_date"] - relativedelta( + months=months_back + ) first_day_of_target_month = target_date.replace(day=1) filter = models.Q(date__gte=first_day_of_target_month) & search_filter @@ -544,9 +541,12 @@ class MainArticlesPageMixin( ) != 0 and ( self.materialize_shared_articles_query( self.append_all_shared_articles_query( - self.root_page.article_page_model.objects.filter(search_filter).live().all() - ) - .order_by("union_date")[:2] # LIMIT 2 + self.root_page.article_page_model.objects.filter(search_filter) + .live() + .all() + ).order_by("union_date")[ + :2 + ] # LIMIT 2 )[0] not in article_timeline_list[-1]["articles"] ) @@ -590,9 +590,12 @@ class MainArticlesPageMixin( self.append_all_shared_articles_query( self.root_page.article_page_model.objects.filter( search_filter - ).live().all() - ) - .order_by("union_date")[:2] # LIMIT 2 + ) + .live() + .all() + ).order_by("union_date")[ + :2 + ] # LIMIT 2 )[0] not in article_timeline_list[-1]["articles"] ) diff --git a/shared/templates/styleguide2/includes/atoms/buttons/round_button_without_url.html b/shared/templates/styleguide2/includes/atoms/buttons/round_button_without_url.html new file mode 100644 index 00000000..4948aaf9 --- /dev/null +++ b/shared/templates/styleguide2/includes/atoms/buttons/round_button_without_url.html @@ -0,0 +1,6 @@ +{% extends "styleguide2/includes/atoms/buttons/round_button.html" %} + +{% block element_opener %}button{% endblock %} +{% block element_closer %}button{% endblock %} + +{% block href %}{% endblock %} diff --git a/shared/templates/styleguide2/includes/molecules/menus/carousel.html b/shared/templates/styleguide2/includes/molecules/menus/carousel.html index 1eb148e0..4e1516f9 100644 --- a/shared/templates/styleguide2/includes/molecules/menus/carousel.html +++ b/shared/templates/styleguide2/includes/molecules/menus/carousel.html @@ -1,14 +1,32 @@ -{% load static %} +{% load static wagtailimages_tags %} <div> <div class="header-carousel"> - <div class="h-[700px] xl:h-screen relative"> + + <{% if self.button_url %}a{% else %}div{% endif %} + class=" + block h-[700px] xl:h-screen relative + + {% if self.button_url %}group cursor-pointer{% endif %} + " + + {% if self.button_url %} + href="{{ self.button_url }}" + {% endif %} + > <img class=" header-carousel--image lg:hidden " - src="{% static 'styleguide2/images/background-images/bg-flag-mobile.gif' %}" + + {% if not self.image %} + src="{% static 'styleguide2/images/background-images/bg-flag-mobile.gif' %}" + {% else %} + {% image self.image original as background_image %} + src="{{ background_image.url }}" + {% endif %} + draggable="false" > @@ -35,8 +53,17 @@ <div>{{ self.desktop_line_2 }}</div> </h1> + {% if self.button_url %} + <div class="ml-4 text-lg group"> + {% firstof self.button_text "Více informací" as button_text %} + + {% include "styleguide2/includes/atoms/buttons/round_button_without_url.html" with button_text=button_text %} + </div> + {% endif %} </div> </div> - </div> + + </{% if self.button_url %}a{% else %}div{% endif %}> + </div> </div> -- GitLab