Skip to content
Open
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
2 changes: 1 addition & 1 deletion cfgov/agreements/jinja2/agreements/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ <h2>Agreements by '{{ issuer.name }}'</h2>
</div>
{% if page.has_next() or page.has_previous() %}
<div class="block block--flush-top block--flush-bottom block--padded-top">
{% import 'v1/includes/molecules/pagination.html' as pagination with context %}
{% import 'v1/includes/molecules/pagination.html' as pagination %}
{{ pagination.render(
page.paginator.num_pages,
page.number,
Expand Down
5 changes: 3 additions & 2 deletions cfgov/ask_cfpb/jinja2/ask-cfpb/answer-search-results.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% import 'v1/includes/molecules/pagination.html' as pagination with context %}
{% import 'v1/includes/molecules/pagination.html' as pagination %}
{% import 'ask-cfpb/_ask-search.html' as ask_search with context %}

{% extends 'v1/layouts/layout-2-1.html' %}
Expand Down Expand Up @@ -52,7 +52,8 @@ <h3 class="results-header">{{ _('Showing') }} {{ results.start_index() }}-{{ res
paginator.num_pages,
current_page | int,
'',
index
index,
pagination_params
) }}
</div>

Expand Down
4 changes: 2 additions & 2 deletions cfgov/ask_cfpb/jinja2/ask-cfpb/see-all.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends 'v1/layouts/layout-1-3.html' %}

{% import 'v1/includes/molecules/pagination.html' as pagination with context %}
{% import 'v1/includes/molecules/pagination.html' as pagination %}

{% block css -%}
{{ super() }}
Expand Down Expand Up @@ -77,7 +77,7 @@ <h1>
{% endfor %}

<div class="block block--sub">
{{ pagination.render( paginator.num_pages, current_page, '', 0 ) }}
{{ pagination.render( paginator.num_pages, current_page, '', 0, pagination_params ) }}
</div>
</section>
{% if not page.portal_category %}
Expand Down
11 changes: 11 additions & 0 deletions cfgov/ask_cfpb/models/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,11 @@ def get_results(self, request):
"pages": paginator.page(page_number),
"paginator": paginator,
"current_page": page_number,
"pagination_params": (
{"search_term": search.search_term}
if search.search_term
else {}
),
}
)
return TemplateResponse(request, "ask-cfpb/see-all.html", context)
Expand Down Expand Up @@ -377,6 +382,12 @@ def get_context(self, request, **kwargs):
)
context["about_us"] = get_standard_text(self.language, "about_us")
context["disclaimer"] = get_standard_text(self.language, "disclaimer")

# AnswerResultsPage.query is set by ask_cfpb.views.ask_search for
# cases where the user is making a query-based search.
query = getattr(self, "query", None)
context["pagination_params"] = {"q": query} if query else {}

return context


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% import 'v1/includes/atoms/radio-button.html' as radio %}
{% import 'v1/includes/atoms/tag-filter.html' as tag %}
{% import 'prepaid_agreements//search_result_item.html' as search_item %}
{% import 'v1/includes/molecules/pagination.html' as pagination with context %}
{% import 'v1/includes/molecules/pagination.html' as pagination %}
{% from 'v1/includes/organisms/expandable.html' import expandable with context %}

{% if current_count and current_count > 0 %}
Expand Down Expand Up @@ -168,7 +168,7 @@ <h3>No results match your search.</h3>
<div class="results__paginator">
{% if paginator.num_pages > 1 %}
<div class="block block--flush-top">
{{ pagination.render( paginator.num_pages, current_page, '', '' ) }}
{{ pagination.render( paginator.num_pages, current_page, '', '', pagination_params ) }}
</div>
{% endif %}
</div>
Expand Down
7 changes: 7 additions & 0 deletions cfgov/prepaid_agreements/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ def index(request):
paginator = Paginator(products.all(), 25)
page = paginator.get_page(page_number)

pagination_params = dict(filters)
if search_term:
pagination_params["q"] = search_term
if search_field:
pagination_params["search_field"] = search_field

return TemplateResponse(
request,
"prepaid_agreements/index.html",
Expand All @@ -153,6 +159,7 @@ def index(request):
"search_field": search_field,
"disclaimer_text": get_disclaimer_text(),
"support_text": get_support_text(),
"pagination_params": pagination_params,
},
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% import 'v1/includes/atoms/tag-filter.html' as tag %}
{% import 'regulations3k/regulations3k-search-result-item.html' as search_item %}
{% import 'v1/includes/molecules/pagination.html' as pagination with context %}
{% import 'v1/includes/molecules/pagination.html' as pagination %}

<div class="results__header">
{% if current_count and current_count > 0 %}
Expand Down Expand Up @@ -51,6 +51,6 @@ <h2 class="h3">No results match your filters.</h2>
{% endfor %}
</div>
<div class="results__paginator">
{{ pagination.render( paginator.num_pages, current_page, '', '' ) }}
{{ pagination.render( paginator.num_pages, current_page, '', '', pagination_params ) }}
</div>
{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{% import 'v1/includes/atoms/radio-button.html' as radio with context %}
{% import 'regulations3k/regulations3k-search-bar.html' as search_bar %}
{% import 'regulations3k/regulations3k-search-result-item.html' as search_item %}
{% import 'v1/includes/molecules/pagination.html' as pagination with context %}
{% from 'v1/includes/organisms/expandable.html' import expandable with context %}

{# HEAD items #}
Expand Down
6 changes: 6 additions & 0 deletions cfgov/regulations3k/models/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ def regulation_results_page(self, request):
"show_filters": any(
reg["selected"] is True for reg in payload["all_regs"]
),
"pagination_params": {
"q": search_query,
"regs": regs,
"order": order,
"results": num_results,
},
}
)
return TemplateResponse(request, self.get_template(request), context)
Expand Down
5 changes: 3 additions & 2 deletions cfgov/searchgov/jinja2/searchgov/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% from './recommended.html' import render as render_recommended %}
{% from './result.html' import render as render_result %}
{% import 'v1/includes/molecules/notification.html' as notification %}
{% import 'v1/includes/molecules/pagination.html' as pagination with context %}
{% import 'v1/includes/molecules/pagination.html' as pagination %}

{% set search_header = _('Search the CFPB') %}

Expand Down Expand Up @@ -81,7 +81,8 @@ <h2 class="u-visually-hidden">Results</h2>
<div class="block block--sub">
{{ pagination.render(
total_pages,
current_page
current_page,
extra_params=pagination_params
) }}
</div>
{% endblock content_main %}
Expand Down
1 change: 1 addition & 0 deletions cfgov/searchgov/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def get(self, request, **kwargs):
"current_page": current_page,
"recommended": recommended,
"results": results,
"pagination_params": {"q": query} if query else {},
}

if form.cleaned_data.get("format") == "json":
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% import 'v1/includes/atoms/tag-filter.html' as tag %}
{% import 'v1/includes/molecules/pagination.html' as pagination with context %}
{% import 'v1/includes/molecules/pagination.html' as pagination %}
{% from 'teachers_digital_platform/tdp_expandable.html' import expandable with context %}

{% macro build_filter_section(name) %}
Expand Down Expand Up @@ -162,7 +162,7 @@ <h3>No results match your search.</h3>
</ul>
</div>
<div class="results__footer">
{{ pagination.render( paginator.num_pages, current_page, 'tdp-search-facets-and-results', '' ) }}
{{ pagination.render( paginator.num_pages, current_page, 'tdp-search-facets-and-results', '', pagination_params ) }}
<div class="o-well">
Activities align with the My Money Five principles introduced by the statutorily created federal Financial Literacy and Education Commission.
</div>
Expand Down
6 changes: 6 additions & 0 deletions cfgov/teachers_digital_platform/models/activity_index_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ def dsl_search(self, request, *args, **kwargs):
return {"facets": []}

data = self.search_form.cleaned_data
pagination_params = {
key: data.get(key)
for key in ("q", "grade_level", "activity_duration", "topic")
}
all_facets = copy.copy(self.activity_setups.facet_setup)
selected_facets = {}
card_setup = self.activity_setups.ordered_cards
Expand Down Expand Up @@ -145,6 +149,7 @@ def dsl_search(self, request, *args, **kwargs):
"current_page": current_page,
"paginator": paginator,
"show_filters": bool(selected_facets),
"pagination_params": pagination_params,
}
return context_update

Expand Down Expand Up @@ -216,6 +221,7 @@ def dsl_search(self, request, *args, **kwargs):
"current_page": current_page,
"paginator": paginator,
"show_filters": bool(selected_facets),
"pagination_params": pagination_params,
}
return context_update

Expand Down
8 changes: 5 additions & 3 deletions cfgov/v1/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from v1.models import enforcement_action_page
from v1.util import ERROR_MESSAGES, ref
from v1.util.categories import clean_categories
from v1.util.categories import expand_shorthand_categories
from v1.util.datetimes import end_of_time_period


Expand Down Expand Up @@ -129,8 +129,6 @@ def __init__(self, *args, **kwargs):

super().__init__(*args, **kwargs)

clean_categories(selected_categories=self.data.get("categories"))

# When the form is created, it needs to make a request to the search
# backend to be able to populate some of its fields: topics, languages,
# and the minimum page date.
Expand All @@ -139,6 +137,10 @@ def __init__(self, *args, **kwargs):
self.set_topics()
self.set_languages()

def clean_categories(self):
"""Expand category shorthand into appropriate subcategories."""
return expand_shorthand_categories(self.cleaned_data.get("categories"))

def has_unfiltered_results(self):
return self.aggregations.hits.total.value > 0

Expand Down
24 changes: 0 additions & 24 deletions cfgov/v1/jinja2/v1/includes/macros/util/url_parameters.html

This file was deleted.

41 changes: 28 additions & 13 deletions cfgov/v1/jinja2/v1/includes/molecules/pagination.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,35 @@
index: A unique number given to render the form and its fields with.
Default is 0.

extra_params: A dict of additional query parameters to carry forward onto
the prev/next/page links, e.g. the caller's active search or
filter values. Each value may be a single string or a list
of strings (for repeated params).

========================================================================== #}

{% macro render(total_pages, current_page, fragment_id='', index=0) %}
{%- macro render(
total_pages, current_page, fragment_id='', index=0, extra_params=none
) %}
{% if total_pages > 1 and current_page <= total_pages %}
{% from 'v1/includes/macros/util/url_parameters.html' import url_parameters %}

{% set fragment_id = '#' + fragment_id if fragment_id else '' %}

{%- set pairs = [] %}
{%- for key, values in (extra_params or {}).items() if key not in ('page', 'partial') %}
{%- for value in (
[values] if values is string or values is not iterable else values
) %}
{%- if value is not none and value != '' %}
{%- do pairs.append((key, value)) %}
{%- endif %}
{%- endfor %}
{%- endfor -%}

{%- set extra_qs %}
{%- for key, value in pairs %}&{{ key }}={{ value }}{% endfor %}
{%- endset -%}

<nav class="m-pagination"
role="navigation"
aria-label="{{ _('Pagination') }}">
Expand All @@ -36,7 +57,7 @@
<a class="a-btn
m-pagination__btn-prev"
href="?page={{ (current_page - 1) ~
url_parameters(request.GET) ~
extra_qs ~
fragment_id }}">
{%- else %}
<a class="a-btn
Expand All @@ -48,15 +69,9 @@
</a>

<form class="m-pagination__form" action="{{ fragment_id }}">
{% for (key, value_as_list) in request.GET.lists() %}
{% for list_item in value_as_list %}
{% if list_item != '' and key != 'page' %}
<input type="hidden"
name="{{ key }}"
value="{{ list_item }}">
{% endif %}
{% endfor %}
{% endfor %}
{% for key, value in pairs -%}
<input type="hidden" name="{{ key }}" value="{{ value }}">
{%- endfor %}
<label class="m-pagination__label">
{{ _('Page') }}
<span class="u-visually-hidden">
Expand Down Expand Up @@ -85,7 +100,7 @@
<a class="a-btn
m-pagination__btn-next"
href="?page={{ (current_page + 1) ~
url_parameters(request.GET) ~
extra_qs ~
fragment_id }}">
{%- else %}
<a class="a-btn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@

{% if paginator.num_pages > 1 %}
<div class="block block--flush-top block--flush-bottom block--padded-top">
{% import 'v1/includes/molecules/pagination.html' as pagination with context %}
{% import 'v1/includes/molecules/pagination.html' as pagination %}
{{ pagination.render(
paginator.num_pages,
page_number
page_number,
extra_params=pagination_params
) }}
</div>
{% endif %}
Expand Down
8 changes: 8 additions & 0 deletions cfgov/v1/models/filterable_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,18 @@ def get_valid_form_results(self, request, form):
filtered_qs_page, many=True, context={"request": request}
)

# cleaned_data["categories"] is expanded from shorthand groups
# like "blog" into a set of subcategory slugs, which is what the
# search backend filters on. Pagination query strings should include
# the original shorthand, not the expanded set.
pagination_params = dict(form.cleaned_data)
pagination_params["categories"] = form.data.get("categories", [])

return {
"paginator": paginator,
"page_number": filtered_qs_page.number,
"results": serializer.data,
"pagination_params": pagination_params,
}

def set_do_not_index(self, field, value):
Expand Down
Loading
Loading