Skip to content

Commit 0d5c508

Browse files
committed
Workflow
Signed-off-by: RISHI GARG <134256793+Rishi-source@users.noreply.github.com>
1 parent a19c824 commit 0d5c508

2 files changed

Lines changed: 29 additions & 25 deletions

File tree

vulnerabilities/pagination_mixin.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ class PaginatedListViewMixin:
33
max_page_size = 100
44

55
PAGE_SIZE_CHOICES = [
6-
{'value': 20, 'label': '20 per page'},
7-
{'value': 50, 'label': '50 per page'},
8-
{'value': 100, 'label': '100 per page'}
6+
{"value": 20, "label": "20 per page"},
7+
{"value": 50, "label": "50 per page"},
8+
{"value": 100, "label": "100 per page"},
99
]
1010

1111
def get_paginate_by(self, queryset=None):
1212
try:
13-
page_size = int(self.request.GET.get('page_size', self.paginate_by))
13+
page_size = int(self.request.GET.get("page_size", self.paginate_by))
1414
if page_size <= 0:
1515
return self.paginate_by
1616
return min(page_size, self.max_page_size)
@@ -19,21 +19,22 @@ def get_paginate_by(self, queryset=None):
1919

2020
def get_context_data(self, **kwargs):
2121
context = super().get_context_data(**kwargs)
22-
22+
2323
current_page_size = self.get_paginate_by()
24-
total_count = context['paginator'].count
25-
26-
context.update({
27-
'current_page_size': current_page_size,
28-
'page_size_choices': self.PAGE_SIZE_CHOICES,
29-
'total_count': total_count,
30-
'page_range': self._get_page_range(
31-
context['paginator'],
32-
context['page_obj'].number
33-
),
34-
'search': self.request.GET.get('search', '')
35-
})
36-
24+
total_count = context["paginator"].count
25+
26+
context.update(
27+
{
28+
"current_page_size": current_page_size,
29+
"page_size_choices": self.PAGE_SIZE_CHOICES,
30+
"total_count": total_count,
31+
"page_range": self._get_page_range(
32+
context["paginator"], context["page_obj"].number
33+
),
34+
"search": self.request.GET.get("search", ""),
35+
}
36+
)
37+
3738
return context
3839

3940
def _get_page_range(self, paginator, current_page, window=2):
@@ -42,16 +43,16 @@ def _get_page_range(self, paginator, current_page, window=2):
4243

4344
pages = [1]
4445
if current_page > 3:
45-
pages.append('...')
46+
pages.append("...")
4647

4748
start_page = max(2, current_page - window)
4849
end_page = min(paginator.num_pages - 1, current_page + window)
4950
pages.extend(range(start_page, end_page + 1))
50-
51+
5152
if current_page < paginator.num_pages - 2:
52-
pages.append('...')
53-
53+
pages.append("...")
54+
5455
if paginator.num_pages not in pages:
5556
pages.append(paginator.num_pages)
56-
57+
5758
return pages

vulnerabilities/views.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import logging
1010
from datetime import datetime
1111

12-
from .pagination_mixin import PaginatedListViewMixin
12+
from .mixins import PaginatedListViewMixin
1313

1414
from cvss.exceptions import CVSS2MalformedError
1515
from cvss.exceptions import CVSS3MalformedError
@@ -68,6 +68,7 @@ class PackageSearch(PaginatedListViewMixin, ListView):
6868
"""
6969
View for searching and displaying packages with pagination.
7070
"""
71+
7172
model = models.Package
7273
template_name = "packages.html"
7374
ordering = ["type", "namespace", "name", "version"]
@@ -86,10 +87,12 @@ def get_queryset(self, query=None):
8687
.order_by("package_url")
8788
)
8889

90+
8991
class VulnerabilitySearch(PaginatedListViewMixin, ListView):
9092
"""
9193
View for searching and displaying vulnerabilities with pagination.
9294
"""
95+
9396
model = models.Vulnerability
9497
template_name = "vulnerabilities.html"
9598
ordering = ["vulnerability_id"]
@@ -102,7 +105,7 @@ def get_context_data(self, **kwargs):
102105
def get_queryset(self, query=None):
103106
query = query or self.request.GET.get("search") or ""
104107
return self.model.objects.search(query=query).with_package_counts()
105-
108+
106109

107110
class PackageDetails(DetailView):
108111
model = models.Package

0 commit comments

Comments
 (0)