From a64364e1adb1bf5b28f2e047b4fb55c7d8e9abbf Mon Sep 17 00:00:00 2001 From: Mike Cantelon Date: Wed, 11 Oct 2023 00:32:44 -0700 Subject: [PATCH] Use server-side paging in aips page. (#209) (#215) 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 | 11 ++++++ AIPscan/Reporter/request_params.py | 1 + AIPscan/Reporter/templates/aips.html | 53 ++++++++++++++++++-------- AIPscan/Reporter/tests/test_helpers.py | 36 +++++++++++++++++ AIPscan/Reporter/tests/test_views.py | 26 +++++++++++++ AIPscan/Reporter/views.py | 42 +++++++++++++++++--- 6 files changed, 147 insertions(+), 22 deletions(-) diff --git a/AIPscan/Reporter/helpers.py b/AIPscan/Reporter/helpers.py index 17c38048..8de8ea3a 100644 --- a/AIPscan/Reporter/helpers.py +++ b/AIPscan/Reporter/helpers.py @@ -145,3 +145,14 @@ def get_premis_xml_lines(file_object): premis_xml_lines = file_object.premis_object.split("\n") return premis_xml_lines + + +def calculate_paging_window(pagination): + first_item = ((pagination.page - 1) * pagination.per_page) + 1 + last_item = pagination.page * pagination.per_page + + return first_item, min(last_item, pagination.total) + + +def remove_dict_none_values(values): + return {index: "" if value is None else value for (index, value) in values.items()} 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..2f6e8c67 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 %} +