Skip to content

Commit

Permalink
Merge pull request #82 from PenseNisso/feature/aprimoramento_filtragem
Browse files Browse the repository at this point in the history
Merge branch feature/aprimoramentos_filtragem on develop
  • Loading branch information
Lozavival authored Dec 13, 2023
2 parents b393321 + f51cc49 commit 198e2ff
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions search/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any

from django.db.models import Count, Q, Value
from django.db.models import Count, Q
from django.db.models.functions import Lower
from django.db.models.query import QuerySet
from django.http import HttpRequest, HttpResponse
from django.views.generic import ListView
Expand Down Expand Up @@ -34,7 +35,7 @@ def build_filters(self, data: dict) -> "list[AbstractFilter]":

def apply_sorting(self, set, option: str):
if option == "alphabetical_descending":
set = set.order_by("-name")
set = set.order_by(Lower("name").desc())
elif option == "most_reports":
set = set.order_by("-count_reports")
elif option == "least_reports":
Expand All @@ -44,14 +45,14 @@ def apply_sorting(self, set, option: str):
elif option == "lowest_score":
set = sorted(set, key=lambda company: company.compute_score())
else:
set = set.order_by("name")
set = set.order_by(Lower("name"))
return set

def filter_queryset(
self, set, filters: "list[AbstractFilter]", sorting_option: str
):
object_list = (
set.annotate(count_reports=Count("reports"))
set.annotate(count_reports=Count("reports", filter=Q(reports__status="AP")))
.annotate(count_lawsuits=Count("lawsuits"))
.annotate(count_news=Count("news"))
.filter(self.apply_filters(filters))
Expand Down

0 comments on commit 198e2ff

Please sign in to comment.