Skip to content

Commit

Permalink
Allow homepage sections to be editable. (#12866)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ramram-mf authored Sep 24, 2024
1 parent a284b31 commit d6e7481
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 19 deletions.
4 changes: 2 additions & 2 deletions network-api/networkapi/wagtailpages/factory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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()
Original file line number Diff line number Diff line change
@@ -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"
),
),
]
2 changes: 1 addition & 1 deletion network-api/networkapi/wagtailpages/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
FoundationMetadataPageMixin,
Homepage,
HomepageFocusAreas,
HomepageHighlights,
HomepageIdeasPosts,
HomepageNewsYouCanUse,
InitiativesPage,
ParticipateHighlights,
ParticipateHighlights2,
Expand Down
19 changes: 14 additions & 5 deletions network-api/networkapi/wagtailpages/pagemodels/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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"),
Expand All @@ -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 = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

<div class="row section-news-you-can-use section-padding">
<div class="col-12 d-flex flex-row justify-content-between">
<h2 class="tw-text-[22px] tw-leading-[30px] medium:tw-text-2xl medium:tw-leading-[30px] tw-font-bold tw-font-sans tw-text-black tw-tracking-normal tw-mb-5">{% trans "News you can use" %}</h2>
<h2 class="tw-text-[22px] tw-leading-[30px] medium:tw-text-2xl medium:tw-leading-[30px] tw-font-bold tw-font-sans tw-text-black tw-tracking-normal tw-mb-5">{{ page.highlights_title }}</h2>
{# this should not be a hardcoded route... #}
<a href="/{{ lang_code }}/blog" class="tw-cta-link d-none d-md-inline-block" id="news-you-can-use-cta">{% trans "Read more news" %}</a>
<a href="/{{ lang_code }}/blog" class="tw-cta-link d-none d-md-inline-block" id="news-you-can-use-cta">{% trans "Read more" %}</a>
</div>

<div class="col-12">
<div class="row d-flex flex-row mb-4">
{% with items=page.news_you_can_use.all %}
{% with items=page.highlights.all %}

{% comment %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="row section-ideas section-padding">

<div class="col-12">
<h2 class="capsule-label mb-0 ml-md-4">{% trans "Ideas" %}</h2>
<h2 class="capsule-label mb-0 ml-md-4">{{ page.ideas_title }}</h2>
</div>
<div class="col-12 col-lg-6 mb-md-4 mb-lg-0 tw-dark">
<div class="ideas-banner d-flex align-items-end full-bleed-xs p-3 p-md-4" style="background-image: linear-gradient(180deg, rgba(238,238,238,0) 14%, #000000 100%), url({% image_url page.ideas_image "width-540" %});">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

<div class="tw-bg-gray-05">
<div class="container">
{% include "./fragments/news_you_can_use.html" %}
{% include "./fragments/highlights.html" %}
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit d6e7481

Please sign in to comment.