Add problem action filter for contest

This commit is contained in:
cuom1999 2023-03-25 22:11:56 -05:00
parent c8d4a57270
commit a07b147ea6
4 changed files with 60 additions and 36 deletions

View file

@ -8,7 +8,7 @@ from judge.utils.celery import Progress
__all__ = ("apply_submission_filter", "rejudge_problem_filter", "rescore_problem") __all__ = ("apply_submission_filter", "rejudge_problem_filter", "rescore_problem")
def apply_submission_filter(queryset, id_range, languages, results): def apply_submission_filter(queryset, id_range, languages, results, contest):
if id_range: if id_range:
start, end = id_range start, end = id_range
queryset = queryset.filter(id__gte=start, id__lte=end) queryset = queryset.filter(id__gte=start, id__lte=end)
@ -16,16 +16,18 @@ def apply_submission_filter(queryset, id_range, languages, results):
queryset = queryset.filter(language_id__in=languages) queryset = queryset.filter(language_id__in=languages)
if results: if results:
queryset = queryset.filter(result__in=results) queryset = queryset.filter(result__in=results)
if contest:
queryset = queryset.filter(contest_object=contest)
queryset = queryset.exclude(status__in=Submission.IN_PROGRESS_GRADING_STATUS) queryset = queryset.exclude(status__in=Submission.IN_PROGRESS_GRADING_STATUS)
return queryset return queryset
@shared_task(bind=True) @shared_task(bind=True)
def rejudge_problem_filter( def rejudge_problem_filter(
self, problem_id, id_range=None, languages=None, results=None self, problem_id, id_range=None, languages=None, results=None, contest=None
): ):
queryset = Submission.objects.filter(problem_id=problem_id) queryset = Submission.objects.filter(problem_id=problem_id)
queryset = apply_submission_filter(queryset, id_range, languages, results) queryset = apply_submission_filter(queryset, id_range, languages, contest)
rejudged = 0 rejudged = 0
with Progress(self, queryset.count()) as p: with Progress(self, queryset.count()) as p:

View file

@ -78,6 +78,13 @@ class ManageProblemSubmissionView(TitleMixin, ManageProblemSubmissionMixin, Deta
) )
] ]
context["results"] = sorted(map(itemgetter(0), Submission.RESULT)) context["results"] = sorted(map(itemgetter(0), Submission.RESULT))
context["in_contest"] = False
if (
self.request.in_contest_mode
and self.object in self.request.participation.contest.problems.all()
):
context["in_contest"] = True
return context return context
@ -102,18 +109,26 @@ class BaseActionSubmissionsView(
except ValueError: except ValueError:
return HttpResponseBadRequest() return HttpResponseBadRequest()
contest = None
try:
in_contest = bool(self.request.POST.get("in_contest", False))
if in_contest:
contest = self.request.participation.contest
except (KeyError, ValueError):
return HttpResponseBadRequest()
return self.generate_response( return self.generate_response(
id_range, languages, self.request.POST.getlist("result") id_range, languages, self.request.POST.getlist("result"), contest
) )
def generate_response(self, id_range, languages, results): def generate_response(self, id_range, languages, results, contest):
raise NotImplementedError() raise NotImplementedError()
class ActionSubmissionsView(BaseActionSubmissionsView): class ActionSubmissionsView(BaseActionSubmissionsView):
def rejudge_response(self, id_range, languages, results): def rejudge_response(self, id_range, languages, results, contest):
status = rejudge_problem_filter.delay( status = rejudge_problem_filter.delay(
self.object.id, id_range, languages, results self.object.id, id_range, languages, results, contest
) )
return redirect_to_task_status( return redirect_to_task_status(
status, status,
@ -124,12 +139,11 @@ class ActionSubmissionsView(BaseActionSubmissionsView):
), ),
) )
def download_response(self, id_range, languages, results): def download_response(self, id_range, languages, results, contest):
if not self.request.user.is_superuser:
raise Http404
queryset = Submission.objects.filter(problem_id=self.object.id) queryset = Submission.objects.filter(problem_id=self.object.id)
submissions = apply_submission_filter(queryset, id_range, languages, results) submissions = apply_submission_filter(
queryset, id_range, languages, results, contest
)
with tempfile.SpooledTemporaryFile() as tmp: with tempfile.SpooledTemporaryFile() as tmp:
with zipfile.ZipFile(tmp, "w", zipfile.ZIP_DEFLATED) as archive: with zipfile.ZipFile(tmp, "w", zipfile.ZIP_DEFLATED) as archive:
@ -155,20 +169,20 @@ class ActionSubmissionsView(BaseActionSubmissionsView):
) )
return response return response
def generate_response(self, id_range, languages, results): def generate_response(self, id_range, languages, results, contest):
action = self.request.POST.get("action") action = self.request.POST.get("action")
if action == "rejudge": if action == "rejudge":
return self.rejudge_response(id_range, languages, results) return self.rejudge_response(id_range, languages, results, contest)
elif action == "download": elif action == "download":
return self.download_response(id_range, languages, results) return self.download_response(id_range, languages, results, contest)
else: else:
return Http404() return Http404()
class PreviewActionSubmissionsView(BaseActionSubmissionsView): class PreviewActionSubmissionsView(BaseActionSubmissionsView):
def generate_response(self, id_range, languages, results): def generate_response(self, id_range, languages, results, contest):
queryset = apply_submission_filter( queryset = apply_submission_filter(
self.object.submission_set.all(), id_range, languages, results self.object.submission_set.all(), id_range, languages, results, contest
) )
return HttpResponse(str(queryset.count())) return HttpResponse(str(queryset.count()))

View file

@ -2,7 +2,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: lqdoj2\n" "Project-Id-Version: lqdoj2\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-03-16 11:07+0700\n" "POT-Creation-Date: 2023-03-26 10:11+0700\n"
"PO-Revision-Date: 2021-07-20 03:44\n" "PO-Revision-Date: 2021-07-20 03:44\n"
"Last-Translator: Icyene\n" "Last-Translator: Icyene\n"
"Language-Team: Vietnamese\n" "Language-Team: Vietnamese\n"
@ -372,7 +372,7 @@ msgstr "Bạn không có quyền chấm lại nhiều bài nộp như vậy."
msgid "Rejudge the selected submissions" msgid "Rejudge the selected submissions"
msgstr "Chấm lại các bài nộp đã chọn" msgstr "Chấm lại các bài nộp đã chọn"
#: judge/admin/submission.py:304 judge/views/problem_manage.py:212 #: judge/admin/submission.py:304 judge/views/problem_manage.py:221
#, python-format #, python-format
msgid "%d submission were successfully rescored." msgid "%d submission were successfully rescored."
msgid_plural "%d submissions were successfully rescored." msgid_plural "%d submissions were successfully rescored."
@ -2527,11 +2527,11 @@ msgstr "Tính lại điểm kỳ thi"
msgid "Running MOSS" msgid "Running MOSS"
msgstr "Đang chạy MOSS" msgstr "Đang chạy MOSS"
#: judge/tasks/submission.py:45 #: judge/tasks/submission.py:47
msgid "Modifying submissions" msgid "Modifying submissions"
msgstr "Chỉnh sửa bài nộp" msgstr "Chỉnh sửa bài nộp"
#: judge/tasks/submission.py:65 #: judge/tasks/submission.py:67
msgid "Recalculating user points" msgid "Recalculating user points"
msgstr "Tính lại điểm người dùng" msgstr "Tính lại điểm người dùng"
@ -3097,7 +3097,7 @@ msgstr "Bạn đã vượt quá số lần nộp cho bài này."
msgid "Submit to %(problem)s" msgid "Submit to %(problem)s"
msgstr "Nộp bài cho %(problem)s" msgstr "Nộp bài cho %(problem)s"
#: judge/views/problem.py:1204 #: judge/views/problem.py:1207
msgid "Clone Problem" msgid "Clone Problem"
msgstr "Nhân bản bài tập" msgstr "Nhân bản bài tập"
@ -3143,17 +3143,17 @@ msgstr "File init.yml cho %s"
msgid "Managing submissions for %s" msgid "Managing submissions for %s"
msgstr "Quản lý bài nộp cho %s" msgstr "Quản lý bài nộp cho %s"
#: judge/views/problem_manage.py:120 #: judge/views/problem_manage.py:132
#, python-format #, python-format
msgid "Rejudging selected submissions for %s..." msgid "Rejudging selected submissions for %s..."
msgstr "Đang chấm lại các bài nộp cho %s..." msgstr "Đang chấm lại các bài nộp cho %s..."
#: judge/views/problem_manage.py:181 #: judge/views/problem_manage.py:190
#, python-format #, python-format
msgid "Rescoring all submissions for %s..." msgid "Rescoring all submissions for %s..."
msgstr "Đang tính điểm lại các bài nộp cho %s..." msgstr "Đang tính điểm lại các bài nộp cho %s..."
#: judge/views/problem_manage.py:196 #: judge/views/problem_manage.py:205
#, python-format #, python-format
msgid "Successfully scheduled %d submission for rejudging." msgid "Successfully scheduled %d submission for rejudging."
msgid_plural "Successfully scheduled %d submissions for rejudging." msgid_plural "Successfully scheduled %d submissions for rejudging."
@ -4812,24 +4812,28 @@ msgstr "Lọc theo ngôn ngữ:"
msgid "Filter by result:" msgid "Filter by result:"
msgstr "Lọc theo kết quả:" msgstr "Lọc theo kết quả:"
#: templates/problem/manage_submission.html:163 #: templates/problem/manage_submission.html:161
msgid "In current contest"
msgstr "Trong kỳ thi hiện tại"
#: templates/problem/manage_submission.html:167
msgid "Action" msgid "Action"
msgstr "Hành động" msgstr "Hành động"
#: templates/problem/manage_submission.html:165 #: templates/problem/manage_submission.html:169
msgid "Rejudge selected submissions" msgid "Rejudge selected submissions"
msgstr "Chấm lại những bài nộp này" msgstr "Chấm lại những bài nộp này"
#: templates/problem/manage_submission.html:170 #: templates/problem/manage_submission.html:174
msgid "Download selected submissions" msgid "Download selected submissions"
msgstr "Tải các bài nộp này" msgstr "Tải các bài nộp này"
#: templates/problem/manage_submission.html:176 #: templates/problem/manage_submission.html:180
#, python-format #, python-format
msgid "Are you sure you want to rescore %(count)d submissions?" msgid "Are you sure you want to rescore %(count)d submissions?"
msgstr "Bạn có chắc muốn tính điểm lại %(count)d bài nộp?" msgstr "Bạn có chắc muốn tính điểm lại %(count)d bài nộp?"
#: templates/problem/manage_submission.html:177 #: templates/problem/manage_submission.html:181
msgid "Rescore all submissions" msgid "Rescore all submissions"
msgstr "Tính điểm lại các bài nộp" msgstr "Tính điểm lại các bài nộp"
@ -5022,11 +5026,11 @@ msgstr "Lọc"
msgid "Random" msgid "Random"
msgstr "Ngẫu nhiên" msgstr "Ngẫu nhiên"
#: templates/problem/submit.html:120 #: templates/problem/submit.html:124
msgid "Your source code must contain at most 65536 characters." msgid "Your source code must contain at most 65536 characters."
msgstr "Code phải chứa không quá 65536 ký tự." msgstr "Code phải chứa không quá 65536 ký tự."
#: templates/problem/submit.html:175 #: templates/problem/submit.html:179
#, python-format #, python-format
msgid "" msgid ""
"<b>Warning!</b> Your default language, <b>%(default_language)s</b>, is " "<b>Warning!</b> Your default language, <b>%(default_language)s</b>, is "
@ -5035,7 +5039,7 @@ msgstr ""
"<b>Cẩn thận!</b> Ngôn ngữ ưa thích của bạn, <b>%(default_language)s</b>, " "<b>Cẩn thận!</b> Ngôn ngữ ưa thích của bạn, <b>%(default_language)s</b>, "
"không được sử dụng trong bài này." "không được sử dụng trong bài này."
#: templates/problem/submit.html:186 #: templates/problem/submit.html:190
#, fuzzy, python-format #, fuzzy, python-format
#| msgid "" #| msgid ""
#| "\n" #| "\n"
@ -5058,15 +5062,15 @@ msgstr[0] ""
" Bạn còn %(left)s lần nộp\n" " Bạn còn %(left)s lần nộp\n"
" " " "
#: templates/problem/submit.html:195 #: templates/problem/submit.html:199
msgid "You have 0 submissions left" msgid "You have 0 submissions left"
msgstr "Bạn đã hết lần nộp" msgstr "Bạn đã hết lần nộp"
#: templates/problem/submit.html:229 #: templates/problem/submit.html:233
msgid "No judge is available for this problem." msgid "No judge is available for this problem."
msgstr "Không có máy chấm có thể chấm bài này." msgstr "Không có máy chấm có thể chấm bài này."
#: templates/problem/submit.html:235 #: templates/problem/submit.html:239
msgid "Submit!" msgid "Submit!"
msgstr "Nộp bài!" msgstr "Nộp bài!"

View file

@ -157,6 +157,10 @@
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
{% if in_contest %}
<label for="in-contest" name="in_contest">{{ _('In current contest') }}:</label>
<input type="checkbox" name="in_contest">
{% endif %}
</form> </form>
</div> </div>
<div class="pane"> <div class="pane">