From d6e74816c489651386121ac1b6dfab1ed0f3e5d5 Mon Sep 17 00:00:00 2001 From: Ram Date: Tue, 24 Sep 2024 15:53:06 -0600 Subject: [PATCH] Allow homepage sections to be editable. (#12866) * Rename `News you can use` section to `Highlights`, enable CMS customization of homepage titles * Updated migration * Fix typo in updated linting ignore rules * Updated migration state * Update migration * Updated migration order * Update migration deps * Migration linearity update --- .../wagtailpages/factory/__init__.py | 4 +-- ..._usable_news.py => homepage_highlights.py} | 10 +++--- ...ighlights_replace_homepagenewsyoucanuse.py | 34 +++++++++++++++++++ network-api/networkapi/wagtailpages/models.py | 2 +- .../wagtailpages/pagemodels/base.py | 19 ++++++++--- ...{news_you_can_use.html => highlights.html} | 6 ++-- .../wagtailpages/fragments/ideas_posts.html | 2 +- .../templates/wagtailpages/homepage.html | 2 +- pyproject.toml | 2 +- 9 files changed, 62 insertions(+), 19 deletions(-) rename network-api/networkapi/wagtailpages/factory/{homepage_usable_news.py => homepage_highlights.py} (60%) create mode 100644 network-api/networkapi/wagtailpages/migrations/0166_homepagehighlights_replace_homepagenewsyoucanuse.py rename network-api/networkapi/wagtailpages/templates/wagtailpages/fragments/{news_you_can_use.html => highlights.html} (97%) diff --git a/network-api/networkapi/wagtailpages/factory/__init__.py b/network-api/networkapi/wagtailpages/factory/__init__.py index 5b4921c214f..ee5111d71db 100644 --- a/network-api/networkapi/wagtailpages/factory/__init__.py +++ b/network-api/networkapi/wagtailpages/factory/__init__.py @@ -10,9 +10,9 @@ homepage, homepage_cause_statement_link, homepage_features, + homepage_highlights, homepage_partner_logos, homepage_take_action, - homepage_usable_news, initiatives_page, locale, opportunity, @@ -40,7 +40,7 @@ def generate(seed): homepage_features.generate(seed) homepage_partner_logos.generate(seed) homepage_take_action.generate(seed) - homepage_usable_news.generate(seed) + homepage_highlights.generate(seed) initiatives_page.generate(seed) opportunity.generate(seed) participate_page_featured_highlights.generate(seed) diff --git a/network-api/networkapi/wagtailpages/factory/homepage_usable_news.py b/network-api/networkapi/wagtailpages/factory/homepage_highlights.py similarity index 60% rename from network-api/networkapi/wagtailpages/factory/homepage_usable_news.py rename to network-api/networkapi/wagtailpages/factory/homepage_highlights.py index ab5b9b3b626..755a03d7521 100644 --- a/network-api/networkapi/wagtailpages/factory/homepage_usable_news.py +++ b/network-api/networkapi/wagtailpages/factory/homepage_highlights.py @@ -2,22 +2,22 @@ from factory.django import DjangoModelFactory from networkapi.utility.faker.helpers import get_homepage, reseed -from networkapi.wagtailpages.models import BlogPage, HomepageNewsYouCanUse +from networkapi.wagtailpages.models import BlogPage, HomepageHighlights from .blog import BlogPageFactory from .homepage import WagtailHomepageFactory -class NewsYouCanUseFactory(DjangoModelFactory): +class HightlightsFactory(DjangoModelFactory): class Meta: abstract = True page = SubFactory(WagtailHomepageFactory) -class HomepageNewsYouCanUseFactory(NewsYouCanUseFactory): +class HomepageHightlightsFactory(HightlightsFactory): class Meta: - model = HomepageNewsYouCanUse + model = HomepageHighlights blog = SubFactory(BlogPageFactory) @@ -29,6 +29,6 @@ def generate(seed): reseed(seed) - home_page.news_you_can_use = [HomepageNewsYouCanUseFactory.build(blog=BlogPage.objects.all()[i]) for i in range(4)] + home_page.highlights = [HomepageHightlightsFactory.build(blog=BlogPage.objects.all()[i]) for i in range(4)] home_page.save() diff --git a/network-api/networkapi/wagtailpages/migrations/0166_homepagehighlights_replace_homepagenewsyoucanuse.py b/network-api/networkapi/wagtailpages/migrations/0166_homepagehighlights_replace_homepagenewsyoucanuse.py new file mode 100644 index 00000000000..6ef7cd55831 --- /dev/null +++ b/network-api/networkapi/wagtailpages/migrations/0166_homepagehighlights_replace_homepagenewsyoucanuse.py @@ -0,0 +1,34 @@ +import django.db.models.deletion +import modelcluster.fields +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("wagtailpages", "0165_alter_articlepage_body_alter_blogpage_body_and_more"), + ] + + operations = [ + migrations.RenameModel( + old_name="HomepageNewsYouCanUse", + new_name="HomepageHighlights", + ), + migrations.AddField( + model_name="homepage", + name="ideas_title", + field=models.CharField(default="Ideas", max_length=50), + ), + migrations.AddField( + model_name="homepage", + name="highlights_title", + field=models.CharField(default="The Highlights", max_length=50), + ), + migrations.AlterField( + model_name="homepagehighlights", + name="page", + field=modelcluster.fields.ParentalKey( + on_delete=django.db.models.deletion.CASCADE, related_name="highlights", to="wagtailpages.homepage" + ), + ), + ] diff --git a/network-api/networkapi/wagtailpages/models.py b/network-api/networkapi/wagtailpages/models.py index efd254e1e70..28ab0304ff7 100644 --- a/network-api/networkapi/wagtailpages/models.py +++ b/network-api/networkapi/wagtailpages/models.py @@ -5,8 +5,8 @@ FoundationMetadataPageMixin, Homepage, HomepageFocusAreas, + HomepageHighlights, HomepageIdeasPosts, - HomepageNewsYouCanUse, InitiativesPage, ParticipateHighlights, ParticipateHighlights2, diff --git a/network-api/networkapi/wagtailpages/pagemodels/base.py b/network-api/networkapi/wagtailpages/pagemodels/base.py index 06473963b45..9d94a41abb2 100644 --- a/network-api/networkapi/wagtailpages/pagemodels/base.py +++ b/network-api/networkapi/wagtailpages/pagemodels/base.py @@ -473,10 +473,10 @@ def __str__(self): return self.page.title + "->" + self.blog.title -class HomepageNewsYouCanUse(TranslatableMixin, WagtailOrderable): +class HomepageHighlights(TranslatableMixin, WagtailOrderable): page = ParentalKey( "wagtailpages.Homepage", - related_name="news_you_can_use", + related_name="highlights", ) blog = models.ForeignKey("BlogPage", on_delete=models.CASCADE, related_name="+") panels = [ @@ -774,6 +774,8 @@ def get_banner(self): max_num=1, ) + ideas_title = models.CharField(default="Ideas", max_length=50) + ideas_image = models.ForeignKey( "wagtailimages.Image", null=True, @@ -847,6 +849,9 @@ def get_banner(self): null=True, on_delete=models.SET_NULL, ) + + highlights_title = models.CharField(default="The Highlights", max_length=50) + # Take Action Section take_action_title = models.CharField(default="Take action", max_length=50) @@ -893,13 +898,15 @@ def get_banner(self): ), MultiFieldPanel( [ - InlinePanel("news_you_can_use", min_num=4, max_num=4), + FieldPanel("highlights_title"), + InlinePanel("highlights", min_num=4, max_num=4), ], - heading="News you can use", + heading="The Highlights", classname="collapsible", ), MultiFieldPanel( [ + FieldPanel("ideas_title"), FieldPanel("ideas_image"), FieldPanel("ideas_headline"), InlinePanel("ideas_posts", label="Posts", min_num=3, max_num=3), @@ -955,6 +962,7 @@ def get_banner(self): TranslatableField("hero_intro_heading"), TranslatableField("hero_intro_body"), SynchronizedField("hero_intro_link"), + TranslatableField("ideas_title"), SynchronizedField("ideas_image"), TranslatableField("ideas_headline"), TranslatableField("cause_statement"), @@ -974,7 +982,8 @@ def get_banner(self): TranslatableField("take_action_cards"), TranslatableField("partner_logos"), TranslatableField("ideas_posts"), - TranslatableField("news_you_can_use"), + TranslatableField("highlights"), + TranslatableField("highlights_title"), ] subpage_types = [ diff --git a/network-api/networkapi/wagtailpages/templates/wagtailpages/fragments/news_you_can_use.html b/network-api/networkapi/wagtailpages/templates/wagtailpages/fragments/highlights.html similarity index 97% rename from network-api/networkapi/wagtailpages/templates/wagtailpages/fragments/news_you_can_use.html rename to network-api/networkapi/wagtailpages/templates/wagtailpages/fragments/highlights.html index c874ffc2ea7..b0f9c7308e3 100644 --- a/network-api/networkapi/wagtailpages/templates/wagtailpages/fragments/news_you_can_use.html +++ b/network-api/networkapi/wagtailpages/templates/wagtailpages/fragments/highlights.html @@ -4,14 +4,14 @@
-

{% trans "News you can use" %}

+

{{ page.highlights_title }}

{# this should not be a hardcoded route... #} - {% trans "Read more news" %} + {% trans "Read more" %}
- {% with items=page.news_you_can_use.all %} + {% with items=page.highlights.all %} {% comment %} diff --git a/network-api/networkapi/wagtailpages/templates/wagtailpages/fragments/ideas_posts.html b/network-api/networkapi/wagtailpages/templates/wagtailpages/fragments/ideas_posts.html index 4d9bcc9475e..312fe5ef6f8 100644 --- a/network-api/networkapi/wagtailpages/templates/wagtailpages/fragments/ideas_posts.html +++ b/network-api/networkapi/wagtailpages/templates/wagtailpages/fragments/ideas_posts.html @@ -3,7 +3,7 @@
-

{% trans "Ideas" %}

+

{{ page.ideas_title }}

diff --git a/network-api/networkapi/wagtailpages/templates/wagtailpages/homepage.html b/network-api/networkapi/wagtailpages/templates/wagtailpages/homepage.html index d2f4763703a..958a5563b72 100644 --- a/network-api/networkapi/wagtailpages/templates/wagtailpages/homepage.html +++ b/network-api/networkapi/wagtailpages/templates/wagtailpages/homepage.html @@ -41,7 +41,7 @@
- {% include "./fragments/news_you_can_use.html" %} + {% include "./fragments/highlights.html" %}
diff --git a/pyproject.toml b/pyproject.toml index 60789aa3200..f14d97c5585 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -172,7 +172,7 @@ ignore="H017" "network-api/networkapi/wagtailpages/templates/wagtailpages/fragments/entry_cards.html" = "T003,T032" "network-api/networkapi/wagtailpages/templates/wagtailpages/fragments/formassembly_body.html" = "H021, H026" "network-api/networkapi/wagtailpages/templates/wagtailpages/fragments/generic_card.html" = "T003" -"network-api/networkapi/wagtailpages/templates/wagtailpages/fragments/news_you_can_use.html" = "D018,H006,T032" +"network-api/networkapi/wagtailpages/templates/wagtailpages/fragments/highlights.html" = "D018,H006,T032" "network-api/networkapi/wagtailpages/templates/wagtailpages/fragments/newsletter-signup-box.html" = "H008" "network-api/networkapi/wagtailpages/templates/wagtailpages/fragments/partner.html" = "H006,H008,H014" "network-api/networkapi/wagtailpages/templates/wagtailpages/fragments/primary_heroguts.html" = "H006"