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: if "orgs" in self.request.GET 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")))
self.org_query = [ if not self.request.user.is_superuser:
i self.org_query = [
for i in self.org_query i
if i for i in self.org_query
in self.request.profile.organizations.values_list("id", flat=True) if i
] in self.request.profile.organizations.values_list("id", flat=True)
]
except ValueError: except ValueError:
pass pass
@ -228,7 +229,10 @@ class ContestList(
context["contest_query"] = self.contest_query context["contest_query"] = self.contest_query
context["org_query"] = self.org_query context["org_query"] = self.org_query
if self.request.profile: 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["page_type"] = "list"
context.update(self.get_sort_context()) context.update(self.get_sort_context())
context.update(self.get_sort_paginate_context()) context.update(self.get_sort_paginate_context())