diff --git a/vulnerabilities/templates/includes/pagination.html b/vulnerabilities/templates/includes/pagination.html
index 0d6dad430..0d4cf22ed 100644
--- a/vulnerabilities/templates/includes/pagination.html
+++ b/vulnerabilities/templates/includes/pagination.html
@@ -1,39 +1,46 @@
-
\ No newline at end of file
+
+
+
+{% endif %}
diff --git a/vulnerabilities/templates/packages.html b/vulnerabilities/templates/packages.html
index 1f7687429..6ca0ec026 100644
--- a/vulnerabilities/templates/packages.html
+++ b/vulnerabilities/templates/packages.html
@@ -18,6 +18,16 @@
{{ page_obj.paginator.count|intcomma }} results
+
+
+
+ 20 per page
+ 50 per page
+ 100 per page
+ 200 per page
+
+
+
{% if is_paginated %}
{% include 'includes/pagination.html' with page_obj=page_obj %}
{% endif %}
@@ -81,4 +91,12 @@
{% endif %}
+
{% endblock %}
diff --git a/vulnerabilities/templates/vulnerabilities.html b/vulnerabilities/templates/vulnerabilities.html
index 023d3f97f..3d9a3d3b5 100644
--- a/vulnerabilities/templates/vulnerabilities.html
+++ b/vulnerabilities/templates/vulnerabilities.html
@@ -18,7 +18,17 @@
{{ page_obj.paginator.count|intcomma }} results
- {% if is_paginated %}
+
+
+
+ 20 per page
+ 50 per page
+ 100 per page
+ 200 per page
+
+
+
+ {% if is_paginated %}
{% include 'includes/pagination.html' with page_obj=page_obj %}
{% endif %}
@@ -77,5 +87,13 @@
{% endif %}
{% endif %}
-
+
+
{% endblock %}
diff --git a/vulnerabilities/views.py b/vulnerabilities/views.py
index 394dc1c36..c4c3f6c93 100644
--- a/vulnerabilities/views.py
+++ b/vulnerabilities/views.py
@@ -15,6 +15,9 @@
from django.contrib import messages
from django.core.exceptions import ValidationError
from django.core.mail import send_mail
+from django.core.paginator import EmptyPage
+from django.core.paginator import PageNotAnInteger
+from django.core.paginator import Paginator
from django.http.response import Http404
from django.shortcuts import redirect
from django.shortcuts import render
@@ -68,11 +71,16 @@ class PackageSearch(ListView):
ordering = ["type", "namespace", "name", "version"]
paginate_by = PAGE_SIZE
+ def get_paginate_by(self, queryset):
+ page_size = self.request.GET.get("page_size", "")
+ return int(page_size) if page_size.isdigit() else self.paginate_by
+
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
request_query = self.request.GET
context["package_search_form"] = PackageSearchForm(request_query)
context["search"] = request_query.get("search")
+ context["page_size"] = self.get_paginate_by(self.get_queryset())
return context
def get_queryset(self, query=None):
@@ -96,17 +104,34 @@ class VulnerabilitySearch(ListView):
ordering = ["vulnerability_id"]
paginate_by = PAGE_SIZE
+ def get_paginate_by(self, queryset):
+ page_size = self.request.GET.get("page_size", "")
+ return int(page_size) if page_size.isdigit() else self.paginate_by
+
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
request_query = self.request.GET
context["vulnerability_search_form"] = VulnerabilitySearchForm(request_query)
context["search"] = request_query.get("search")
+ context["page_size"] = self.get_paginate_by(self.get_queryset())
return context
- def get_queryset(self, query=None):
- query = query or self.request.GET.get("search") or ""
+ def get_queryset(self):
+ query = self.request.GET.get("search") or ""
return self.model.objects.search(query=query).with_package_counts()
+ def paginate_queryset(self, queryset, page_size):
+ paginator = Paginator(queryset, page_size)
+ page = self.request.GET.get("page", "1")
+ try:
+ page_number = int(page)
+ page_obj = paginator.page(page_number)
+ except (ValueError, PageNotAnInteger):
+ page_obj = paginator.page(1)
+ except EmptyPage:
+ page_obj = paginator.page(paginator.num_pages)
+ return (paginator, page_obj, page_obj.object_list, page_obj.has_other_pages())
+
class PackageDetails(DetailView):
model = models.Package