Skip to content

Commit daacfdb

Browse files
♿️ DP193 Create consistent page titles (#281)
* Implement consistent page titles * update tests * make h1 and h2 sizings smaller * move description to a h3 tag and add back in item name test --------- Co-authored-by: Tom Webber <80110358+tom-webber@users.noreply.github.com>
1 parent 97030f8 commit daacfdb

19 files changed

+156
-113
lines changed

core/settings.py

+3
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,6 @@
134134
"NAME": ":memory:",
135135
}
136136
}
137+
# Define a service name setting for page titles
138+
SERVICE_NAME = "Find MOJ Data"
139+
GOV_UK_SUFFIX = "GOV.UK"

home/service/details.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def _get_context(self):
4747
"result": self.result,
4848
"result_type": "Data product",
4949
"tables": self.assets_in_data_product,
50-
"page_title": f"{self.result.name} - Data catalogue",
50+
"h1_value": "Details",
5151
}
5252

5353
return context
@@ -95,7 +95,7 @@ def _get_context(self):
9595
"result": self.result,
9696
"result_type": "Database",
9797
"tables": self.entities_in_database,
98-
"page_title": f"{self.result.name} - Data catalogue",
98+
"h1_value": "Details",
9999
}
100100

101101
return context
@@ -138,6 +138,7 @@ def _get_context(self):
138138
"table": self.table_metadata,
139139
"parent_entity": self.parent_entity,
140140
"dataset_parent_type": self.dataset_parent_type,
141+
"h1_value": "Details",
141142
}
142143

143144

@@ -148,4 +149,7 @@ def __init__(self, urn: str):
148149
self.context = self._get_context()
149150

150151
def _get_context(self):
151-
return {"chart": self.chart_metadata}
152+
return {
153+
"chart": self.chart_metadata,
154+
"h1_value": "Details",
155+
}

home/service/glossary.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ def grouper(result):
5656
else:
5757
parent_term["description"] = ""
5858

59-
context = {"results": sorted_total_results}
59+
context = {"results": sorted_total_results, "h1_value": "Glossary"}
6060

6161
return context

home/service/search.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,12 @@ def _generate_domain_clear_href(
156156
}
157157

158158
def _get_context(self) -> dict[str, Any]:
159-
if self.form["query"].value():
160-
page_title = f'Search for "{self.form["query"].value()}" - Data catalogue'
161-
else:
162-
page_title = "Search - Data catalogue"
163159

164160
context = {
165161
"form": self.form,
166162
"results": self.results.page_results,
167163
"highlighted_results": self.highlighted_results.page_results,
168-
"page_title": page_title,
164+
"h1_value": "Search",
169165
"page_obj": self.paginator.get_page(self.page),
170166
"page_range": self.paginator.get_elided_page_range(
171167
self.page, on_each_side=2, on_ends=1

home/templatetags/page_title.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from django import template
2+
from django.conf import settings
3+
4+
register = template.Library()
5+
6+
7+
@register.filter
8+
def render_title(h1_value: str) -> str:
9+
"""Renders a compliant page title for based on the h1 value,
10+
service name and gov uk suffix."""
11+
return f"{h1_value} - {settings.SERVICE_NAME} - {settings.GOV_UK_SUFFIX}"

home/views.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44

55
from home.forms.search import SearchForm
66
from home.service.details import (
7+
ChartDetailsService,
8+
DatabaseDetailsService,
79
DataProductDetailsService,
810
DatasetDetailsService,
9-
DatabaseDetailsService,
10-
ChartDetailsService,
1111
)
1212
from home.service.glossary import GlossaryService
1313
from home.service.search import SearchService
1414

1515

1616
def home_view(request):
1717
context = {}
18+
context["h1_value"] = "Home"
1819
return render(request, "home.html", context)
1920

2021

@@ -26,7 +27,7 @@ def details_view(request, result_type, id):
2627
context = dataset_details(id)
2728
return render(request, "details_table.html", context)
2829
if result_type == "database":
29-
context = database_details(request, id)
30+
context = database_details(id)
3031
return render(request, "details_database.html", context)
3132
if result_type == "chart":
3233
context = chart_details(id)
@@ -44,7 +45,7 @@ def data_product_details(id):
4445
return context
4546

4647

47-
def database_details(request, id):
48+
def database_details(id):
4849
try:
4950
service = DatabaseDetailsService(id)
5051
except ObjectDoesNotExist:

templates/base/head.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{% load static %}
2+
{% load page_title %}
23
<head>
34
<meta charset="utf-8">
4-
<title>{{page_title|default:"Data catalogue"}}</title>
5+
<title>{{h1_value|render_title}}</title>
56
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
67
<meta name="theme-color" content="blue">
78
<link rel="icon" sizes="48x48" href="{% static 'assets/images/favicon.ico' %}">

templates/details_chart.html

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,17 @@
2020

2121
<div class="govuk-grid-row">
2222
<div class="govuk-grid-column-full">
23+
<h1 class="govuk-heading-l">{{h1_value}}</h1>
2324
<span class="govuk-caption-m">Chart</span>
24-
<h2 class="govuk-heading-l">{{chart.name}}</h2>
25+
<h2 class="govuk-heading-m">{{chart.name}}</h2>
2526
</div>
2627
</div>
2728
<div class="govuk-grid-row">
2829
<div class="govuk-grid-column-two-thirds">
2930
<div class="summary-card">
30-
<h2 class="govuk-heading-s govuk-!-margin-top-3">
31+
<h3 class="govuk-heading-s govuk-!-margin-top-3">
3132
Description
32-
</h2>
33+
</h3>
3334
<div class="govuk-body">
3435
{{chart.description|markdown:3}}
3536
</div>

templates/details_data_product.html

+33-32
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@
1919
{% block content %}
2020
<div class="govuk-grid-row">
2121
<div class="govuk-grid-column-full">
22+
<h1 class="govuk-heading-l">{{h1_value}}</h1>
2223
<span class="govuk-caption-m">Data product</span>
23-
<h1 class="govuk-heading-l">{{result.name}}</h1>
24+
<h2 class="govuk-heading-m">{{result.name}}</h2>
2425
</div>
2526
<div class="govuk-grid-row">
2627
<div class="govuk-grid-column-two-thirds">
2728
<div class="summary-card">
28-
<h2 class="govuk-heading-s govuk-!-margin-top-3">
29+
<h3 class="govuk-heading-s govuk-!-margin-top-3">
2930
Description
30-
</h2>
31+
</h3>
3132
<div class="govuk-body">
3233
{{result.description|markdown:3}}
3334
</div>
@@ -71,36 +72,36 @@ <h2 class="govuk-heading-s govuk-!-margin-top-3">
7172
<div class="govuk-grid-row">
7273
<div class="govuk-grid-column-full">
7374
{% if tables %}
74-
<table class="govuk-table">
75-
<caption class="govuk-table__caption govuk-table__caption--m">Data product content</caption>
76-
<thead class="govuk-table__head">
77-
<tr class="govuk-table__row">
78-
<th scope="col" class="govuk-table__header app-custom-class">Table name</th>
79-
<th scope="col" class="govuk-table__header app-custom-class">Description</th>
80-
<th scope="col" class="govuk-table__header app-custom-class">Schema details</th>
81-
</tr>
82-
</thead>
83-
<tbody class="govuk-table__body">
84-
{% for table in tables %}
85-
{% with table_type=table.type|lower %}
86-
<tr class="govuk-table__row">
87-
<td class="govuk-table__cell">{{table.name}}</td>
88-
<td class="govuk-table__cell">
89-
{% if table.description|length > 200 %}
90-
{{ table.description|slice:":200"|add:"..."|markdown:3 }}
91-
{% else %}
92-
{{ table.description|markdown:3 }}
93-
{% endif %}
94-
</td>
95-
<td class="govuk-table__cell"> <a href="{% url 'home:details' result_type=table_type id=table.urn %}" class="govuk-link">Table details</a></td>
96-
</tr>
97-
{% endwith %}
98-
{% endfor %}
99-
</tbody>
100-
</table>
75+
<table class="govuk-table">
76+
<caption class="govuk-table__caption govuk-table__caption--m">Data product content</caption>
77+
<thead class="govuk-table__head">
78+
<tr class="govuk-table__row">
79+
<th scope="col" class="govuk-table__header app-custom-class">Table name</th>
80+
<th scope="col" class="govuk-table__header app-custom-class">Description</th>
81+
<th scope="col" class="govuk-table__header app-custom-class">Schema details</th>
82+
</tr>
83+
</thead>
84+
<tbody class="govuk-table__body">
85+
{% for table in tables %}
86+
{% with table_type=table.type|lower %}
87+
<tr class="govuk-table__row">
88+
<td class="govuk-table__cell">{{table.name}}</td>
89+
<td class="govuk-table__cell">
90+
{% if table.description|length > 200 %}
91+
{{ table.description|slice:":200"|add:"..."|markdown:3 }}
92+
{% else %}
93+
{{ table.description|markdown:3 }}
94+
{% endif %}
95+
</td>
96+
<td class="govuk-table__cell"> <a href="{% url 'home:details' result_type=table_type id=table.urn %}" class="govuk-link">Table details</a></td>
97+
</tr>
98+
{% endwith %}
99+
{% endfor %}
100+
</tbody>
101+
</table>
101102
{% else %}
102-
<h2 class="govuk-heading-m">Data product content</h2>
103-
<p class="govuk-body">This data product is missing table information.</p>
103+
<h2 class="govuk-heading-m">Data product content</h2>
104+
<p class="govuk-body">This data product is missing table information.</p>
104105
{% endif %}
105106
</div>
106107
</div>

templates/details_database.html

+33-32
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@
1919
{% block content %}
2020
<div class="govuk-grid-row">
2121
<div class="govuk-grid-column-full">
22+
<h1 class="govuk-heading-l">{{h1_value}}</h1>
2223
<span class="govuk-caption-m">Database</span>
23-
<h1 class="govuk-heading-l">{{result.name}}</h1>
24+
<h2 class="govuk-heading-m">{{result.name}}</h2>
2425
</div>
2526
<div class="govuk-grid-row">
2627
<div class="govuk-grid-column-two-thirds">
2728
<div class="summary-card">
28-
<h2 class="govuk-heading-s govuk-!-margin-top-3">
29+
<h3 class="govuk-heading-s govuk-!-margin-top-3">
2930
Description
30-
</h2>
31+
</h3>
3132
<div class="govuk-body">
3233
{{result.description|markdown:3}}
3334
</div>
@@ -71,36 +72,36 @@ <h2 class="govuk-heading-s govuk-!-margin-top-3">
7172
<div class="govuk-grid-row">
7273
<div class="govuk-grid-column-full">
7374
{% if tables %}
74-
<table class="govuk-table">
75-
<caption class="govuk-table__caption govuk-table__caption--m">Database content</caption>
76-
<thead class="govuk-table__head">
77-
<tr class="govuk-table__row">
78-
<th scope="col" class="govuk-table__header app-custom-class">Table name</th>
79-
<th scope="col" class="govuk-table__header app-custom-class">Description</th>
80-
<th scope="col" class="govuk-table__header app-custom-class">Schema details</th>
81-
</tr>
82-
</thead>
83-
<tbody class="govuk-table__body">
84-
{% for table in tables %}
85-
{% with table_type=table.type|lower %}
86-
<tr class="govuk-table__row">
87-
<td class="govuk-table__cell">{{table.name}}</td>
88-
<td class="govuk-table__cell">
89-
{% if table.description|length > 200 %}
90-
{{ table.description|slice:":200"|add:"..."|markdown:3 }}
91-
{% else %}
92-
{{ table.description|markdown:3 }}
93-
{% endif %}
94-
</td>
95-
<td class="govuk-table__cell"> <a href="{% url 'home:details' result_type=table_type id=table.urn %}" class="govuk-link">Table details</a></td>
96-
</tr>
97-
{% endwith %}
98-
{% endfor %}
99-
</tbody>
100-
</table>
75+
<table class="govuk-table">
76+
<caption class="govuk-table__caption govuk-table__caption--m">Database content</caption>
77+
<thead class="govuk-table__head">
78+
<tr class="govuk-table__row">
79+
<th scope="col" class="govuk-table__header app-custom-class">Table name</th>
80+
<th scope="col" class="govuk-table__header app-custom-class">Description</th>
81+
<th scope="col" class="govuk-table__header app-custom-class">Schema details</th>
82+
</tr>
83+
</thead>
84+
<tbody class="govuk-table__body">
85+
{% for table in tables %}
86+
{% with table_type=table.type|lower %}
87+
<tr class="govuk-table__row">
88+
<td class="govuk-table__cell">{{table.name}}</td>
89+
<td class="govuk-table__cell">
90+
{% if table.description|length > 200 %}
91+
{{ table.description|slice:":200"|add:"..."|markdown:3 }}
92+
{% else %}
93+
{{ table.description|markdown:3 }}
94+
{% endif %}
95+
</td>
96+
<td class="govuk-table__cell"> <a href="{% url 'home:details' result_type=table_type id=table.urn %}" class="govuk-link">Table details</a></td>
97+
</tr>
98+
{% endwith %}
99+
{% endfor %}
100+
</tbody>
101+
</table>
101102
{% else %}
102-
<h2 class="govuk-heading-m">Database content</h2>
103-
<p class="govuk-body">This database is missing table information.</p>
103+
<h2 class="govuk-heading-m">Database content</h2>
104+
<p class="govuk-body">This database is missing table information.</p>
104105
{% endif %}
105106
</div>
106107
</div>

templates/details_table.html

+4-3
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,17 @@
2525

2626
<div class="govuk-grid-row">
2727
<div class="govuk-grid-column-full">
28+
<h1 class="govuk-heading-l">{{h1_value}}</h1>
2829
<span class="govuk-caption-m">Table</span>
29-
<h1 class="govuk-heading-l">{{table.name}}</h1>
30+
<h2 class="govuk-heading-m">{{table.name}}</h2>
3031
</div>
3132
</div>
3233
<div class="govuk-grid-row">
3334
<div class="govuk-grid-column-two-thirds">
3435
<div class="summary-card">
35-
<h2 class="govuk-heading-s govuk-!-margin-top-3">
36+
<h3 class="govuk-heading-s govuk-!-margin-top-3">
3637
Description
37-
</h2>
38+
</h3>
3839
<div class="govuk-body">
3940
{{table.description|markdown:3}}
4041
</div>

templates/glossary.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{% block content %}
66
<div class="govuk-grid-row">
77
<div class="govuk-grid-column-one-quarter">
8-
<h1 class="govuk-heading-l">Glossary</h1>
8+
<h1 class="govuk-heading-l">{{h1_value}}</h1>
99
</div>
1010
<div class="govuk-grid-column-three-quarters">
1111
<div class="govuk-form-group govuk-!-margin-bottom-8 js-required">
@@ -58,4 +58,4 @@ <h3 class="govuk-heading-m" id="{{ member.name }}">{{ member.name }}</h3>
5858
import {init} from "{% static 'assets/js/enhanced-glossary.js' %}"
5959
init();
6060
</script>
61-
{% endblock scripts %}
61+
{% endblock scripts %}

templates/home.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{% block content %}
55

66
<a onclick="history.back()" class="govuk-back-link">Back</a>
7-
<h1 class="govuk-heading-xl">Customised page template</h1>
7+
<h1 class="govuk-heading-l">{{h1_value}}</h1>
88

99
<p class="govuk-body">
1010
<a href="{% url 'home:glossary' %}" class="govuk-link">Glossary</a>.

templates/search.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<div class="govuk-grid-column-two-thirds">
99
<form action="{% url 'home:search' %}" method="get" role="search" class="search__form govuk-!-margin-bottom-4" id="searchform">
1010
<div class="govuk-form-group">
11-
<h1 class="govuk-heading-xl">Find MOJ Data</h1>
11+
<h1 class="govuk-heading-l">{{h1_value}}</h1>
1212
<div class="search-container">
1313
<label for="{{ form.query.id_for_label }}" class="govuk-label govuk-visually-hidden-focusable">Search MOJ Data</label>
1414
{{ form.query }}
@@ -38,4 +38,4 @@ <h2 class="govuk-heading-l govuk-!-display-inline-block" id="result-count">{{tot
3838
import {initDomainFilter} from "{% static 'assets/js/enhanced-search.js' %}"
3939
initDomainFilter();
4040
</script>
41-
{% endblock scripts %}
41+
{% endblock scripts %}

0 commit comments

Comments
 (0)