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

Draft: Updates to the previous releases page #100

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

AWitcherONS
Copy link
Contributor

Pagination on Previous Release Page

Add the Pagination to the release Page

How to review

Content / functionality

Describe the steps required to test the changes (include screenshots if appropriate).

Follow-up Actions

Issues I have noticed
Previous Release page showing 11 entries expected 10
Previous Release Page Sorting correctly

@zerolab zerolab changed the title Feature/previous release page cms 256 Updates to the previous releases page Feb 13, 2025
@AWitcherONS AWitcherONS changed the title Updates to the previous releases page Draft: Updates to the previous releases page Feb 18, 2025

{% block header_area %}
<div class="common-header article-header {% if page.updates %}article-header--flush{% endif %}">
<div class="ons-container">
{% include "templates/components/navigation/breadcrumbs.html" %}
Copy link
Contributor

Choose a reason for hiding this comment

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

The breadcrumbs include needs to stay on the statistical article page

@@ -99,3 +99,6 @@
"0002_articleseriespage_listing_image_and_more", # Ignoring NOT NULL constraint on columns
],
}

# Override size of the pagination used on the previous_release page.
PREVIOUS_RELEASES_PER_PAGE = 3
Copy link
Contributor

Choose a reason for hiding this comment

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

It is probably best to move this to local.py.example, and commented out too. This should be a developer choice

Given a topic page exists with status published
And the topic page has a statistical article in a series with status published
When an external user navigates to statistical article in a series previous releases page
Then the external user should not see pagination
Copy link
Contributor

Choose a reason for hiding this comment

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

surely if you are on the previous releases page, the breadcrumb should end with the latest article in series, rather than not show at all. We are, after all, one level deeper

e.g. https://www.ons.gov.uk/economy/inflationandpriceindices/bulletins/consumerpriceinflation/previousreleases

@@ -72,3 +72,6 @@
SLACK_NOTIFICATIONS_WEBHOOK_URL = None

ONS_API_BASE_URL = "dummy_url"

# Override size of the pagination used on the previous_release page.
PREVIOUS_RELEASES_PER_PAGE = 3
Copy link
Contributor

Choose a reason for hiding this comment

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

This is probably fine.
For future, Django's test suite has override_settings which helps with overriding any of its settings during tests, either at test class level or individual test function

Comment on lines 13 to 26
{% block ONS_pagination_v1 %}
{% from "components/pagination/_macro.njk" import onsPagination %}
{% if pages.paginator.num_pages > 1 %}
<div class="ons-pagination__position">Page {{ pages.number }} of {{pages.paginator.num_pages }}</div>

{{
onsPagination({
"hideRangeIndicator": true,
"currentPageNumber": pages.number ,
"pages": ons_pagination_url_list
})
}}
{% endif %}
{% endblock %}
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
{% block ONS_pagination_v1 %}
{% from "components/pagination/_macro.njk" import onsPagination %}
{% if pages.paginator.num_pages > 1 %}
<div class="ons-pagination__position">Page {{ pages.number }} of {{pages.paginator.num_pages }}</div>
{{
onsPagination({
"hideRangeIndicator": true,
"currentPageNumber": pages.number ,
"pages": ons_pagination_url_list
})
}}
{% endif %}
{% endblock %}
{% block pagination %}
{% from "components/pagination/_macro.njk" import onsPagination %}
{% if pages.paginator.num_pages > 1 %}
<div class="ons-pagination__position">Page {{ pages.number }} of {{pages.paginator.num_pages }}</div>
{# fmt:off #}
{{
onsPagination({
"hideRangeIndicator": true,
"currentPageNumber": pages.number ,
"pages": ons_pagination_url_list
})
}}
{# fmt:on #}
{% endif %}
{% endblock %}

although I question the need to wrap this whole bit in {% block %} since we don't plan to derive the template


try:
pages = paginator.page(int(request.GET.get("page", 1)))
ons_pagination_url_list = [{"url": "?page=" + str(n + 1)} for n in range(paginator.num_pages)]
Copy link
Contributor

@zerolab zerolab Mar 11, 2025

Choose a reason for hiding this comment

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

Suggested change
ons_pagination_url_list = [{"url": "?page=" + str(n + 1)} for n in range(paginator.num_pages)]
ons_pagination_url_list = [{"url": f"?page={n}"} for n in paginator.page_range]

See https://docs.djangoproject.com/en/5.1/topics/pagination/

or, if you prefer using range, then

Suggested change
ons_pagination_url_list = [{"url": "?page=" + str(n + 1)} for n in range(paginator.num_pages)]
ons_pagination_url_list = [{"url": f"?page={n}"} for n in range(1, paginator.num_pages + 1)]

as per https://docs.python.org/3.12/library/stdtypes.html#range


Kudos for the approach to satisfy the page urls list requirement for the pagination component

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I liked your first suggestion but it needed an "in"

Copy link
Contributor

Choose a reason for hiding this comment

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

overzealous deletion of characters. edited

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants