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

Methodology page #57

Merged
merged 30 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ed52cc9
Refactorig to make the Section block reusable between apps
kacperpONS Dec 10, 2024
e4aaf3d
Page model, page HTML and a few TODOs
kacperpONS Dec 10, 2024
430e236
Merge branch 'main' into methodology-page-CMS-200
kacperpONS Dec 10, 2024
74f5448
Renamed to SectionStoryBlock and moved to stream_blocks.py
kacperpONS Dec 10, 2024
5650515
Renamed Related content to Related publications in the template
kacperpONS Dec 11, 2024
54c647f
Added index for search
kacperpONS Dec 11, 2024
e4e6893
Removed the methodology_summary field - future requirement when in DS
kacperpONS Dec 11, 2024
3f6c6cc
Restrict to only allow Methodology under Topic page
kacperpONS Dec 11, 2024
584191b
Added tests, date validation and minor fixes
kacperpONS Dec 11, 2024
0d6c077
Added migration file
kacperpONS Dec 11, 2024
fc9b1ac
Formatting
kacperpONS Dec 11, 2024
bc5136f
Extract methodology into its own app
kacperpONS Dec 11, 2024
7bad8a3
Rename published_date to publication_date
kacperpONS Dec 11, 2024
2ce7a72
Section blocks - changed the fields order, moved block_counts + forma…
kacperpONS Dec 11, 2024
1ea7ed1
A bunch of small fixes
kacperpONS Dec 11, 2024
f21fbdd
Put the date panels in a FieldRowPanel
kacperpONS Dec 11, 2024
96e07a6
Make CoreStoryBlock and SectionStoryBlock separate again
kacperpONS Dec 12, 2024
13211ed
Added test for external env (+formatting)
kacperpONS Dec 12, 2024
62ddaf1
Wrapped Last revised date in a conditional in the template
kacperpONS Dec 17, 2024
539a1d3
Move Section Block Factories to the core app's tests
kacperpONS Dec 17, 2024
5690c11
Formatted the date input panels code (+ removed the redundant FieldPa…
kacperpONS Dec 18, 2024
4109c3b
Merge branch 'main' into methodology-page-CMS-200
kacperpONS Dec 18, 2024
ff99288
Merge branch 'main' into methodology-page-CMS-200
zerolab Jan 8, 2025
2141b87
Tidy up tests
zerolab Jan 8, 2025
028d806
Make related publications specific to Methodology page and limited to…
zerolab Jan 8, 2025
a498b4d
Minor tidy ups
zerolab Jan 8, 2025
5b58b6e
Merge branch 'main' into methodology-page-CMS-200
zerolab Jan 8, 2025
765705e
Update the methodology page template post #55
zerolab Jan 8, 2025
ac4bed3
Tidy up the related publications output
zerolab Jan 9, 2025
8a96fd0
Merge branch 'main' into methodology-page-CMS-200
zerolab Jan 9, 2025
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
6 changes: 3 additions & 3 deletions cms/analysis/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
from wagtail.models import Page
from wagtail.search import index

from cms.analysis.blocks import AnalysisStoryBlock
from cms.bundles.models import BundledPageMixin
from cms.core.blocks import HeadlineFiguresBlock
from cms.core.blocks.stream_blocks import SectionStoryBlock
from cms.core.fields import StreamField
from cms.core.models import BasePage

Expand Down Expand Up @@ -120,7 +120,7 @@ class AnalysisPage(BundledPageMixin, BasePage): # type: ignore[django-manager-m

# Fields: content
headline_figures = StreamField([("figures", HeadlineFiguresBlock())], blank=True, max_num=1)
content = StreamField(AnalysisStoryBlock())
content = StreamField(SectionStoryBlock())

show_cite_this_page = models.BooleanField(default=True)

Expand All @@ -144,7 +144,7 @@ class AnalysisPage(BundledPageMixin, BasePage): # type: ignore[django-manager-m
FieldPanel("summary"),
MultiFieldPanel(
[
FieldPanel("release_date", icon="calendar-alt"),
FieldPanel("release_date"),
FieldPanel(
"next_release_date",
help_text=_("If no next date is chosen, 'To be announced' will be displayed."),
Expand Down
18 changes: 4 additions & 14 deletions cms/analysis/blocks.py → cms/core/blocks/section_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
ONSEmbedBlock,
PanelBlock,
QuoteBlock,
RelatedContentBlock,
RelatedLinksBlock,
)

Expand All @@ -21,7 +20,7 @@


class SectionContentBlock(StreamBlock):
"""The analysis section content StreamField block definition."""
"""The core section content block definition."""

rich_text = RichTextBlock()
quote = QuoteBlock()
Expand All @@ -31,15 +30,15 @@ class SectionContentBlock(StreamBlock):
embed = EmbedBlock(group="Media")
equation = MathBlock(group="DataVis", icon="decimal")
ons_embed = ONSEmbedBlock(group="DataVis", label="ONS General Embed")
related_links = RelatedLinksBlock(RelatedContentBlock(), icon="link")
related_links = RelatedLinksBlock(icon="link")

class Meta:
template = "templates/components/streamfield/stream_block.html"
block_counts: ClassVar[dict[str, dict]] = {"related_links": {"max_num": 1}}


class SectionBlock(StructBlock):
"""The analysis section block definition."""
"""The core section block definition with headers."""

title = HeadingBlock()
content = SectionContentBlock()
Expand All @@ -49,13 +48,4 @@ def to_table_of_contents_items(self, value: "StructValue") -> list[dict[str, str
return [{"url": "#" + slugify(value["title"]), "text": value["title"]}]

class Meta:
template = "templates/components/streamfield/analysis_section_block.html"


class AnalysisStoryBlock(StreamBlock):
"""The analysis StreamField block definition."""

section = SectionBlock()

class Meta:
template = "templates/components/streamfield/stream_block.html"
template = "templates/components/streamfield/section_block.html"
16 changes: 13 additions & 3 deletions cms/core/blocks/stream_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
QuoteBlock,
RelatedLinksBlock,
)
from cms.core.blocks.section_blocks import SectionBlock


class SectionStoryBlock(StreamBlock):
"""The core section StreamField block definition."""

section = SectionBlock()

class Meta:
template = "templates/components/streamfield/stream_block.html"


class CoreStoryBlock(StreamBlock):
zerolab marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -22,9 +32,9 @@ class CoreStoryBlock(StreamBlock):
rich_text = RichTextBlock()
quote = QuoteBlock()
panel = PanelBlock()
embed = EmbedBlock()
image = ImageChooserBlock()
documents = DocumentsBlock()
embed = EmbedBlock(group="Media")
image = ImageChooserBlock(group="Media")
documents = DocumentsBlock(group="Media")
related_links = RelatedLinksBlock()
equation = MathBlock(group="DataVis", icon="decimal")
ons_embed = ONSEmbedBlock(group="DataVis", label="ONS General Embed")
Expand Down
22 changes: 22 additions & 0 deletions cms/core/tests/factories.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import factory
import wagtail_factories
from wagtail import blocks
from wagtail.rich_text import RichText
from wagtail_factories.blocks import BlockFactory
Expand Down Expand Up @@ -50,3 +51,24 @@ class Meta:

name = factory.Faker("name")
email = factory.Faker("email")


# Section Block Factories


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

title = factory.Faker("text", max_nb_chars=50)
content = wagtail_factories.StreamFieldFactory(
{
"rich_text": factory.SubFactory(RichTextBlockFactory),
}
)


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

title = factory.Faker("text", max_nb_chars=50)
content = factory.SubFactory(SectionContentBlockFactory)
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ <h2 class="ons-u-fs-l">{{ value.title }}</h2>

{% include_block value.content %}
</section>

103 changes: 103 additions & 0 deletions cms/jinja2/templates/pages/methodology_page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{% extends "templates/base_page.html" %}

{% from "components/table-of-contents/_macro.njk" import onsTableOfContents %}
{% from "components/list/_macro.njk" import onsList %}

{% block header_area %}
<div class="common-header analysis-header {% if page.updates %}analysis-header--flush{% endif %}">
<div class="ons-container">
{% include "templates/components/navigation/breadcrumbs.html" %}
<p class="analysis-header__doc-type ons-u-fs-l">{{ _("Methodology") }}</p>

<div class="ons-grid ons-grid-flex-gap ons-grid-flex-gap--40">
<div class="ons-grid__col ons-col-10@m ">
<h1 class="ons-u-fs-3xl common-header__heading">
{{ page.title }}
</h1>

<div class="common-header__summary">{{ page.summary|richtext() }}</div>
</div>
</div>
</div>

{% block release_meta %}
<div class="ons-container common-header__releases">
<div>
<span class="ons-u-fs-r--b common-header__releases-label">{{ _("Published") }}:</span>
<span class="ons-u-nowrap">{{ page.publication_date|date("DATE_FORMAT") }}</span>
</div>
{% if page.last_revised_date %}
<div>
<span class="ons-u-fs-r--b common-header__releases-label">{{ _("Last revised") }}:</span>
<span class="ons-u-nowrap">{{ page.last_revised_date|date("DATE_FORMAT")}}</span>
</div>
{% endif %}

{% if page.contact_details %}
<div>
<span class="ons-u-fs-r--b common-header__releases-label">{{ _("Contact") }}:</span>
<a href="mailto:{{ page.contact_details.email }}">{{ page.contact_details.name }}</a>
</div>
{% endif %}
</div>
{% endblock %}
</div>
{% endblock %}

{% block main %}
<div class="ons-grid ons-grid-flex-gap ons-grid-flex-gap--32">
<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 #}
{{-
onsTableOfContents({
"title": toc_title,
"ariaLabel": toc_aria_label,
"itemsList": table_of_contents
})
}}
{# fmt:on #}
{% endwith %}
</div>

<div class="ons-grid__col ons-col-8@m">
{# if there are no contact details on the page, we don't want the last
streamfield block to have a bottom margin. last_flush is used in stream_block.html #}
{% if page.contact_details %}
{% set last_flush = False %}
{% else %}
{% set last_flush = True %}
{% endif %}

{% include_block page.content %}

{% if related_publications %}
<section id="related-publications" class="spacing">
<h2 class="ons-u-fs-l">{{ _("Related publications") }}</h2>
{{- onsList({"itemsList": related_publications}) -}}
</section>
{% endif %}

{% if page.show_cite_this_page %}
<section id="cite-this-page" class="spacing">
<h2 class="ons-u-fs-l">{{ _("Cite this methodology") }}</h2>
<p>
{%- set cite_link -%}
<a href="{{ fullpageurl(page) }}">{{ page.title }}</a>
{% endset %}
{% set latest_date = page.last_revised_date if page.last_revised_date else page.publication_date %}
{% trans trimmed latest_date_formatted = latest_date|date("DATE_FORMAT"), cite_link=cite_link %}
Office for National Statistics (ONS), last revised {{ latest_date_formatted }}, ONS website, methodology, {{ cite_link }}
{% endtrans %}
</p>
</section>
{% endif %}

{% if page.contact_details %}
{% with contact_details = page.contact_details%}
{% include "templates/components/contact_details/contact_details.html" %}
{% endwith %}
{% endif %}
</div>
</div>
{% endblock %}
Empty file added cms/methodology/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions cms/methodology/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class MethodologyConfig(AppConfig):
default_auto_field = "django.db.models.AutoField"
name = "cms.methodology"
104 changes: 104 additions & 0 deletions cms/methodology/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Generated by Django 5.1.4 on 2025-01-08 12:42

import django.db.models.deletion
import modelcluster.fields
import wagtail.fields
from django.db import migrations, models

import cms.core.fields


class Migration(migrations.Migration):
initial = True

dependencies = [
("core", "0004_contactdetails_core_contactdetails_name_unique"),
("images", "0002_customimage_description"),
("wagtailcore", "0094_alter_page_locale"),
]

operations = [
migrations.CreateModel(
name="MethodologyPage",
fields=[
(
"page_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="wagtailcore.page",
),
),
("listing_title", models.CharField(blank=True, max_length=255)),
("listing_summary", models.CharField(blank=True, max_length=255)),
("social_text", models.CharField(blank=True, max_length=255)),
("summary", wagtail.fields.RichTextField()),
("publication_date", models.DateField()),
("last_revised_date", models.DateField(blank=True, null=True)),
("content", cms.core.fields.StreamField(block_lookup={})),
("show_cite_this_page", models.BooleanField(default=True)),
(
"contact_details",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to="core.contactdetails",
),
),
(
"listing_image",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to="images.customimage",
),
),
(
"social_image",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to="images.customimage",
),
),
],
options={
"abstract": False,
},
bases=("wagtailcore.page", models.Model),
),
migrations.CreateModel(
name="MethodologyRelatedPage",
fields=[
("id", models.AutoField(auto_created=True, primary_key=True, serialize=False)),
("sort_order", models.IntegerField(blank=True, editable=False, null=True)),
(
"page",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, related_name="+", to="wagtailcore.page"
),
),
(
"parent",
modelcluster.fields.ParentalKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="related_pages",
to="methodology.methodologypage",
),
),
],
options={
"ordering": ["sort_order"],
"abstract": False,
},
),
]
Empty file.
Loading
Loading