From 1bde7ab8a7995591503987ecc0f70ba050a28619 Mon Sep 17 00:00:00 2001 From: Tudor Brindus Date: Sat, 25 May 2024 12:20:52 -0400 Subject: [PATCH] api: add submission filtering by contest + contest info --- judge/views/api/api_v2.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/judge/views/api/api_v2.py b/judge/views/api/api_v2.py index dd45c284b..3c2b719c4 100644 --- a/judge/views/api/api_v2.py +++ b/judge/views/api/api_v2.py @@ -42,6 +42,11 @@ def get_object(self, key): return Problem.objects.get(code=key) +class ContestSimpleFilter(BaseSimpleFilter): + def get_object(self, key): + return Contest.objects.get(key=key) + + class BaseListFilter: def to_filter(self, key_list): raise NotImplementedError() @@ -566,6 +571,7 @@ class APISubmissionList(APIListView): basic_filters = ( ('user', ProfileSimpleFilter('user')), ('problem', ProblemSimpleFilter('problem')), + ('contest', ContestSimpleFilter('contest_object')), ) list_filters = ( ('id', 'id'), @@ -590,7 +596,7 @@ def get_unfiltered_queryset(self): ) return ( queryset - .select_related('problem', 'user__user', 'language') + .select_related('problem', 'contest', 'contest__participation', 'contest_object', 'user__user', 'language') .order_by('id') .only( 'id', @@ -602,6 +608,10 @@ def get_unfiltered_queryset(self): 'memory', 'points', 'result', + 'contest_object__key', + 'contest__points', + 'contest__participation__virtual', + 'contest__participation__real_start', ) ) @@ -616,6 +626,12 @@ def get_object_data(self, submission): 'memory': submission.memory, 'points': submission.points, 'result': submission.result, + 'contest': None if not submission.contest_object else { + 'key': submission.contest_object.key, + 'points': submission.contest.points, + 'virtual_participation_number': submission.contest.participation.virtual, + 'time_since_start_of_participation': submission.date - submission.contest.participation.real_start, + }, }