From fe5241450cb5c6372c6cfcc331f5f0d652ba8712 Mon Sep 17 00:00:00 2001 From: "jindra12.underdark" <jindra12.underdark@gmail.com> Date: Thu, 27 Apr 2023 21:06:59 +0200 Subject: [PATCH] Rm calendar page mixin #163 --- calendar_utils/models.py | 27 ------------------- .../0109_districtcalendarpage_and_more.py | 10 ++++--- district/models.py | 6 ++--- .../calendar_current_events_snippet.html | 4 +-- ...lendarpage_uniwebhomepage_calendar_page.py | 10 ++++--- uniweb/models.py | 10 ++++--- 6 files changed, 23 insertions(+), 44 deletions(-) diff --git a/calendar_utils/models.py b/calendar_utils/models.py index c6e60455..6327c8c3 100644 --- a/calendar_utils/models.py +++ b/calendar_utils/models.py @@ -79,10 +79,6 @@ class CalendarMixin(models.Model): Calendar, null=True, blank=True, on_delete=models.PROTECT ) - @property - def first_calendar_page(self): - return self._first_subpage_of_type(CalendarPageMixin) - class Meta: abstract = True @@ -108,26 +104,3 @@ class CalendarMixin(models.Model): self.calendar = None super().save(*args, **kwargs) - - -class CalendarPageMixin(CalendarMixin): - """ - Page mixin for displaying full calendar - """ - - calendar_url = models.URLField( - "URL kalendáře ve formátu iCal", blank=False, null=True - ) - - ### PANELS - - content_panels = [ - FieldPanel("calendar_url"), - ] - - ### RELATIONS - - subpage_types = [] - - class Meta: - abstract = True diff --git a/district/migrations/0109_districtcalendarpage_and_more.py b/district/migrations/0109_districtcalendarpage_and_more.py index 468fe20f..e9d7d78d 100644 --- a/district/migrations/0109_districtcalendarpage_and_more.py +++ b/district/migrations/0109_districtcalendarpage_and_more.py @@ -1,4 +1,4 @@ -# Generated by Django 4.1.8 on 2023-04-14 23:48 +# Generated by Django 4.1.8 on 2023-04-27 18:52 import django.db.models.deletion import wagtailmetadata.models @@ -9,9 +9,9 @@ import shared.models class Migration(migrations.Migration): dependencies = [ - ("wagtailimages", "0025_alter_image_file_alter_rendition_file"), - ("wagtailcore", "0083_workflowcontenttype"), ("calendar_utils", "0004_auto_20220505_1228"), + ("wagtailcore", "0083_workflowcontenttype"), + ("wagtailimages", "0025_alter_image_file_alter_rendition_file"), ("district", "0108_alter_districtcenterpage_content_and_more"), ] @@ -33,7 +33,9 @@ class Migration(migrations.Migration): ( "calendar_url", models.URLField( - null=True, verbose_name="URL kalendáře ve formátu iCal" + blank=True, + null=True, + verbose_name="URL kalendáře ve formátu iCal", ), ), ( diff --git a/district/models.py b/district/models.py index cb55d0d9..2892ad90 100644 --- a/district/models.py +++ b/district/models.py @@ -26,7 +26,7 @@ from wagtail.fields import RichTextField, StreamField from wagtail.models import Orderable, Page from wagtailmetadata.models import MetadataPageMixin -from calendar_utils.models import CalendarMixin, CalendarPageMixin +from calendar_utils.models import CalendarMixin from maps_utils.blocks import MapPointBlock from maps_utils.const import ( DEFAULT_MAP_STYLE, @@ -1638,14 +1638,14 @@ def make_feature_index_cache_key(feature: "DistrictGeoFeatureDetailPage"): return f"DistrictGeoFeatureDetailPage::{feature.id}::index" -class DistrictCalendarPage(SubpageMixin, MetadataPageMixin, CalendarPageMixin, Page): +class DistrictCalendarPage(SubpageMixin, MetadataPageMixin, CalendarMixin, Page): """ Page for displaying full calendar """ ### PANELS - content_panels = Page.content_panels + CalendarPageMixin.content_panels + content_panels = Page.content_panels + [FieldPanel("calendar_url")] ### RELATIONS diff --git a/shared/templates/shared/calendar_current_events_snippet.html b/shared/templates/shared/calendar_current_events_snippet.html index 2475677f..a54faa6f 100644 --- a/shared/templates/shared/calendar_current_events_snippet.html +++ b/shared/templates/shared/calendar_current_events_snippet.html @@ -5,8 +5,8 @@ <aside class="banner bg-orange-300 text-white h-full"> <i class="ico--calendar banner__icon"></i> <div class="banner__body"><h1 class="head-alt-md banner__cta">Kalendář</h1> - {% if not fullscreen and page.root_page.first_calendar_page %} - <a href="{{ page.root_page.first_calendar_page.url }}"> + {% if not fullscreen and page.calendar_page %} + <a href="{{ page.calendar_page.url }}"> <button class="btn btn--white btn--fullwidth sm:btn--autowidth mt-8"> <div class="btn__body">Zobrazit další</div> </button> diff --git a/uniweb/migrations/0042_uniwebcalendarpage_uniwebhomepage_calendar_page.py b/uniweb/migrations/0042_uniwebcalendarpage_uniwebhomepage_calendar_page.py index 1a805596..dd100b5c 100644 --- a/uniweb/migrations/0042_uniwebcalendarpage_uniwebhomepage_calendar_page.py +++ b/uniweb/migrations/0042_uniwebcalendarpage_uniwebhomepage_calendar_page.py @@ -1,4 +1,4 @@ -# Generated by Django 4.1.8 on 2023-04-14 23:48 +# Generated by Django 4.1.8 on 2023-04-27 18:52 import django.db.models.deletion import wagtailmetadata.models @@ -9,9 +9,9 @@ import shared.models class Migration(migrations.Migration): dependencies = [ - ("wagtailimages", "0025_alter_image_file_alter_rendition_file"), - ("wagtailcore", "0083_workflowcontenttype"), ("calendar_utils", "0004_auto_20220505_1228"), + ("wagtailcore", "0083_workflowcontenttype"), + ("wagtailimages", "0025_alter_image_file_alter_rendition_file"), ("uniweb", "0041_alter_uniwebflexiblepage_content_and_more"), ] @@ -33,7 +33,9 @@ class Migration(migrations.Migration): ( "calendar_url", models.URLField( - null=True, verbose_name="URL kalendáře ve formátu iCal" + blank=True, + null=True, + verbose_name="URL kalendáře ve formátu iCal", ), ), ( diff --git a/uniweb/models.py b/uniweb/models.py index 6569f8bf..434c0963 100644 --- a/uniweb/models.py +++ b/uniweb/models.py @@ -1,3 +1,5 @@ +import random + from captcha.fields import CaptchaField from django import forms from django.core.paginator import Paginator @@ -23,7 +25,7 @@ from wagtail.images.blocks import ImageChooserBlock from wagtail.models import Page from wagtailmetadata.models import MetadataPageMixin -from calendar_utils.models import CalendarMixin, CalendarPageMixin +from calendar_utils.models import CalendarMixin from shared.blocks import ChartBlock from shared.const import RICH_TEXT_DEFAULT_FEATURES from shared.models import ( @@ -32,7 +34,7 @@ from shared.models import ( ExtendedMetadataPageMixin, SubpageMixin, ) -from shared.utils import make_promote_panels +from shared.utils import make_promote_panels, strip_all_html_tags, trim_to_length from tuning import admin_help from .blocks import PeopleGroupListBlock, PersonUrlBlock @@ -455,14 +457,14 @@ class UniwebFlexiblePage( verbose_name = "Flexibilní stránka" -class UniwebCalendarPage(SubpageMixin, MetadataPageMixin, CalendarPageMixin, Page): +class UniwebCalendarPage(SubpageMixin, MetadataPageMixin, CalendarMixin, Page): """ Page for displaying full calendar """ ### PANELS - content_panels = Page.content_panels + CalendarPageMixin.content_panels + content_panels = Page.content_panels + [FieldPanel("calendar_url")] ### RELATIONS -- GitLab