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

Try out the statistical article hero wtih the hero component from the design system #91

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
92 changes: 92 additions & 0 deletions cms/jinja2/templates/pages/statistical_article_page.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,101 @@
{% extends "templates/base_page.html" %}

{% from "components/hero/_macro.njk" import onsHero %}
{% from "components/panel/_macro.njk" import onsPanel %}
{% from "components/table-of-contents/_macro.njk" import onsTableOfContents %}

{% block header_area %}
{# Currently missing email link as the onsDescriptionList does not allow markup #}
{% if page.contact_details %}
{# fmt:off #}
{% set contact_details =
{
"term": "Contact:",
"descriptions": [
{
"description": page.contact_details.name
}
]
}
%}
{# fmt:on #}
{% else %}
{% set contact_details = "" %}
{% endif %}
{% if page.is_census %}
{% import "templates/components/census/census-logo.html" as census_logo %}
{% set census_html = ['<div class="ons-container">'|safe, census_logo] | join %}
{% set census_html = [census_html, "</div>"|safe] | join %}
{% else %}
{% set census_html = "" %}
{% endif %}
Comment on lines +25 to +31
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could do something like:

{% set census_html -%}
    {% if page.is_census %}
        <div class="ons-container">{% import "templates/components/census/census-logo.html"</div>
    {% endif %}
{%- endset %}

which should be much cleaner, IMHO

{# Currently missing links as the onsDescriptionList does not allow markup #}
{% if page.is_latest %}
{% set releases_text = _("View previous releases") %}
{% else %}
{% set releases_text = _("View latest release") %}
{% endif %}
{% set next_release_date_text = page.next_release_date|date("DATE_FORMAT") or _("To be announced") %}
{# fmt:off #}
{{
onsHero({
"topic": _("Statistical article"),
"title": page.display_title,
"variants": 'grey',
"text": page.summary,
"officialStatisticsBadge": page.is_accredited,
"wide": true,
"detailsColumns": 12,
"html": census_html,
"descriptionList": {

"descriptionListLabel": "",
"termCol": "6",
"descriptionCol": "6",
"itemsList": [
{
"term": _("Release date"),
"descriptions": [
{
"description": page.release_date|date("DATE_FORMAT")
}
]
},
{
"term": _("Edition"),
"descriptions": [
{
"description": _("Latest")
}
]
},
contact_details,
{
"term": _("Next release"),
"descriptions": [
{
"description": next_release_date_text
}
]
},
{
"term": _("Releases"),
"descriptions": [
{
"description": releases_text
}
]
},
]
},
"breadcrumbs":
{
"ariaLabel": 'Breadcrumbs',
"itemsList": breadcrumbs(page),
}
})
}}
{# fmt:on #}
<div class="common-header article-header {% if page.updates %}article-header--flush{% endif %}">
<div class="ons-container">
{% include "templates/components/navigation/breadcrumbs.html" %}
Expand Down
17 changes: 17 additions & 0 deletions cms/navigation/jinja2tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from typing import TYPE_CHECKING

from jinja2.ext import Extension

from cms.navigation.templatetags.navigation_tags import breadcrumbs

if TYPE_CHECKING:
from jinja2 import Environment


class NavigationExtension(Extension): # pylint: disable=abstract-method
"""Extends Jinja templates with what's needed to render the navigation and breadcrumbs."""

def __init__(self, environment: "Environment"):
super().__init__(environment)

self.environment.globals.update({"breadcrumbs": breadcrumbs})
24 changes: 24 additions & 0 deletions cms/navigation/templatetags/navigation_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from typing import TYPE_CHECKING

import jinja2
from django.utils.translation import gettext_lazy as _

if TYPE_CHECKING:
from wagtail.models import Page


# Breadcrumbs
@jinja2.pass_context
def breadcrumbs(context: jinja2.runtime.Context, page: "Page") -> list[dict[str, object]]:
"""Returns the breadcrumbs as a list of dictionaries for the given page."""
breadcrumbs_list = []
page_depth = 2
for ancestor_page in page.get_ancestors().specific().defer_streamfields():
if not ancestor_page.is_root():
if ancestor_page.depth <= page_depth:
Comment on lines +15 to +18
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
page_depth = 2
for ancestor_page in page.get_ancestors().specific().defer_streamfields():
if not ancestor_page.is_root():
if ancestor_page.depth <= page_depth:
for ancestor_page in page.get_ancestors().specific().defer_streamfields():
if not ancestor_page.is_root():
# Root has depth 1, Homepage 2
if ancestor_page.depth <= 2:

breadcrumbs_list.append({"url": "/", "text": _("Home")})
elif not getattr(ancestor_page, "exclude_from_breadcrumbs", False):
breadcrumbs_list.append(
{"url": ancestor_page.get_url(request=context.get("request")), "text": ancestor_page.title}
)
return breadcrumbs_list
1 change: 1 addition & 0 deletions cms/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
"wagtail.images.jinja2tags.images",
"wagtail.contrib.settings.jinja2tags.settings",
"cms.core.jinja2tags.CoreExtension",
"cms.navigation.jinja2tags.NavigationExtension",
],
},
},
Expand Down
Loading