Add organization to problem search

This commit is contained in:
cuom1999 2021-02-20 01:36:16 -06:00
parent 5a892f5a17
commit ffb6797c64
3 changed files with 34 additions and 4 deletions

View file

@ -29,7 +29,7 @@ from judge.comments import CommentedDetailView
from judge.forms import ProblemCloneForm, ProblemSubmitForm
from judge.models import ContestProblem, ContestSubmission, Judge, Language, Problem, ProblemGroup, \
ProblemTranslation, ProblemType, RuntimeVersion, Solution, Submission, SubmissionSource, \
TranslatedProblemForeignKeyQuerySet
TranslatedProblemForeignKeyQuerySet, Organization
from judge.pdf_problems import DefaultPdfMaker, HAS_PDF
from judge.utils.diggpaginator import DiggPaginator
from judge.utils.opengraph import generate_opengraph
@ -374,6 +374,10 @@ class ProblemList(QueryStringSortMixin, TitleMixin, SolvedProblemMixin, ListView
if self.profile is not None and self.hide_solved:
queryset = queryset.exclude(id__in=Submission.objects.filter(user=self.profile, points=F('problem__points'))
.values_list('problem__id', flat=True))
if self.org_query:
queryset = queryset.filter(
Q(organizations__in=self.org_query) |
Q(contests__contest__organizations__in=self.org_query))
if self.show_types:
queryset = queryset.prefetch_related('types')
if self.category is not None:
@ -414,12 +418,14 @@ class ProblemList(QueryStringSortMixin, TitleMixin, SolvedProblemMixin, ListView
context['full_text'] = 0 if self.in_contest else int(self.full_text)
context['show_editorial'] = 0 if self.in_contest else int(self.show_editorial)
context['organizations'] = Organization.objects.all()
context['category'] = self.category
context['categories'] = ProblemGroup.objects.all()
if self.show_types:
context['selected_types'] = self.selected_types
context['problem_types'] = ProblemType.objects.all()
context['has_fts'] = settings.ENABLE_FTS
context['org_query'] = self.org_query
context['search_query'] = self.search_query
context['completed_problem_ids'] = self.get_completed_problems()
context['attempted_problems'] = self.get_attempted_problems()
@ -467,6 +473,7 @@ class ProblemList(QueryStringSortMixin, TitleMixin, SolvedProblemMixin, ListView
self.search_query = None
self.category = None
self.org_query = []
self.selected_types = []
# This actually copies into the instance dictionary...
@ -481,6 +488,12 @@ class ProblemList(QueryStringSortMixin, TitleMixin, SolvedProblemMixin, ListView
except ValueError:
pass
if 'orgs' in request.GET:
try:
self.org_query = list(map(int, request.GET.getlist('orgs')))
except ValueError:
pass
self.point_start = safe_float_or_none(request.GET.get('point_start'))
self.point_end = safe_float_or_none(request.GET.get('point_end'))