fix superuser contest search

This commit is contained in:
zhaospei 2023-02-08 17:22:43 +07:00
parent 2ee279098f
commit 8e6bcd90af

View file

@ -153,12 +153,13 @@ class ContestList(
if "orgs" in self.request.GET and self.request.profile:
try:
self.org_query = list(map(int, request.GET.getlist("orgs")))
self.org_query = [
i
for i in self.org_query
if i
in self.request.profile.organizations.values_list("id", flat=True)
]
if not self.request.user.is_superuser:
self.org_query = [
i
for i in self.org_query
if i
in self.request.profile.organizations.values_list("id", flat=True)
]
except ValueError:
pass
@ -228,7 +229,10 @@ class ContestList(
context["contest_query"] = self.contest_query
context["org_query"] = self.org_query
if self.request.profile:
context["organizations"] = self.request.profile.organizations.all()
if self.request.user.is_superuser:
context["organizations"] = Organization.objects.all()
else:
context["organizations"] = self.request.profile.organizations.all()
context["page_type"] = "list"
context.update(self.get_sort_context())
context.update(self.get_sort_paginate_context())