diff --git a/calendar_utils/models.py b/calendar_utils/models.py index 335161250f7c8c763a9fb89a11f700035984b25a..39c231bc0a444aa270a73deed62138389e95a233 100644 --- a/calendar_utils/models.py +++ b/calendar_utils/models.py @@ -5,6 +5,9 @@ import arrow from django.core.serializers.json import DjangoJSONEncoder from django.db import models from icalevnt import icalevents +from wagtail.admin.panels import FieldPanel +from wagtail.models import Page +from wagtailmetadata.models import MetadataPageMixin from .parser import process_event_list @@ -76,6 +79,13 @@ class CalendarMixin(models.Model): calendar = models.ForeignKey( Calendar, null=True, blank=True, on_delete=models.PROTECT ) + calendar_page = models.ForeignKey( + "calendar_utils.CalendarPage", + verbose_name="Stránka s kalendářem", + on_delete=models.PROTECT, + null=True, + blank=True, + ) class Meta: abstract = True @@ -102,3 +112,35 @@ class CalendarMixin(models.Model): self.calendar = None super().save(*args, **kwargs) + + +class CalendarPage(SubpageMixin, MetadataPageMixin, CalendarMixin, Page): + """ + Page for displaying full calendar + """ + + calendar_url = models.URLField( + "URL kalendáře ve formátu iCal", blank=False, null=True + ) + + ### PANELS + + content_panels = Page.content_panels + [ + FieldPanel("calendar_url"), + ] + + ### RELATIONS + + parent_page_types = [ + "district.DistrictCenterPage", + "district.DistrictHomePage", + "elections2021.Elections2021CalendarPage", + "senat_campaign.SenatCampaignHomePage", + "uniweb.UniwebHomePage", + ] + subpage_types = [] + + ### OTHERS + + class Meta: + verbose_name = "Stránka s kalendářem" diff --git a/district/models.py b/district/models.py index 68270abaabb159ddfd320bed2e2c103ea580b91b..71fef1f7878d86be9ff010e4eb09d5bb0474adef 100644 --- a/district/models.py +++ b/district/models.py @@ -247,7 +247,13 @@ class DistrictHomePage( [ FieldPanel("region_map_button_text"), FieldPanel("calendar_button_text"), - FieldPanel("calendar_url"), + MultiFieldPanel( + [ + FieldPanel("calendar_url"), + PageChooserPanel("calendar_page"), + ], + "Kalendář", + ), ], gettext_lazy("Nastavení lišty s kalendářem a mapou"), ), @@ -278,6 +284,7 @@ class DistrictHomePage( "district.DistrictProgramPage", "district.DistrictInteractiveProgramPage", "district.DistrictGeoFeatureCollectionPage", + "calendar_utils.CalendarPage", ] ### OTHERS @@ -1243,7 +1250,14 @@ class DistrictCenterPage( FieldPanel("background_photo"), FieldPanel("text"), FieldPanel("content"), - FieldPanel("calendar_url"), + MultiFieldPanel( + [ + FieldPanel("calendar_url"), + PageChooserPanel("calendar_page"), + ], + "Kalendář", + ), + PageChooserPanel("calendar_page"), FieldPanel("sidebar_content"), ] @@ -1254,7 +1268,7 @@ class DistrictCenterPage( ### RELATIONS parent_page_types = ["district.DistrictHomePage"] - subpage_types = [] + subpage_types = ["calendar_utils.CalendarPage"] ### OTHERS diff --git a/elections2021/models.py b/elections2021/models.py index cd452b167b8d1332868967e5eb617b4b7be319ad..fe54fe96cc6ea6227dbaee49f8b739906171fe5b 100644 --- a/elections2021/models.py +++ b/elections2021/models.py @@ -2578,7 +2578,13 @@ class Elections2021CalendarPage(SubpageMixin, MetadataPageMixin, CalendarMixin, content_panels = Page.content_panels + [ FieldPanel("photo"), - FieldPanel("calendar_url"), + MultiFieldPanel( + [ + FieldPanel("calendar_url"), + PageChooserPanel("calendar_page"), + ], + "Kalendář", + ), ] promote_panels = [ @@ -2602,7 +2608,7 @@ class Elections2021CalendarPage(SubpageMixin, MetadataPageMixin, CalendarMixin, ### RELATIONS parent_page_types = ["elections2021.Elections2021HomePage"] - subpage_types = [] + subpage_types = ["calendar_utils.CalendarPage"] ### OTHERS diff --git a/senat_campaign/models.py b/senat_campaign/models.py index 7b68f07064a4ced0c76fa65e0299c9c045512deb..d45a1547645d5bad8c3cacfa190331cfe0f86f2b 100644 --- a/senat_campaign/models.py +++ b/senat_campaign/models.py @@ -7,6 +7,7 @@ from wagtail.admin.panels import ( FieldPanel, HelpPanel, MultiFieldPanel, + PageChooserPanel, PublishingPanel, ) from wagtail.documents.blocks import DocumentChooserBlock @@ -183,7 +184,13 @@ class SenatCampaignHomePage( ], heading="Sociální sítě", ), - FieldPanel("calendar_url"), + MultiFieldPanel( + [ + FieldPanel("calendar_url"), + PageChooserPanel("calendar_page"), + ], + "Kalendář", + ), FieldPanel("donations_url"), FieldPanel("matomo_id"), FieldPanel("title_suffix"), @@ -197,6 +204,7 @@ class SenatCampaignHomePage( "senat_campaign.SenatCampaignNewsIndexPage", "senat_campaign.SenatCampaignProgramPage", "senat_campaign.SenatCampaignCookiesPage", + "calendar_utils.CalendarPage", ] ### OTHERS diff --git a/uniweb/models.py b/uniweb/models.py index e68eb96c9918f7090a39b255b5adfbb71338d39d..91d53570c7614dbdcc9597ba04e8eb20c20ca8b1 100644 --- a/uniweb/models.py +++ b/uniweb/models.py @@ -12,6 +12,7 @@ from wagtail.admin.panels import ( InlinePanel, MultiFieldPanel, ObjectList, + PageChooserPanel, TabbedInterface, ) from wagtail.contrib.forms.models import AbstractForm, AbstractFormField @@ -34,11 +35,7 @@ from shared.models import ( from shared.utils import make_promote_panels from tuning import admin_help -from .blocks import ( - PersonCustomPositionBlock, - PeopleGroupListBlock, - PersonUrlBlock, -) +from .blocks import PeopleGroupListBlock, PersonCustomPositionBlock, PersonUrlBlock from .constants import ( ALIGN_CHOICES, ALIGN_CSS, @@ -359,7 +356,13 @@ class UniwebHomePage( ], "nastavení webu", ), - FieldPanel("calendar_url"), + MultiFieldPanel( + [ + FieldPanel("calendar_url"), + PageChooserPanel("calendar_page"), + ], + "Kalendář", + ), MultiFieldPanel( [ FieldPanel("show_logo"), @@ -390,6 +393,7 @@ class UniwebHomePage( "uniweb.UniwebArticlesIndexPage", "uniweb.UniwebFormPage", "uniweb.UniwebPeoplePage", + "calendar_utils.CalendarPage", ] ### OTHERS