Skip to content

Commit

Permalink
WIP for UAT
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenMullally committed Sep 6, 2023
1 parent a4a0660 commit c86907e
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 4 deletions.
125 changes: 124 additions & 1 deletion measures/jinja2/measures/list.jinja
Original file line number Diff line number Diff line change
@@ -1,4 +1,127 @@
{% extends "layouts/layout.jinja" %}

{% from "components/button/macro.njk" import govukButton %}
{% from "components/input/macro.njk" import govukInput %}
{% from "components/table/macro.njk" import govukTable %}

{% set form_url = "measure-ui-list" %}
{% set list_include = "includes/measures/list.jinja" %}

{%- include "layouts/list_vertical.jinja" -%}
{% set page_title = "Find and edit " ~ object_list.model._meta.verbose_name_plural %}

{% block content %}
<h1 class="govuk-heading-xl">{{ page_title }}</h1>

<div class="full-width-search">
<div class="govuk-!-margin-bottom-5">
<h2 class="govuk-heading-m govuk-!-margin-bottom-5">Search and filter</h2>
<p class="govuk-body">
Select one or more options to search
</p>
<form method="get" action="{{ url(form_url) }}">
{{ crispy(filter.form) }}
</form>
</div>


<div class="govuk-!-margin-top-3">
{% if paginator.count > 0 %}

{% set objects_count = '{0:,}'.format(paginator.count) %}
{% if paginator.limit_breached %}
{% set objects_count = objects_count ~ '+' %}
{% endif %}

<p class="govuk-body-l">
{{ objects_count }} results
</p>

{% endif %}
{% if object_list %}
{% include list_include %}
{% else %}
<p class="govuk-body">There are no results for your search, please:</p>
<ul class="govuk-list govuk-list--bullet">
<li>check the spelling of your keywords</li>
<li>use more general keywords</li>
<li>select or deselect different filters</li>
<li>get help via our <a class="govuk-link" href="#">support and feedback form</a></li>
</ul>
{% endif %}


{% if page_obj.has_other_pages() %}
{% set objects_count = '{0:,}'.format(paginator.count) %}
{% set page_count = '{0:,}'.format(paginator.num_pages) %}
{% if paginator.limit_breached %}
{% set objects_count = 'more than ' ~ objects_count %}
{% set page_count = 'more than ' ~ page_count %}
{% endif %}

<nav class="pagination tamato-clearfix" role="navigation" aria-label="Pagination Navigation">
<div class="govuk-body">
Showing {{ page_obj|length }} of {{ objects_count }}
{# Polymorphic TrackedModelsQuerySet instances don't have a valid `model`. #}
{% if items_name %}
{{items_name}}
{% elif page_obj.object_list.model %}
{{ page_obj.object_list.model._meta.verbose_name_plural if paginator.count > 1 else page_obj.object_list.model._meta.verbose_name }}
{% else %}
"items"
{% endif %}
</div>
<div class="govuk-body align-left">
Page {{page_obj.number}} of {{ page_count }}
</div>
<ul class="govuk-list align-right">
{% if page_obj.has_previous() %}
<li>
<a
class="govuk-link govuk-!-margin-right-1"
href="?{{ query_transform(request, page=page_obj.previous_page_number())}}"
rel="prev"
aria-label="Goto Page {{ page_obj.previous_page_number() }}"
>
Prev
</a>
</li>
{% endif %}
{% for page_link in page_links %}
{% set isCurrent = page_link == page_obj.number %}
<li
class="{{ 'govuk-!-margin-left-2 govuk-!-margin-right-2' if isCurrent else 'govuk-!-margin-right-1'}}"
{% if isCurrent %}aria-current="true"{% endif %}
>
{% if page_link == '...' or page_link == page_obj.number|string %}
{{ page_link }}
{% else %}
<a
class="govuk-link"
href="?{{ query_transform(request, page=page_link) }}"
aria-label="Goto Page {{ page_link }}"
>{{ '{0:,}'.format(page_link|int) }}</a>
{% endif %}
</li>
{% endfor %}
{% if paginator.limit_breached %}
<li class="govuk-!-margin-right-1" >...</li>
{% endif %}
{% if page_obj.has_next() %}
<li>
<a
class="govuk-link"
href="?{{ query_transform(request, page=page_obj.next_page_number()) }}"
rel="next"
aria-label="Goto Page {{ page_obj.next_page_number() }}"
>
Next
</a>
</li>
{% endif %}
</ul>
</nav>
{% endif %}

</div>
</div>
{% endblock %}
18 changes: 16 additions & 2 deletions measures/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

from common.forms import unprefix_formset_data
from common.models import TrackedModel
from common.pagination import build_pagination_list
from common.serializers import AutoCompleteSerializer
from common.util import TaricDateRange
from common.validators import UpdateType
Expand Down Expand Up @@ -176,10 +177,23 @@ def get_form_kwargs(self):
def paginator(self):
filterset_class = self.get_filterset_class()
self.filterset = self.get_filterset(filterset_class)
return MeasurePaginator(self.filterset.qs, per_page=20)
return MeasurePaginator(self.filterset.qs, per_page=200)

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context = {}
paginator = self.paginator
page = paginator.get_page(self.request.GET.get("page", 1))
context["is_paginated"] = True
context["filter"] = kwargs["filter"]
context["form"] = self.get_form()
context["view"] = self
context["paginator"] = paginator
context["page_obj"] = page
context["object_list"] = page.object_list
context["page_links"] = build_pagination_list(
page.number,
page.paginator.num_pages,
)
measure_selections = [
SelectableObjectsForm.object_id_from_field_name(name)
for name in self.measure_selections
Expand Down
2 changes: 1 addition & 1 deletion settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@
LIMITED_PAGINATOR_MAX_COUNT = 200
# Default max number of objects that will be accurately counted by MeasurePaginator.
MEASURES_PAGINATOR_MAX_COUNT = int(
os.environ.get("MEASURES_PAGINATOR_MAX_COUNT", "1000"),
os.environ.get("MEASURES_PAGINATOR_MAX_COUNT", "30000"),
)

# key used to instantiate GOVUK Notify python client
Expand Down

0 comments on commit c86907e

Please sign in to comment.