diff --git a/district/forms.py b/district/forms.py index 48600686a04f6efbc03dbd7de3cbe1dbe5c416c4..37b237fbdc4c91cc31408016870a9ca7a4c0f5a5 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 8162ecb06496e59c2bef2bd445984ff4fb7363d9..4870b7020008da8079a433f2307b1d35cbae169a 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 b252a89ac370c1ae3dd2b4dba6d51bb91d689604..45b12efafb86376aa240cb2a98fcf530fa4e5405 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 7222292745c5a7315b349973434bea4ef403d867..2129b74cd66a1d58123e06f1ed2bca3c96029974 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 f3cce43e0f8491caa438ea473f1e9b69fb041c74..7e71537e76957f281676d87688c7f25a4bd8ddee 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 975b3cdc066356ebc37938b548926c06a9c324a8..02b100d5031c07cd7334d8add669c8085fbb33a3 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 b252a89ac370c1ae3dd2b4dba6d51bb91d689604..45b12efafb86376aa240cb2a98fcf530fa4e5405 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 0000000000000000000000000000000000000000..3f3f034c27d7ff8a0a998306a34aeeba580c52fc --- /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 0000000000000000000000000000000000000000..a6ae9762c0c2bd477bf1c59890903577c44b32af --- /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 0000000000000000000000000000000000000000..480603f2c7e755dba35f1d8abbbc437e38032b33 --- /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 9f4cc1678e85385e86a0999268714c91875b9dbe..511d37c4c95f5b54b087b972ebea45e73194f545 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 7d90d645e6e9abea8808599731c60ead70571525..231899f1a6c6f6fe03f56c653ac86e3b8bd6237e 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 909728431a623b39325640543a4a6ee1f8aaf03c..464b10dad6ba62d05557218c286bbb609f398a37 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 1d5baffa94a1348153750bcddb43f4a20ba3c1be..f95d2c45ce5a4347be628494e1922a3ce21d8b0c 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 7f4848c62dcc0df32291d05f88e751bbb3551783..b59265884c5d42bd6118b3d60713c6e22656e20a 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 0000000000000000000000000000000000000000..4948aaf9ad47511d4345423004d5a61f5e57ffc1 --- /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 1eb148e079ee2b4dcd5bc56fe4798c3e312ab152..4e1516f904b5a3d681b9f39e3f6490dca7ae5f0a 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>