Skip to content

Commit

Permalink
Add pagination nav element in UI #3
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <[email protected]>
  • Loading branch information
tdruez committed Dec 14, 2023
1 parent 6c183b3 commit b17eee1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
{% load i18n %}
{% load as_icon from dje_tags %}
{% load urlize_target_blank from dje_tags %}
{% load humanize %}

{% spaceless %}
<div class="row align-items-end">
<div class="col-auto">
{% include 'pagination/object_list_pagination.html' with page_obj=values.page_obj previous_url=values.previous_url next_url=values.next_url %}
</div>
</div>

<table class="table table-bordered table-md">
<thead>
<tr>
Expand Down
21 changes: 13 additions & 8 deletions product_portfolio/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ def get_extra_add_urls(self):
class ProductDetailsView(
LoginRequiredMixin,
BaseProductView,
PreviousNextPaginationMixin,
ObjectDetailsView,
):
template_name = "product_portfolio/product_details.html"
Expand Down Expand Up @@ -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 <span class="badge badge-primary">{count}</span>'
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)
Expand Down Expand Up @@ -516,6 +520,7 @@ def tab_inventory(self):

tab_context["vulnerable_purls"] = vulnerablecode.get_vulnerable_purls(packages)

label = f'Inventory <span class="badge text-bg-primary">{paginator.count}</span>'
return {
"label": format_html(label),
"fields": [
Expand Down

0 comments on commit b17eee1

Please sign in to comment.