Skip to content

Commit

Permalink
initial push sorting added in api and ui
Browse files Browse the repository at this point in the history
  • Loading branch information
NucleonGodX committed Jan 23, 2025
1 parent 56eb442 commit 801ea0f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions vulnerabilities/api_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def get_queryset(self):
if aliases:
queryset = queryset.filter(aliases__alias__in=aliases).distinct()

return queryset
return queryset.order_by("-aliases__alias")

def get_serializer_class(self):
if self.action == "list":
Expand Down Expand Up @@ -284,7 +284,7 @@ def get_queryset(self):
queryset = queryset.filter(
fixing_vulnerabilities__vulnerability_id=fixing_vulnerability
)
return queryset.with_is_vulnerable()
return queryset.with_is_vulnerable().order_by("type", "namespace", "name", "-version")

def list(self, request, *args, **kwargs):
queryset = self.get_queryset()
Expand Down Expand Up @@ -427,8 +427,8 @@ def bulk_search(self, request):

query = (
Package.objects.filter(plain_package_url__in=plain_purls)
.order_by("plain_package_url")
.distinct("plain_package_url")
.order_by("type", "namespace", "name", "-version")
.distinct("type", "namespace", "name", "version")
.with_is_vulnerable()
)

Expand Down Expand Up @@ -498,8 +498,8 @@ def all(self, request):
vulnerable_purls = (
Package.objects.vulnerable()
.only("package_url")
.order_by("package_url")
.distinct()
.order_by("type", "namespace", "name", "-version")
.distinct("type", "namespace", "name", "version")
.values_list("package_url", flat=True)
)
return Response(vulnerable_purls)
Expand Down
10 changes: 5 additions & 5 deletions vulnerabilities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ def get_queryset(self, query=None):
self.model.objects.search(query)
.with_vulnerability_counts()
.prefetch_related()
.order_by("package_url")
.order_by("type", "namespace", "name", "-version")
)


class VulnerabilitySearch(ListView):
model = models.Vulnerability
template_name = "vulnerabilities.html"
ordering = ["vulnerability_id"]
ordering = ["aliases"]
paginate_by = PAGE_SIZE

def get_context_data(self, **kwargs):
Expand All @@ -105,7 +105,7 @@ def get_context_data(self, **kwargs):

def get_queryset(self, query=None):
query = query or self.request.GET.get("search") or ""
return self.model.objects.search(query=query).with_package_counts()
return self.model.objects.search(query=query).with_package_counts().order_by("-aliases")


class PackageDetails(DetailView):
Expand All @@ -118,10 +118,10 @@ def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
package = self.object
context["package"] = package
context["affected_by_vulnerabilities"] = package.affected_by.order_by("vulnerability_id")
context["affected_by_vulnerabilities"] = package.affected_by.order_by("-aliases")
# Ghost package should not fix any vulnerability.
context["fixing_vulnerabilities"] = (
None if package.is_ghost else package.fixing.order_by("vulnerability_id")
None if package.is_ghost else package.fixing.order_by("-aliases")
)
context["package_search_form"] = PackageSearchForm(self.request.GET)
context["fixed_package_details"] = package.fixed_package_details
Expand Down

0 comments on commit 801ea0f

Please sign in to comment.