Skip to content

Commit

Permalink
CDD-2169: New landing page
Browse files Browse the repository at this point in the history
  • Loading branch information
phill-stanley committed Sep 25, 2024
1 parent 1f5f91c commit cd63baa
Show file tree
Hide file tree
Showing 34 changed files with 1,935 additions and 6 deletions.
6 changes: 6 additions & 0 deletions cms/dashboard/management/commands/build_cms_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def handle(self, *args, **options):
is_default_site=True,
)

# Deprecated: to be removed after migration to landing page version two.
landing_dashboard_page: HomePage = (
build_cms_site_helpers.create_landing_dashboard_page(parent_page=root_page)
)
Expand Down Expand Up @@ -121,6 +122,11 @@ def handle(self, *args, **options):
name="cold_health_alerts", parent_page=weather_health_alerts_page
)

# landing page version two
build_cms_site_helpers.create_landing_dashboard_page_version_two(
parent_page=root_page
)

build_cms_site_helpers.create_menu_snippet()

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
create_composite_page,
create_bulk_downloads_page,
create_landing_dashboard_page,
create_landing_dashboard_page_version_two,
create_whats_new_parent_page,
create_whats_new_child_entry,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
from cms.composite.models import CompositePage
from cms.topic.models import TopicPage


def create_landing_page_body_wih_page_links() -> list[dict]:
covid_page = TopicPage.objects.get(slug="covid-19")
influenza_page = TopicPage.objects.get(slug="influenza")
other_respiratory_viruses_page = TopicPage.objects.get(
slug="other-respiratory-viruses"
)
weather_health_alerts_page = CompositePage.objects.get(slug="weather-health-alerts")

return [
{
"type": "section",
"value": {
"heading": "Respiratory viruses",
"page_link": None,
"content": [
{
"type": "chart_row_card",
"value": {
"columns": [
{
"type": "simplified_chart_with_link",
"value": {
"title": "COVID-19",
"sub_title": "Cases reported",
"tag_manager_event_id": "",
"topic_page": covid_page.id,
"x_axis": "date",
"y_axis": "metric",
"chart": [
{
"type": "plot",
"value": {
"topic": "COVID-19",
"metric": "COVID-19_cases_countRollingMean",
"geography": "England",
"geography_type": "Nation",
"sex": "all",
"age": "all",
"stratum": "default",
"chart_type": "line_single_simplified",
},
"id": "0cb2a953-8737-4978-9886-d3943b76820a",
}
],
},
"id": "8b2ca8aa-7bdb-4c47-835c-dc1c09f767cf",
},
{
"type": "simplified_chart_with_link",
"value": {
"title": "Influenza",
"sub_title": "Healthcare admission rates",
"tag_manager_event_id": "",
"topic_page": influenza_page.id,
"x_axis": "date",
"y_axis": "metric",
"chart": [
{
"type": "plot",
"value": {
"topic": "Influenza",
"metric": "influenza_healthcare_ICUHDUadmissionRateByWeek",
"geography": "England",
"geography_type": "Nation",
"sex": "all",
"age": "all",
"stratum": "default",
"chart_type": "line_single_simplified",
},
"id": "7423460c-aa0c-482d-8fd5-ab9c62396657",
}
],
},
"id": "b7b37be5-8bc0-4f88-8310-7a91430b7993",
},
{
"type": "simplified_chart_with_link",
"value": {
"title": "RSV",
"sub_title": "Healthcare admission rates",
"tag_manager_event_id": "",
"topic_page": other_respiratory_viruses_page.id,
"x_axis": "date",
"y_axis": "metric",
"chart": [
{
"type": "plot",
"value": {
"topic": "RSV",
"metric": "RSV_healthcare_admissionRateByWeek",
"geography": "England",
"geography_type": "Nation",
"sex": "all",
"age": "all",
"stratum": "default",
"chart_type": "line_single_simplified",
},
"id": "f9eb94ff-0d92-4265-a88b-d52bf73532a5",
}
],
},
"id": "0a830ab5-b232-47f1-a5af-f140e0f07c23",
},
]
},
"id": "40d17855-71e3-424e-a662-2f6930073e59",
}
],
},
"id": "c3ec156e-e58b-4976-b0f2-c08c1e933467",
},
{
"type": "section",
"value": {
"heading": "Weather health alerts",
"page_link": weather_health_alerts_page.id,
"content": [
{
"type": "weather_health_alert_card",
"value": {
"title": "weather health alerts",
"sub_title": "Across England",
"alert_type": "heat",
},
"id": "d01c65cb-4cd2-4e07-bd6e-71ea0ec04594",
}
],
},
"id": "be533e25-ba91-4e86-8a45-1314ed395fb9",
},
]
23 changes: 23 additions & 0 deletions cms/dashboard/management/commands/build_cms_site_helpers/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

from cms.common.models import CommonPage, CommonPageRelatedLink
from cms.composite.models import CompositePage, CompositeRelatedLink
from cms.dashboard.management.commands.build_cms_site_helpers.landing_page import (
create_landing_page_body_wih_page_links,
)
from cms.home.models import HomePage, HomePageRelatedLink
from cms.landing_page.models import LandingPage
from cms.snippets.data_migrations.operations import (
get_or_create_download_button_internal_button_snippet,
)
Expand Down Expand Up @@ -41,6 +45,7 @@ def _add_page_to_parent(*, page: Page, parent_page: Page) -> None:
page.save_revision().publish()


# Deprecated: to be removed after version two migration.
def create_landing_dashboard_page(*, parent_page: Page) -> HomePage:
data = open_example_page_response(page_name="ukhsa_data_dashboard")

Expand All @@ -63,6 +68,24 @@ def create_landing_dashboard_page(*, parent_page: Page) -> HomePage:
return page


def create_landing_dashboard_page_version_two(*, parent_page: Page) -> LandingPage:
data = open_example_page_response(page_name="landing_page")

landing_page_body = create_landing_page_body_wih_page_links()

page = LandingPage(
title=data["title"],
sub_title=data["sub_title"],
body=landing_page_body,
slug=data["meta"]["slug"],
seo_title=data["meta"]["seo_title"],
search_description=data["meta"]["search_description"],
)
_add_page_to_parent(page=page, parent_page=parent_page)

return page


def create_topic_page(*, name: str, parent_page: Page) -> TopicPage:
data = open_example_page_response(page_name=name)

Expand Down
30 changes: 30 additions & 0 deletions cms/dashboard/templates/cms_starting_pages/landing_page.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"id": 79,
"meta": {
"search_description": "",
"type": "landing_page.LandingPage",
"detail_url": "https://http:/api/pages/79/",
"html_url": "https://http://localhost:3000/landing-page/",
"slug": "landing-page",
"show_in_menus": false,
"seo_title": "Home | UKHSA data dashboard",
"first_published_at": "2024-09-20T13:06:42.106160+01:00",
"alias_of": null,
"parent": {
"id": 3,
"meta": {
"type": "home.UKHSARootPage",
"detail_url": "https://http:/api/pages/3/",
"html_url": null
},
"title": "UKHSA Dashboard Root"
}
},
"title": "Landing page",
"sub_title": "showing public health data across England",
"body": "",
"last_published_at": "2024-09-20T14:04:30.332316+01:00",
"last_updated_at": "2024-09-24T16:40:55.228390+01:00",
"seo_change_frequency": 5,
"seo_priority": "0.5"
}
7 changes: 7 additions & 0 deletions cms/dynamic_content/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
use_json_field=True,
)

ALLOWABLE_BODY_CONTENT_SECTION_LINK = StreamField(
[
("section", sections.SectionWithLink()),
],
use_json_field=True,
)

ALLOWABLE_BODY_CONTENT_TEXT_SECTION = StreamField(
[
("section", sections.TextSection()),
Expand Down
9 changes: 9 additions & 0 deletions cms/dynamic_content/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,12 @@ def get_api_representation(cls, value, context=None) -> dict | None:
"geography_code": value.geography_code,
}
return None


class PageLinkChooserBlock(blocks.PageChooserBlock):
@classmethod
def get_api_representation(cls, value, context=None) -> str | None:
if value:
return value.full_url

return None
11 changes: 6 additions & 5 deletions cms/dynamic_content/cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from cms.dynamic_content.blocks import (
HeadlineNumberBlockTypes,
MetricNumberBlock,
PageLinkChooserBlock,
)
from cms.dynamic_content.components import (
ChartComponent,
Expand All @@ -21,7 +22,7 @@
MAXIMUM_HEADLINES_IN_CHART_CARD_COLUMN_COUNT: int = 2

MINIMUM_COLUMNS_CHART_COLUMNS_COUNT: int = 1
MAXIMUM_COLUMNS_CHART_COLUMNS_COUNT: int = 2
MAXIMUM_COLUMNS_CHART_COLUMNS_COUNT: int = 3

MAXIMUM_TOPIC_TREND_CARD_CHARTS: int = 1
MAXIMUM_TREND_NUMBER: int = 1
Expand All @@ -40,8 +41,8 @@ class Meta:


class WHAlerts(models.TextChoices):
HEAT = "Heat"
COLD = "Cold"
HEAT = "heat"
COLD = "cold"

@classmethod
def get_alerts(cls) -> tuple[tuple[str, str]]:
Expand Down Expand Up @@ -108,13 +109,13 @@ class Meta:

class SimplifiedChartWithLink(blocks.StructBlock):
title = blocks.TextBlock(required=True, help_text=help_texts.TITLE_FIELD)
body = blocks.TextBlock(required=False, help_text=help_texts.OPTIONAL_BODY_FIELD)
sub_title = blocks.CharBlock(required=False, help_text=help_texts.SUB_TITLE_FIELD)
tag_manager_event_id = blocks.CharBlock(
required=False,
help_text=help_texts.TAG_MANAGER_EVENT_ID_FIELD,
label="Tag manager event ID",
)
topic_page = blocks.PageChooserBlock(
topic_page = PageLinkChooserBlock(
page_type="topic.TopicPage",
required=True,
help_text=help_texts.TOPIC_PAGE_FIELD,
Expand Down
6 changes: 6 additions & 0 deletions cms/dynamic_content/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
get_chart_types,
get_colours,
get_headline_chart_types,
get_simplified_chart_types,
)

DEFAULT_GEOGRAPHY = "England"
Expand Down Expand Up @@ -151,3 +152,8 @@ class SimplifiedChartPlotElement(BaseMetricsElement):
choices=get_all_timeseries_metric_names,
help_text=help_texts.METRIC_FIELD,
)
chart_type = blocks.ChoiceBlock(
required=True,
choices=get_simplified_chart_types,
default=DEFAULT_SIMPLIFIED_CHART_TYPE,
)
6 changes: 5 additions & 1 deletion cms/dynamic_content/help_texts.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
"""

TOPIC_PAGE_FIELD: str = """
The related topic page you want to link to.
The related topic page you want to link to. Eg: `COVID-19`
"""

INDEX_PAGE_FIELD: str = """
The related index page you want to link to. Eg: `Respiratory viruses` or `Outbreaks`
"""

HEADLINE_BLOCK_FIELD: str = """
Expand Down
13 changes: 13 additions & 0 deletions cms/dynamic_content/sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ class Meta:
icon = "thumbtack"


class SectionWithLink(StructBlock):
heading = TextBlock(help_text=help_texts.HEADING_BLOCK, required=True)
page_link = blocks.PageLinkChooserBlock(
page_type=["composite.CompositePage"],
required=False,
help_text=help_texts.INDEX_PAGE_FIELD,
)
content = ContentCards(help_text=help_texts.CONTENT_ROW_CARDS)

class Meta:
icon = "thumbtack"


class TextSection(StructBlock):
title = TextBlock(help_text=help_texts.HEADING_BLOCK, required=True)
body = RichTextBlock(help_text=help_texts.REQUIRED_BODY_FIELD, required=True)
Expand Down
Empty file added cms/landing_page/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions cms/landing_page/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class LandingPageConfig(AppConfig):
default_auto_fields = "django.db.models.BigAutoField"
name = "cms.landing_page"
Loading

0 comments on commit cd63baa

Please sign in to comment.