From fc3fe8da0ffa064909f75d0a946dd236bf49e980 Mon Sep 17 00:00:00 2001 From: Mike Cantelon Date: Wed, 27 Sep 2023 00:54:41 -0700 Subject: [PATCH] Use server-side paging in aips page. (#209) To avoid slow page responses when there are a large amount of AIPs use server-side paging to limit the number of AIP HTML sent to the browser. --- AIPscan/Reporter/helpers.py | 19 +++++++++ AIPscan/Reporter/request_params.py | 1 + AIPscan/Reporter/templates/aips.html | 53 ++++++++++++++++++-------- AIPscan/Reporter/tests/test_helpers.py | 35 +++++++++++++++++ AIPscan/Reporter/views.py | 31 ++++++++++++--- 5 files changed, 118 insertions(+), 21 deletions(-) diff --git a/AIPscan/Reporter/helpers.py b/AIPscan/Reporter/helpers.py index 17c38048..c520e8eb 100644 --- a/AIPscan/Reporter/helpers.py +++ b/AIPscan/Reporter/helpers.py @@ -5,6 +5,7 @@ import csv from datetime import timedelta from io import StringIO +from urllib.parse import urlencode from flask import make_response from natsort import natsorted @@ -145,3 +146,21 @@ def get_premis_xml_lines(file_object): premis_xml_lines = file_object.premis_object.split("\n") return premis_xml_lines + + +def calculate_paging_window(page, pagination): + first_item = ((page - 1) * pagination.per_page) + 1 + last_item = page * pagination.per_page + + if last_item > pagination.total: + last_item = pagination.total + + return first_item, last_item + + +def urlencode_without_none_values(values): + for key in values: + if values[key] is None: + values[key] = "" + + return urlencode(values) diff --git a/AIPscan/Reporter/request_params.py b/AIPscan/Reporter/request_params.py index 732f048c..a2027b1b 100644 --- a/AIPscan/Reporter/request_params.py +++ b/AIPscan/Reporter/request_params.py @@ -11,6 +11,7 @@ PUID = "puid" STORAGE_LOCATION_ID = "storage_location" STORAGE_SERVICE_ID = "amss_id" +PAGE = "page" START_DATE = "start_date" END_DATE = "end_date" diff --git a/AIPscan/Reporter/templates/aips.html b/AIPscan/Reporter/templates/aips.html index c456f527..2c03f596 100644 --- a/AIPscan/Reporter/templates/aips.html +++ b/AIPscan/Reporter/templates/aips.html @@ -2,7 +2,7 @@ {% block content %} -
AIPs ({{ aips|length }})
+
AIPs ({{ pager.items|length }})
{% if storage_services %} @@ -42,9 +42,9 @@ - {% if aips %} + {% if pager.items %} - +
@@ -54,19 +54,17 @@ - - {% if aips %} - {% for aip in aips %} - - - - - - - - - {% endfor %} - {% endif %} + + {% for aip in pager.items %} + + + + + + + + + {% endfor %}
Transfer namePreservation copies Action
{{ aip.transfer_name }}{{ aip.uuid }}{{ aip.create_date }}{{ aip.original_file_count }}{{ aip.preservation_file_count }}
{{ aip.transfer_name }}{{ aip.uuid }}{{ aip.create_date }}{{ aip.original_file_count }}{{ aip.preservation_file_count }}
{% else %} @@ -85,6 +83,29 @@ {% endif %} +{% if pager.total %} + +
+
+
+
Showing {{ first_item }} to {{ last_item }} of {{ pager.total }} entries
+
+
+ +
+
+
+ +{% endif %} +