Fix contest filter

This commit is contained in:
cuom1999 2023-11-17 01:11:54 -06:00
parent 2ac300ff02
commit 32a1ea8919

View file

@ -146,7 +146,7 @@ class ContestList(
default_desc = frozenset(("name", "user_count")) default_desc = frozenset(("name", "user_count"))
def get_default_sort_order(self, request): def get_default_sort_order(self, request):
if "contest" in request.GET and settings.ENABLE_FTS: if request.GET.get("contest") and settings.ENABLE_FTS:
return "-relevance" return "-relevance"
return "-start_time" return "-start_time"
@ -161,7 +161,7 @@ class ContestList(
if request.GET.get("show_orgs"): if request.GET.get("show_orgs"):
self.show_orgs = 1 self.show_orgs = 1
if "orgs" in self.request.GET and self.request.profile: if self.request.GET.get("orgs") and self.request.profile:
try: try:
self.org_query = list(map(int, request.GET.getlist("orgs"))) self.org_query = list(map(int, request.GET.getlist("orgs")))
if not self.request.user.is_superuser: if not self.request.user.is_superuser:
@ -169,9 +169,11 @@ class ContestList(
i i
for i in self.org_query for i in self.org_query
if i if i
in self.request.profile.organizations.values_list( in set(
self.request.profile.organizations.values_list(
"id", flat=True "id", flat=True
) )
)
] ]
except ValueError: except ValueError:
pass pass
@ -185,7 +187,7 @@ class ContestList(
.prefetch_related("tags", "organizations", "authors", "curators", "testers") .prefetch_related("tags", "organizations", "authors", "curators", "testers")
) )
if "contest" in self.request.GET: if self.request.GET.get("contest"):
self.contest_query = query = " ".join( self.contest_query = query = " ".join(
self.request.GET.getlist("contest") self.request.GET.getlist("contest")
).strip() ).strip()
@ -253,9 +255,6 @@ class ContestList(
context["org_query"] = self.org_query context["org_query"] = self.org_query
context["show_orgs"] = int(self.show_orgs) context["show_orgs"] = int(self.show_orgs)
if self.request.profile: if self.request.profile:
if self.request.user.is_superuser:
context["organizations"] = Organization.objects.all()
else:
context["organizations"] = self.request.profile.organizations.all() context["organizations"] = self.request.profile.organizations.all()
context["page_type"] = "list" context["page_type"] = "list"
context.update(self.get_sort_context()) context.update(self.get_sort_context())