From 8e6bcd90afc7aff5e822b36f09d80fbc85318009 Mon Sep 17 00:00:00 2001 From: zhaospei Date: Wed, 8 Feb 2023 17:22:43 +0700 Subject: [PATCH 1/2] fix superuser contest search --- judge/views/contests.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/judge/views/contests.py b/judge/views/contests.py index 9fb4273..f944e11 100644 --- a/judge/views/contests.py +++ b/judge/views/contests.py @@ -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()) From e2067d4d18823aac1f7db9c89aabebea9e4f0002 Mon Sep 17 00:00:00 2001 From: zhaospei Date: Thu, 9 Feb 2023 02:12:23 +0700 Subject: [PATCH 2/2] add hide organization contests list --- judge/views/contests.py | 6 ++++++ templates/contest/list.html | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/judge/views/contests.py b/judge/views/contests.py index f944e11..414a650 100644 --- a/judge/views/contests.py +++ b/judge/views/contests.py @@ -149,6 +149,9 @@ class ContestList( def get(self, request, *args, **kwargs): self.contest_query = None self.org_query = [] + self.show_orgs = 0 + if request.GET.get("show_orgs"): + self.show_orgs = 1 if "orgs" in self.request.GET and self.request.profile: try: @@ -182,6 +185,8 @@ class ContestList( ) if not self.org_query and self.request.organization: self.org_query = [self.request.organization.id] + if self.show_orgs: + queryset = queryset.filter(organizations=None) if self.org_query: queryset = queryset.filter(organizations__in=self.org_query) @@ -228,6 +233,7 @@ class ContestList( context["first_page_href"] = "." context["contest_query"] = self.contest_query context["org_query"] = self.org_query + context["show_orgs"] = int(self.show_orgs) if self.request.profile: if self.request.user.is_superuser: context["organizations"] = Organization.objects.all() diff --git a/templates/contest/list.html b/templates/contest/list.html index 94ec439..7d406d4 100644 --- a/templates/contest/list.html +++ b/templates/contest/list.html @@ -18,6 +18,10 @@ padding-bottom: 1em; } + #show-btn { + margin-top: 0.5em; + } + {% if page_obj and page_obj.number > 1%} #ongoing-table { display: none; @@ -71,6 +75,10 @@