From 7765c14264038e81c65e75fa90a43d58af581eac 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 | 10 +++++ AIPscan/Reporter/templates/aips.html | 53 ++++++++++++++++++-------- AIPscan/Reporter/tests/test_helpers.py | 27 +++++++++++++ AIPscan/Reporter/views.py | 19 ++++++--- 4 files changed, 88 insertions(+), 21 deletions(-) diff --git a/AIPscan/Reporter/helpers.py b/AIPscan/Reporter/helpers.py index 17c38048..4fa1bb36 100644 --- a/AIPscan/Reporter/helpers.py +++ b/AIPscan/Reporter/helpers.py @@ -145,3 +145,13 @@ 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 diff --git a/AIPscan/Reporter/templates/aips.html b/AIPscan/Reporter/templates/aips.html index c456f527..34a49684 100644 --- a/AIPscan/Reporter/templates/aips.html +++ b/AIPscan/Reporter/templates/aips.html @@ -2,7 +2,7 @@ {% block content %} -
AIPs ({{ aips|length }})
+
AIPs ({{ paging.items|length }})
{% if storage_services %} @@ -42,9 +42,9 @@ - {% if aips %} + {% if paging.items %} - +
@@ -54,19 +54,17 @@ - - {% if aips %} - {% for aip in aips %} - - - - - - - - - {% endfor %} - {% endif %} + + {% for aip in paging.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 paging.total %} + +
+
+
+
Showing {{ first_item }} to {{ last_item }} of {{ paging.total }} entries
+
+
+ +
+
+
+ +{% endif %} +