Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make homepage editable in Wagtail #8460

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions cfgov/v1/jinja2/v1/home_page/_hardcoded_en.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
],
} -%}

<!-- {%- set highlights_heading = "Bureau highlights" -%} -->

{%- set highlights = [
{
"img_src": static( "apps/homepage/img/putting-green_housing-counselor.png" ),
Expand Down
2 changes: 1 addition & 1 deletion cfgov/v1/jinja2/v1/home_page/home_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ <h2 class="h3">{{ highlight.heading }}</h2>
{% block content_main %}
{% import "v1/home_page/_hardcoded_" ~ language ~ ".html" as hardcoded with context %}
<section class="block u-text-centered">
<h2 class="h1">{{ hardcoded.answers_heading }}</h2>
<h2 class="h1">{{ breakout_cards_heading }}</h2>
</section>

<section class="block">
Expand Down
110 changes: 105 additions & 5 deletions cfgov/v1/models/home_page.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,115 @@
from wagtail.admin.panels import ObjectList, TabbedInterface
from wagtail.models import Page
from django.db import models

from wagtail import blocks
from wagtail.admin.panels import (
FieldPanel,
MultiFieldPanel,
ObjectList,
TabbedInterface,
)
from wagtail.fields import StreamField

from v1.models.base import CFGOVPage


class HomePage(CFGOVPage):
hero_heading = models.TextField(
blank=True,
null=True,
)

hero_heading_continued = models.TextField(
blank=True,
null=True,
)

hero_image = models.TextField(
blank=True,
null=True,
)

topics_heading = models.TextField(
blank=True,
null=True,
)

breakout_cards_heading = models.TextField(
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", 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",
),
MultiFieldPanel(
[
FieldPanel("topics_heading"),
FieldPanel("topics"),
],
heading="Topics",
classname="collapsible",
),
# 5050 goes here
MultiFieldPanel(
[
FieldPanel("breakout_cards_heading"),
FieldPanel("breakout_cards"),
],
heading="Breakout cards",
classname="collapsible",
),
]

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"),
]
)
Expand Down
Loading