From 0658c3382f7fc984e7aa43cabe75f754c7c12ad8 Mon Sep 17 00:00:00 2001 From: Chuck Sebian-Lander Date: Fri, 7 Jun 2024 11:35:19 -0400 Subject: [PATCH 1/2] Wagtail-editable homepage --- .../v1/jinja2/v1/home_page/_hardcoded_en.html | 19 ---- cfgov/v1/models/home_page.py | 94 ++++++++++++++++++- 2 files changed, 89 insertions(+), 24 deletions(-) diff --git a/cfgov/v1/jinja2/v1/home_page/_hardcoded_en.html b/cfgov/v1/jinja2/v1/home_page/_hardcoded_en.html index 4110be91bb..4209bbfeb1 100644 --- a/cfgov/v1/jinja2/v1/home_page/_hardcoded_en.html +++ b/cfgov/v1/jinja2/v1/home_page/_hardcoded_en.html @@ -10,23 +10,6 @@ "is_jumbo": true } -%} -{%- set inkwell = { - "infounits": [ - { - "heading": "We enforce", - "content": "We’ve taken action against predatory companies and practices, returning billions of dollars to harmed consumers.", - }, - { - "heading": "We educate", - "content": "We help consumers build the skills they need to take control of their finances and plan for the future.", - }, - { - "heading": "We empower", - "content": "Our tools and resources help consumers make informed decisions through every step of their financial journey.", - }, - ], -} -%} - {%- set answers_heading = "Find answers to your money questions" -%} {%- set topics = { @@ -59,8 +42,6 @@ ], } -%} - - {%- set highlights = [ { "img_src": static( "apps/homepage/img/putting-green_finances-covid.png" ), diff --git a/cfgov/v1/models/home_page.py b/cfgov/v1/models/home_page.py index 7203e936fe..8ae77498e7 100644 --- a/cfgov/v1/models/home_page.py +++ b/cfgov/v1/models/home_page.py @@ -1,15 +1,99 @@ -from wagtail.admin.panels import ObjectList, TabbedInterface -from wagtail.models import Page +from django.db import models + +from wagtail.admin.panels import ( + FieldPanel, + MultiFieldPanel, + ObjectList, + TabbedInterface, +) +from wagtail.blocks import ListBlock, StructBlock, TextBlock from v1.models.base import CFGOVPage +class home_card(StructBlock): + icon = TextBlock() + text = TextBlock() + url = TextBlock() + + +class home_highlight(StructBlock): + card_type = "highlight" + img_src = TextBlock() + heading = TextBlock() + link_text = TextBlock() + link_url = TextBlock() + + +class home_breakout(StructBlock): + card_type = "breakout" + link_text = TextBlock() + link_url = TextBlock() + img_src = TextBlock() + + +class HomeTopics(StructBlock): + topics = ListBlock("home_card", default=list()) + + +class HomeHighlights(StructBlock): + highlights = ListBlock("home_highlight", default=list()) + + +class HomeBreakouts(StructBlock): + breakouts = ListBlock("home_breakout", default=list()) + + class HomePage(CFGOVPage): + hero_heading = models.TextField( + default="On your side", + help_text=("Will be formatted in bold"), + ) + + hero_heading_continued = models.TextField( + default="through life's financial moments." + ) + + hero_image = models.TextField() + + answers_heading = models.TextField( + default="Find answers to your money questions", + ) + + breakout_cards_heading = models.TextField( + default="Get help planning for future goals" + ) + + content_panels = CFGOVPage.content_panels + [ + MultiFieldPanel( + [ + FieldPanel("hero_heading"), + FieldPanel("hero_heading_continued"), + FieldPanel("hero_image"), + ], + heading="Hero", + ), + FieldPanel("highlights"), + MultiFieldPanel( + [ + FieldPanel("answers_heading"), + FieldPanel("home_topics", HomeTopics()), + ], + heading="Topics", + ), + # 50/50 goes here when we un-hardcode it + MultiFieldPanel( + [ + FieldPanel("breakout_cards_heading"), + FieldPanel("breakout_cards"), + ], + heading="Breakout cards", + ), + ] + edit_handler = TabbedInterface( [ - # This is required to support editing of the page's title field. - # HomePages have no other Wagtail-editable content fields. - ObjectList(Page.content_panels, heading="General Content"), + ObjectList(content_panels, heading="General Content"), ObjectList(CFGOVPage.settings_panels, heading="Configuration"), ] ) From 4521a212e18af7c6da5cbd0df558be1916d8a9c1 Mon Sep 17 00:00:00 2001 From: Chuck Sebian-Lander Date: Fri, 7 Jun 2024 13:31:24 -0400 Subject: [PATCH 2/2] no one has ever had less of an idea what they're doing --- cfgov/v1/jinja2/v1/home_page/home_page.html | 2 +- cfgov/v1/models/home_page.py | 112 +++++++++++--------- 2 files changed, 65 insertions(+), 49 deletions(-) diff --git a/cfgov/v1/jinja2/v1/home_page/home_page.html b/cfgov/v1/jinja2/v1/home_page/home_page.html index 4a0fb33f89..88d1065d96 100644 --- a/cfgov/v1/jinja2/v1/home_page/home_page.html +++ b/cfgov/v1/jinja2/v1/home_page/home_page.html @@ -60,7 +60,7 @@

{{ highlight.heading }}

{% block content_main %} {% import "v1/home_page/_hardcoded_" ~ language ~ ".html" as hardcoded with context %}
-

{{ hardcoded.answers_heading }}

+

{{ breakout_cards_heading }}

diff --git a/cfgov/v1/models/home_page.py b/cfgov/v1/models/home_page.py index 8ae77498e7..a9e8cc9a6e 100644 --- a/cfgov/v1/models/home_page.py +++ b/cfgov/v1/models/home_page.py @@ -1,93 +1,109 @@ from django.db import models +from wagtail import blocks from wagtail.admin.panels import ( FieldPanel, MultiFieldPanel, ObjectList, TabbedInterface, ) -from wagtail.blocks import ListBlock, StructBlock, TextBlock +from wagtail.fields import StreamField from v1.models.base import CFGOVPage -class home_card(StructBlock): - icon = TextBlock() - text = TextBlock() - url = TextBlock() - - -class home_highlight(StructBlock): - card_type = "highlight" - img_src = TextBlock() - heading = TextBlock() - link_text = TextBlock() - link_url = TextBlock() - - -class home_breakout(StructBlock): - card_type = "breakout" - link_text = TextBlock() - link_url = TextBlock() - img_src = TextBlock() - - -class HomeTopics(StructBlock): - topics = ListBlock("home_card", default=list()) - - -class HomeHighlights(StructBlock): - highlights = ListBlock("home_highlight", default=list()) - - -class HomeBreakouts(StructBlock): - breakouts = ListBlock("home_breakout", default=list()) - - class HomePage(CFGOVPage): hero_heading = models.TextField( - default="On your side", - help_text=("Will be formatted in bold"), + blank=True, + null=True, ) hero_heading_continued = models.TextField( - default="through life's financial moments." + blank=True, + null=True, ) - hero_image = models.TextField() + hero_image = models.TextField( + blank=True, + null=True, + ) - answers_heading = models.TextField( - default="Find answers to your money questions", + topics_heading = models.TextField( + blank=True, + null=True, ) breakout_cards_heading = models.TextField( - default="Get help planning for future goals" + blank=True, + null=True, + ) + + class HighlightItemBlock(blocks.StructBlock): + img_src = blocks.CharBlock(label="Image URL") + heading = blocks.CharBlock() + link_text = blocks.CharBlock() + link_url = blocks.CharBlock() + + highlights = StreamField( + [("highlight", HighlightItemBlock())], + blank=True, + ) + + class TopicItemBlock(blocks.StructBlock): + icon = blocks.CharBlock() + text = blocks.CharBlock() + url = blocks.CharBlock() + + topics = StreamField( + [("topic", TopicItemBlock())], + blank=True, + ) + + class BreakoutCardBlock(blocks.StructBlock): + link_text = blocks.CharBlock() + link_url = blocks.CharBlock() + img_src = blocks.CharBlock(label="Image URL") + + breakout_cards = StreamField( + [("card", BreakoutCardBlock())], + blank=True, ) content_panels = CFGOVPage.content_panels + [ MultiFieldPanel( [ - FieldPanel("hero_heading"), - FieldPanel("hero_heading_continued"), - FieldPanel("hero_image"), + FieldPanel("hero_heading", heading="Hero H1 (bold)"), + FieldPanel( + "hero_heading_continued", heading="Hero H1 continued" + ), + FieldPanel("hero_image", heading="Image URL"), ], heading="Hero", + classname="collapsible", + ), + MultiFieldPanel( + [ + FieldPanel("highlights"), + ], + heading="Highlights", + classname="collapsible", ), - FieldPanel("highlights"), MultiFieldPanel( [ - FieldPanel("answers_heading"), - FieldPanel("home_topics", HomeTopics()), + FieldPanel("topics_heading"), + FieldPanel("topics"), ], heading="Topics", + classname="collapsible", ), - # 50/50 goes here when we un-hardcode it + # 5050 goes here MultiFieldPanel( [ FieldPanel("breakout_cards_heading"), FieldPanel("breakout_cards"), ], heading="Breakout cards", + classname="collapsible", ), ]