diff --git a/district/wagtail_hooks.py b/district/wagtail_hooks.py index 461e746ed8a2b4da06de45e92deb5cadb35d368a..67eb4a399ad321ea36ade3e355f89eb56556be9b 100644 --- a/district/wagtail_hooks.py +++ b/district/wagtail_hooks.py @@ -2,53 +2,6 @@ from wagtail.core import hooks from district.models import DistrictCenterPage, DistrictHomePage -# import re -# -# from wagtail.core import hooks -# -# # FIXME hooks are loaded globally so it doesn't make sense to have it in this module -# -# -# @hooks.register("construct_page_chooser_queryset") -# def this_web_only(pages, request): -# add_result = re.search( -# "page/(.*)/", request.META.get("HTTP_REFERER") -# ) # FIXME better regex -# edit_result = re.search("pages/(.*)/edit", request.META.get("HTTP_REFERER")) -# -# if add_result: -# return handle_add_page_selection(pages=pages, add_result=add_result) -# -# if edit_result: -# return handle_edit_page_selection(pages=pages, edit_result=edit_result) -# -# return pages -# -# -# def handle_add_page_selection(pages, add_result): -# parent_page_id = add_result.group(1) -# if parent_page_id == 1: # pro novou homepage žádné podstránky nejsou -# return pages.none() -# -# parent_page = pages.model.objects.get(id=parent_page_id) -# root_page = getattr(parent_page.specific, "root_page", None) -# return get_only_root_page_descendants(pages=pages, root_page=root_page) -# -# -# def handle_edit_page_selection(pages, edit_result): -# current_page_id = edit_result.group(1) -# current_page = pages.model.objects.get(id=current_page_id) -# root_page = getattr(current_page.specific, "root_page", None) -# return get_only_root_page_descendants(pages=pages, root_page=root_page) -# -# -# def get_only_root_page_descendants(pages, root_page): -# if not root_page: -# return pages -# -# web_pages_id_list = root_page.get_descendants().live().values_list("id", flat=True) -# return pages.filter(id__in=web_pages_id_list) - @hooks.register("after_copy_page") def handle_copy_calendar(request, origin_page, copied_page): diff --git a/main/migrations/0012_alter_mainpeoplepage_people_delete_mainarticlespage.py b/main/migrations/0012_alter_mainpeoplepage_people_delete_mainarticlespage.py new file mode 100644 index 0000000000000000000000000000000000000000..3bf5d208f0d00bd1f76fe32e2c041cd2af9ebc90 --- /dev/null +++ b/main/migrations/0012_alter_mainpeoplepage_people_delete_mainarticlespage.py @@ -0,0 +1,56 @@ +# Generated by Django 4.0.7 on 2022-08-24 13:39 + +import wagtail.blocks +import wagtail.fields +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("main", "0011_alter_mainarticlepage_content_and_more"), + ] + + operations = [ + migrations.AlterField( + model_name="mainpeoplepage", + name="people", + field=wagtail.fields.StreamField( + [ + ( + "people_group", + wagtail.blocks.StructBlock( + [ + ("title", wagtail.blocks.CharBlock(label="Titulek")), + ( + "slug", + wagtail.blocks.CharBlock( + help_text="Není třeba vyplňovat, bude automaticky vyplněno", + label="Slug skupiny", + required=False, + ), + ), + ( + "person_list", + wagtail.blocks.ListBlock( + wagtail.blocks.PageChooserBlock( + label="Detail osoby", + page_type=["main.MainPersonPage"], + ), + label="Skupina osob", + ), + ), + ], + label="Seznam osob", + ), + ) + ], + blank=True, + use_json_field=None, + verbose_name="Lidé", + ), + ), + migrations.DeleteModel( + name="MainArticlesPage", + ), + ] diff --git a/main/migrations/0013_rename_mainworkpage_mainarticlespage.py b/main/migrations/0013_rename_mainworkpage_mainarticlespage.py new file mode 100644 index 0000000000000000000000000000000000000000..22ab6f107b902656e5d1ac87a505fb2e44d1e3e5 --- /dev/null +++ b/main/migrations/0013_rename_mainworkpage_mainarticlespage.py @@ -0,0 +1,19 @@ +# Generated by Django 4.0.7 on 2022-08-24 13:39 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("wagtailimages", "0024_index_image_file_hash"), + ("wagtailcore", "0069_log_entry_jsonfield"), + ("main", "0012_alter_mainpeoplepage_people_delete_mainarticlespage"), + ] + + operations = [ + migrations.RenameModel( + old_name="MainWorkPage", + new_name="MainArticlesPage", + ), + ] diff --git a/main/migrations/0014_alter_mainarticlespage_options_and_more.py b/main/migrations/0014_alter_mainarticlespage_options_and_more.py new file mode 100644 index 0000000000000000000000000000000000000000..58e8d88bb868869fa9ac7442e3af43458388cabb --- /dev/null +++ b/main/migrations/0014_alter_mainarticlespage_options_and_more.py @@ -0,0 +1,29 @@ +# Generated by Django 4.0.7 on 2022-08-24 13:44 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("main", "0013_rename_mainworkpage_mainarticlespage"), + ] + + operations = [ + migrations.AlterModelOptions( + name="mainarticlespage", + options={"verbose_name": "Rozcestník článků"}, + ), + migrations.AddField( + model_name="mainarticlepage", + name="article_type", + field=models.PositiveSmallIntegerField( + choices=[ + (1, "Článek na timeline Piráti pracují"), + (2, "Tisková zpráva"), + ], + default=2, + verbose_name="Typ článku", + ), + ), + ] diff --git a/main/models.py b/main/models.py index 74f6befa6f956b67a5a1630e40b1baff62022425..64750535bce47ae6a3826dbbe73a2d3de5d8c5ae 100644 --- a/main/models.py +++ b/main/models.py @@ -2,7 +2,6 @@ from datetime import timedelta from functools import cached_property from django.conf import settings -from django.core.paginator import Paginator from django.db import models from django.http import HttpResponseRedirect from django.shortcuts import render @@ -34,6 +33,11 @@ from . import blocks from .menu import MenuMixin +class ARTICLE_TYPES(models.IntegerChoices): + WORK_TIMELINE = 1, "Článek na timeline Piráti pracují" + PRESS_RELEASE = 2, "Tisková zpráva" + + class MainHomePage(MenuMixin, ExtendedMetadataHomePageMixin, MetadataPageMixin, Page): # header @@ -129,7 +133,6 @@ class MainHomePage(MenuMixin, ExtendedMetadataHomePageMixin, MetadataPageMixin, ### RELATIONS subpage_types = [ - "main.MainWorkPage", "main.MainArticlesPage", "main.MainProgramPage", "main.MainPeoplePage", @@ -181,7 +184,9 @@ class MainHomePage(MenuMixin, ExtendedMetadataHomePageMixin, MetadataPageMixin, return HttpResponseRedirect(self.url) -class MainWorkPage(ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, Page): +class MainArticlesPage( + ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, Page +): perex = models.TextField() timeline = StreamField( # TODO delete [ @@ -207,7 +212,7 @@ class MainWorkPage(ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, P ### OTHERS class Meta: - verbose_name = "Piráti pracují" + verbose_name = "Rozcestník článků" def get_article_data_list(self): last_month = timezone.now().today().replace(day=1) - timedelta(days=1) @@ -260,13 +265,16 @@ class MainArticlePage( ): ### FIELDS + article_type = models.PositiveSmallIntegerField( + "Typ článku", choices=ARTICLE_TYPES.choices, default=ARTICLE_TYPES.PRESS_RELEASE + ) content = StreamField( [ - ('text', RichTextBlock(template="")), - ('quote', blocks.ArticleQuoteBlock()), - ('download', blocks.ArticleDownloadBlock()), - ('image', blocks.ArticleImageBlock()) + ("text", RichTextBlock(template="")), + ("quote", blocks.ArticleQuoteBlock()), + ("download", blocks.ArticleDownloadBlock()), + ("image", blocks.ArticleImageBlock()), ], verbose_name="Článek", blank=True, @@ -291,6 +299,7 @@ class MainArticlePage( ### PANELS content_panels = ArticleMixin.content_panels + [ + FieldPanel("article_type"), FieldPanel("author_page"), FieldPanel("region"), FieldPanel("tags"), @@ -322,36 +331,6 @@ class MainArticlePage( # return context -class MainArticlesPage( - RoutablePageMixin, ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, Page -): - def get_context(self, request): - context = super().get_context(request) - context["articles"] = Paginator( - self.get_children().live().specific().order_by("-mainarticlepage__date"), - 12, # nevím, návrh nemáme - ).get_page(request.GET.get("page")) - return context - - @route(r"^tagy/$", name="tags") - def tags(self, request): - return render( - request, - "main/main_tags_page.html", - context=self.get_tags_page_context(request=request), - ) - - ### RELATIONS - - parent_page_types = ["main.MainHomePage"] - subpage_types = ["main.MainArticlePage"] - - ### OTHERS - - class Meta: - verbose_name = "Aktuality" - - class MainProgramPage(ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, Page): ### FIELDS diff --git a/main/templates/main/includes/work_article_preview.html b/main/templates/main/includes/work_article_preview.html index 90c35f97d516146df4a83c376ed49a7203a82c40..6d423edbe8e55ed9827ac334a249f29ff0996ae6 100644 --- a/main/templates/main/includes/work_article_preview.html +++ b/main/templates/main/includes/work_article_preview.html @@ -15,6 +15,6 @@ {{ article_page.perex }} </p> <div> - {% include 'main/includes/button_animated.html' with btn_text="Číst dále" %} + {% include 'main/includes/button_animated.html' with btn_link=article_page.url btn_text="Číst dále" %} </div> </div> diff --git a/main/templates/main/main_program_page.html b/main/templates/main/main_program_page.html index 05020476de073698f509c086a9f8ceabb73513c1..97d2b8f38e6b64e2d0b9ec290184b7db3cb1a2a8 100644 --- a/main/templates/main/main_program_page.html +++ b/main/templates/main/main_program_page.html @@ -2,6 +2,8 @@ {% load wagtailcore_tags wagtailimages_tags shared_filters %} {% block content %} + {% include 'main/includes/layout/simple_page_header.html' %} + <main role="main"> <div class="grid-container"> <div class="grid-content"> @@ -15,13 +17,13 @@ <div class="mb-12"> <div class="switch"> {% for program_group in page.program %} - <a - class="switch__item {% if forloop.first %}switch__item--active{% endif %}">{{ program_group.value.title }}</a> + <a class="switch__item {% if forloop.first %}switch__item--active{% endif %}"> + {{ program_group.value.title }} + </a> {% endfor %} </div> </div> - <div class="mb-12"> {% for program_group in page.program %} {% for item in program_group.value.point_list %}