From b17eee12b36bd05076c8282207b111b19f693a88 Mon Sep 17 00:00:00 2001 From: tdruez Date: Thu, 14 Dec 2023 15:14:01 +0100 Subject: [PATCH] Add pagination nav element in UI #3 Signed-off-by: tdruez --- .../product_portfolio/tabs/tab_inventory.html | 8 +++++++ product_portfolio/views.py | 21 ++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/product_portfolio/templates/product_portfolio/tabs/tab_inventory.html b/product_portfolio/templates/product_portfolio/tabs/tab_inventory.html index a155d26f..746cdb75 100644 --- a/product_portfolio/templates/product_portfolio/tabs/tab_inventory.html +++ b/product_portfolio/templates/product_portfolio/tabs/tab_inventory.html @@ -1,7 +1,15 @@ {% load i18n %} {% load as_icon from dje_tags %} {% load urlize_target_blank from dje_tags %} +{% load humanize %} + {% spaceless %} +
+
+ {% include 'pagination/object_list_pagination.html' with page_obj=values.page_obj previous_url=values.previous_url next_url=values.next_url %} +
+
+ diff --git a/product_portfolio/views.py b/product_portfolio/views.py index 09a69116..3b92006d 100644 --- a/product_portfolio/views.py +++ b/product_portfolio/views.py @@ -204,6 +204,7 @@ def get_extra_add_urls(self): class ProductDetailsView( LoginRequiredMixin, BaseProductView, + PreviousNextPaginationMixin, ObjectDetailsView, ): template_name = "product_portfolio/product_details.html" @@ -455,20 +456,23 @@ def tab_inventory(self): return # 2. Paginate the inventory list - page_number = self.request.GET.get("inventory-page", 2) paginator = Paginator(all_inventory_items, settings.TAB_PAGINATE_BY) - object_list = paginator.page(page_number).object_list + page_obj = paginator.get_page(number=self.request.GET.get("inventory-page", 2)) + object_list = page_obj.object_list + + self.query_dict_page_param = "inventory-page" + previous_url, next_url = self.get_previous_next(page_obj) + tab_context = { + "page_obj": page_obj, + "previous_url": previous_url, + "next_url": next_url, + } # 3. Group objects by features objects_by_feature = defaultdict(list) for feature, items in group_by_simple(object_list, "feature").items(): objects_by_feature[feature].extend(items) - - count = len(all_inventory_items) - label = f'Inventory {count}' - tab_context = { - "inventory_items": dict(objects_by_feature.items()), - } + tab_context["inventory_items"] = dict(objects_by_feature.items()) # 4. Inject the Scan data when activated scancodeio = ScanCodeIO(user) @@ -516,6 +520,7 @@ def tab_inventory(self): tab_context["vulnerable_purls"] = vulnerablecode.get_vulnerable_purls(packages) + label = f'Inventory {paginator.count}' return { "label": format_html(label), "fields": [