From 5ed190ada248002050984348a3a16219dbb63147 Mon Sep 17 00:00:00 2001 From: James Biggs Date: Mon, 2 Dec 2024 15:17:30 +0000 Subject: [PATCH] Add HeroAccentColourMixin to ExhibitionPage, and "Exhibition events" fields --- ...4_alter_exhibitionpage_options_and_more.py | 60 ++++++++++++++++++- etna/whatson/models.py | 25 +++++++- 2 files changed, 79 insertions(+), 6 deletions(-) diff --git a/etna/whatson/migrations/0014_alter_exhibitionpage_options_and_more.py b/etna/whatson/migrations/0014_alter_exhibitionpage_options_and_more.py index 95bbd98df..42023cc46 100644 --- a/etna/whatson/migrations/0014_alter_exhibitionpage_options_and_more.py +++ b/etna/whatson/migrations/0014_alter_exhibitionpage_options_and_more.py @@ -1,4 +1,4 @@ -# Generated by Django 5.1.2 on 2024-11-28 16:48 +# Generated by Django 5.1.2 on 2024-12-02 15:12 # etna:allowRemoveField # etna:allowAlterField # etna:allowDeleteModel @@ -97,7 +97,7 @@ class Migration(migrations.Migration): default="none", help_text="The accent colour of the page where relevant.", max_length=20, - verbose_name="hero text colour", + verbose_name="page accent colour", ), ), migrations.AddField( @@ -130,6 +130,44 @@ class Migration(migrations.Migration): verbose_name="booking details", ), ), + migrations.AddField( + model_name="exhibitionpage", + name="event_links", + field=wagtail.fields.StreamField( + [("event_links", 5)], + block_lookup={ + 0: ( + "wagtail.blocks.CharBlock", + (), + {"label": "Title", "max_length": 100}, + ), + 1: ("wagtail.blocks.CharBlock", (), {"label": "Description"}), + 2: ("wagtail.blocks.URLBlock", (), {"label": "URL"}), + 3: ( + "etna.core.blocks.image.APIImageChooserBlock", + (), + {"label": "Image", "required": False}, + ), + 4: ( + "wagtail.blocks.StructBlock", + [[("title", 0), ("description", 1), ("url", 2), ("image", 3)]], + {}, + ), + 5: ("wagtail.blocks.ListBlock", (4,), {"max_num": 2}), + }, + null=True, + ), + ), + migrations.AddField( + model_name="exhibitionpage", + name="event_title", + field=models.CharField( + default="Exhibition events", + help_text="The title of the events section.", + max_length=100, + verbose_name="event title", + ), + ), migrations.AddField( model_name="exhibitionpage", name="exclude_days", @@ -201,6 +239,22 @@ class Migration(migrations.Migration): to="wagtailcore.page", ), ), + migrations.AddField( + model_name="exhibitionpage", + name="hero_accent_colour", + field=models.CharField( + choices=[ + ("none", "None"), + ("contrast", "Contrast"), + ("tint", "Tint"), + ("accent", "Accent"), + ], + default="none", + help_text="The accent colour of the hero component.", + max_length=20, + verbose_name="hero component colour", + ), + ), migrations.AddField( model_name="exhibitionpage", name="hero_image_caption", @@ -407,7 +461,7 @@ class Migration(migrations.Migration): 4: ( "etna.core.blocks.image.APIImageChooserBlock", (), - {"label": "Background image", "required": False}, + {"label": "Background image"}, ), 5: ( "wagtail.blocks.StructBlock", diff --git a/etna/whatson/models.py b/etna/whatson/models.py index d3c49f35a..ddbcdd23f 100644 --- a/etna/whatson/models.py +++ b/etna/whatson/models.py @@ -25,6 +25,7 @@ from etna.articles.models import ArticleTagMixin from etna.collections.models import TopicalPageMixin from etna.core.blocks import ( + FeaturedExternalLinkBlock, FeaturedPagesBlock, ImageGalleryBlock, LargeCardLinksBlock, @@ -36,6 +37,7 @@ from etna.core.models import ( AccentColourMixin, BasePageWithRequiredIntro, + HeroAccentColourMixin, RequiredHeroImageMixin, ) from etna.core.serializers import DefaultPageSerializer, RichTextSerializer @@ -755,6 +757,7 @@ def save(self, *args, **kwargs): class ExhibitionPage( ArticleTagMixin, AccentColourMixin, + HeroAccentColourMixin, RequiredHeroImageMixin, TopicalPageMixin, BasePageWithRequiredIntro, @@ -891,6 +894,19 @@ class ExhibitionPage( related_pages = StreamField(FeaturedPagesBlock(), blank=True, null=True) + event_title = models.CharField( + max_length=100, + verbose_name=_("event title"), + help_text=_("The title of the events section."), + default="Exhibition events", + ) + + event_links = StreamField( + [("event_links", blocks.ListBlock(FeaturedExternalLinkBlock(), max_num=2))], + max_num=1, + null=True, + ) + shop = StreamField( [("shop", ShopCollectionBlock())], blank=True, @@ -912,9 +928,6 @@ def type_label(cls) -> str: """ Overrides the type_label method from BasePage, to return the correct type label for the exhibition page. - - NOTE: Removed `@classmethod` as that only acts on the class itself rather - than an instance of the class. """ if cls.end_date < timezone.now().date(): return "Past exhibition" @@ -930,6 +943,7 @@ class Meta: [ FieldPanel("hero_image"), FieldPanel("hero_image_caption"), + FieldPanel("hero_accent_colour"), FieldPanel("subtitle"), FieldPanel("accent_colour"), ], @@ -950,6 +964,8 @@ class Meta: FieldPanel("related_pages_title"), FieldPanel("featured_page"), FieldPanel("related_pages"), + FieldPanel("event_title"), + FieldPanel("event_links"), FieldPanel("shop"), ], heading=_("Related content"), @@ -1007,6 +1023,7 @@ class Meta: api_fields = ( BasePageWithRequiredIntro.api_fields + RequiredHeroImageMixin.api_fields + + HeroAccentColourMixin.api_fields + AccentColourMixin.api_fields + [ APIField("subtitle"), @@ -1029,6 +1046,8 @@ class Meta: APIField("related_pages_title"), APIField("featured_page", serializer=DefaultPageSerializer()), APIField("related_pages"), + APIField("event_title"), + APIField("event_links"), APIField("shop"), APIField("plan_your_visit"), ]