Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/gh-version-updates…
Browse files Browse the repository at this point in the history
…-533f70582a
  • Loading branch information
MebinAbraham authored Feb 6, 2025
2 parents d5d2435 + 1e8125b commit 4994528
Show file tree
Hide file tree
Showing 27 changed files with 712 additions and 125 deletions.
6 changes: 4 additions & 2 deletions cms/core/blocks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
)
from .headline_figures import HeadlineFiguresBlock
from .markup import BasicTableBlock, HeadingBlock, QuoteBlock
from .panels import PanelBlock
from .panels import AnnouncementPanelBlock, InformationPanelBlock, WarningPanelBlock
from .related import LinkBlock, RelatedContentBlock, RelatedLinksBlock

__all__ = [
Expand All @@ -19,7 +19,9 @@
"ImageBlock",
"LinkBlock",
"ONSEmbedBlock",
"PanelBlock",
"WarningPanelBlock",
"InformationPanelBlock",
"AnnouncementPanelBlock",
"QuoteBlock",
"RelatedContentBlock",
"RelatedLinksBlock",
Expand Down
48 changes: 29 additions & 19 deletions cms/core/blocks/panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,37 @@
from wagtail import blocks


class PanelBlock(blocks.StructBlock):
"""DS Panel block.
https://service-manual.ons.gov.uk/design-system/components/panel
https://service-manual.ons.gov.uk/design-system/components/announcement-panel
https://service-manual.ons.gov.uk/design-system/components/success-panel
https://service-manual.ons.gov.uk/design-system/components/warning-panels.
class BasePanelBlock(blocks.StructBlock):
"""A reusable base panel block with a body field.
Subclasses can override Meta attributes (e.g., template, label)
and define additional fields as needed.
"""

variant = blocks.ChoiceBlock(
choices=[
("warn", _("Warning")),
("info", _("Information")),
("announcement", "Announcement"),
("error", "Error"),
("success", "Success"),
],
default="warn",
)
body = blocks.RichTextBlock(features=settings.RICH_TEXT_BASIC)
title = blocks.CharBlock(required=False, label=_("Title (optional)"))

class Meta:
label = _("Warning or information panel")
template = "templates/components/streamfield/panel_block.html"
abstract = True
group = _("Panels")


class WarningPanelBlock(BasePanelBlock):
class Meta:
template = "templates/components/streamfield/warning_panel.html"
icon = "warning"
label = _("Warning Panel")


class AnnouncementPanelBlock(BasePanelBlock):
class Meta:
template = "templates/components/streamfield/announcement_panel.html"
icon = "pick"
label = _("Announcement Panel")


class InformationPanelBlock(BasePanelBlock):
title = blocks.CharBlock(required=True, label=_("Title"))

class Meta:
template = "templates/components/streamfield/information_panel.html"
icon = "info-circle"
label = _("Information Panel")
8 changes: 6 additions & 2 deletions cms/core/blocks/section_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
from wagtailmath.blocks import MathBlock

from cms.core.blocks import (
AnnouncementPanelBlock,
DocumentsBlock,
HeadingBlock,
InformationPanelBlock,
ONSEmbedBlock,
PanelBlock,
QuoteBlock,
RelatedLinksBlock,
VideoEmbedBlock,
WarningPanelBlock,
)

if TYPE_CHECKING:
Expand All @@ -24,7 +26,9 @@ class SectionContentBlock(StreamBlock):

rich_text = RichTextBlock()
quote = QuoteBlock()
panel = PanelBlock()
warning_panel = WarningPanelBlock()
information_panel = InformationPanelBlock()
announcement_panel = AnnouncementPanelBlock()
image = ImageChooserBlock(group="Media")
documents = DocumentsBlock(group="Media")
video_embed = VideoEmbedBlock(group="Media")
Expand Down
8 changes: 6 additions & 2 deletions cms/core/blocks/stream_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
from wagtailmath.blocks import MathBlock

from cms.core.blocks import (
AnnouncementPanelBlock,
DocumentsBlock,
HeadingBlock,
InformationPanelBlock,
ONSEmbedBlock,
PanelBlock,
QuoteBlock,
RelatedLinksBlock,
VideoEmbedBlock,
WarningPanelBlock,
)
from cms.core.blocks.section_blocks import SectionBlock

Expand Down Expand Up @@ -42,7 +44,9 @@ class CoreStoryBlock(StreamBlock):
heading = HeadingBlock()
rich_text = RichTextBlock()
quote = QuoteBlock()
panel = PanelBlock()
warning_panel = WarningPanelBlock()
information_panel = InformationPanelBlock()
announcement_panel = AnnouncementPanelBlock()
video_embed = VideoEmbedBlock(group="Media")
image = ImageChooserBlock(group="Media")
documents = DocumentsBlock(group="Media")
Expand Down
23 changes: 17 additions & 6 deletions cms/core/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from wagtail.rich_text import RichText
from wagtail_factories.blocks import BlockFactory, PageChooserBlockFactory, StructBlockFactory

from cms.core.blocks.base import LinkBlock
from cms.core.blocks.related import LinkBlock, RelatedContentBlock
from cms.core.blocks.section_blocks import SectionBlock, SectionContentBlock
from cms.core.models import ContactDetails


Expand Down Expand Up @@ -54,12 +55,12 @@ class Meta:
email = factory.Faker("email")


# Section Block Factories


class SectionContentBlockFactory(wagtail_factories.StructBlockFactory):
class SectionContentBlockFactory(StructBlockFactory):
"""Factory for Section content block."""

class Meta:
model = SectionContentBlock

title = factory.Faker("text", max_nb_chars=50)
content = wagtail_factories.StreamFieldFactory(
{
Expand All @@ -68,9 +69,12 @@ class SectionContentBlockFactory(wagtail_factories.StructBlockFactory):
)


class SectionBlockFactory(wagtail_factories.StructBlockFactory):
class SectionBlockFactory(StructBlockFactory):
"""Factory for Section StructBlock."""

class Meta:
model = SectionBlock

title = factory.Faker("text", max_nb_chars=50)
content = factory.SubFactory(SectionContentBlockFactory)

Expand All @@ -87,3 +91,10 @@ class Meta:

class Params:
with_page = factory.Trait(page=factory.SubFactory(PageChooserBlockFactory), external_url=None)


class RelatedContentBlockFactory(LinkBlockFactory):
class Meta:
model = RelatedContentBlock

description = factory.Faker("text", max_nb_chars=20)
71 changes: 2 additions & 69 deletions cms/jinja2/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,73 +38,6 @@
{% set navigation_settings = settings.navigation.NavigationSettings %}
{% set main_menu = main_menu | default(navigation_settings.main_menu) %}

{% set keyLinksList = [] %}

{% if main_menu and main_menu.highlights %}
{% for highlight in main_menu.highlights %}
{% if highlight.value.page and highlight.value.page.live %}
{% set _ = keyLinksList.append({
'text': highlight.value.title if highlight.value.title else highlight.value.page.title,
'description': highlight.value.description,
'url': pageurl(highlight.value.page),
}) %}
{% elif highlight.value.external_url %}
{% set _ = keyLinksList.append({
'text': highlight.value.title,
'description': highlight.value.description,
'url': highlight.value.external_url,
}) %}
{% endif %}
{% endfor %}
{% endif %}

{% set itemsList = [] %}

{% if main_menu and main_menu.columns %}
{% for column in main_menu.columns %}
{% set columnData = {
'column': loop.index,
'linksList': []
} %}

{% for section in column.value.sections %}
{% if section.section_link.page and section.section_link.page.live %}
{% set sectionData = {
'text': section.section_link.title or section.section_link.page.title,
'url': pageurl(section.section_link.page),
'children': []
} %}
{% elif section.section_link.external_url %}
{% set sectionData = {
'text': section.section_link.title,
'url': section.section_link.external_url,
'children': []
} %}
{% endif %}

{% if sectionData %}
{% for link in section.links %}
{% if link.page and link.page.live%}
{% do sectionData.children.append({
'text': link.title or link.page.title,
'url': pageurl(link.page),
}) %}
{% elif link.external_url %}
{% do sectionData.children.append({
'text': link.title,
'url': link.external_url,
}) %}
{% endif %}
{% endfor %}
{% endif %}

{% do columnData.linksList.append(sectionData) %}
{% endfor %}

{% do itemsList.append(columnData) %}
{% endfor %}
{% endif %}

{% set pageConfig = {
"bodyClasses": body_class,
"title": page_title,
Expand All @@ -125,8 +58,8 @@
"text": 'Menu',
"ariaLabel": 'Toggle main menu'
},
"keyLinksList": keyLinksList,
"itemsList": itemsList
"keyLinksList": main_menu_highlights(main_menu),
"itemsList": main_menu_columns(main_menu)
}
},
"footer": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% from "components/panel/_macro.njk" import onsPanel %}

{# fmt:off #}
{{-
onsPanel({
"variant": "announcement",
"body": value.body
})
-}}
{# fmt:on #}
11 changes: 11 additions & 0 deletions cms/jinja2/templates/components/streamfield/information_panel.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% from "components/panel/_macro.njk" import onsPanel %}

{# fmt:off #}
{{-
onsPanel({
"variant": "info",
"body": value.body,
"title": value.title
})
-}}
{# fmt:on #}
7 changes: 0 additions & 7 deletions cms/jinja2/templates/components/streamfield/panel_block.html

This file was deleted.

10 changes: 10 additions & 0 deletions cms/jinja2/templates/components/streamfield/warning_panel.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% from "components/panel/_macro.njk" import onsPanel %}

{# fmt:off #}
{{-
onsPanel({
"variant": "warn",
"body": value.body
})
-}}
{# fmt:off #}
34 changes: 34 additions & 0 deletions cms/jinja2/templates/pages/index_page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{% extends "templates/base_page.html" %}
{% from "components/document-list/_macro.njk" import onsDocumentList %}
{% from "components/related-content/_macro.njk" import onsRelatedContent %}

{% block main %}

{% if page.summary %}
<p>{{ page.summary|richtext }}</p>
{% endif %}

{% if formatted_items %}
{{ onsDocumentList({"documents": formatted_items}) }}
{% endif %}

{% if page.content %}
{% include_block page.content|richtext %}
{% endif %}

{% if related_links_list %}
{# fmt:off #}
{{
onsRelatedContent({
"ariaLabel": _('Related links'),
"rows": [{
"id": 'related-content',
"title": _('Related links'),
"itemsList": related_links_list
}]
})
}}
{# fmt:on #}
{% endif %}

{% endblock %}
2 changes: 1 addition & 1 deletion cms/jinja2/templates/pages/information_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% from "components/related-content/_macro.njk" import onsRelatedContent %}

{% block main %}
<p>{{ page.summary }}</p>
<p>{{ page.summary|richtext }}</p>

{% if page.last_updated %}
<h5>{{ _("Last Updated") }}: {{ page.last_updated }}</h5>
Expand Down
2 changes: 1 addition & 1 deletion cms/jinja2/templates/pages/methodology_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ <h1 class="ons-u-fs-3xl common-header__heading">
{% endblock %}

{% block main %}
<div class="ons-grid ons-grid-flex-gap ons-grid-flex-gap--32">
<div class="ons-grid ons-grid-flex-gap ons-grid-flex-gap--32 ons-js-toc-container">
<div class="ons-grid__col ons-grid__col--sticky@m ons-col-4@m">
{% with toc_title=_("Contents"), toc_aria_label=_("Sections in this page") %}
{# fmt:off #}
Expand Down
2 changes: 1 addition & 1 deletion cms/jinja2/templates/pages/statistical_article_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ <h1 class="ons-u-fs-3xl common-header__heading">
{% endblock %}

{% block main %}
<div class="ons-grid ons-grid-flex-gap ons-grid-flex-gap--32">
<div class="ons-grid ons-grid-flex-gap ons-grid-flex-gap--32 ons-js-toc-container">
<div class="ons-grid__col ons-grid__col--sticky@m ons-col-4@m">
{% with toc_title=_("Contents"), toc_aria_label=_("Sections in this page") %}
{# fmt:off #}
Expand Down
6 changes: 3 additions & 3 deletions cms/methodology/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ def get_context(self, request: HttpRequest, *args: Any, **kwargs: Any) -> dict:

@cached_property
def related_publications(self) -> "PageQuerySet":
"""Return a `PageQuerySet` of items related to this page via the
`PageRelatedPage` through model, and are suitable for display.
"""Return a `PageQuerySet` of the StatisticalArticlePage page model via the
`MethodologyRelatedPage` through model, which is suitable for display.
The result is ordered to match that specified by editors using
the 'page_related_pages' `InlinePanel`.
"""
Expand All @@ -116,7 +116,7 @@ def related_publications(self) -> "PageQuerySet":
)

def get_formatted_related_publications_list(self, request: HttpRequest | None = None) -> list[dict[str, str]]:
"""Returns a formatted list of related publications for use with the Design System list component."""
"""Returns a formatted list of related internal pages for use with the Design System list component."""
items = []
for page in self.related_publications:
items.append(
Expand Down
Loading

0 comments on commit 4994528

Please sign in to comment.