Add problem action filter for contest
This commit is contained in:
parent
c8d4a57270
commit
a07b147ea6
4 changed files with 60 additions and 36 deletions
|
@ -8,7 +8,7 @@ from judge.utils.celery import Progress
|
|||
__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:
|
||||
start, end = id_range
|
||||
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)
|
||||
if 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)
|
||||
return queryset
|
||||
|
||||
|
||||
@shared_task(bind=True)
|
||||
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 = apply_submission_filter(queryset, id_range, languages, results)
|
||||
queryset = apply_submission_filter(queryset, id_range, languages, contest)
|
||||
|
||||
rejudged = 0
|
||||
with Progress(self, queryset.count()) as p:
|
||||
|
|
|
@ -78,6 +78,13 @@ class ManageProblemSubmissionView(TitleMixin, ManageProblemSubmissionMixin, Deta
|
|||
)
|
||||
]
|
||||
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
|
||||
|
||||
|
||||
|
@ -102,18 +109,26 @@ class BaseActionSubmissionsView(
|
|||
except ValueError:
|
||||
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(
|
||||
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()
|
||||
|
||||
|
||||
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(
|
||||
self.object.id, id_range, languages, results
|
||||
self.object.id, id_range, languages, results, contest
|
||||
)
|
||||
return redirect_to_task_status(
|
||||
status,
|
||||
|
@ -124,12 +139,11 @@ class ActionSubmissionsView(BaseActionSubmissionsView):
|
|||
),
|
||||
)
|
||||
|
||||
def download_response(self, id_range, languages, results):
|
||||
if not self.request.user.is_superuser:
|
||||
raise Http404
|
||||
|
||||
def download_response(self, id_range, languages, results, contest):
|
||||
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 zipfile.ZipFile(tmp, "w", zipfile.ZIP_DEFLATED) as archive:
|
||||
|
@ -155,20 +169,20 @@ class ActionSubmissionsView(BaseActionSubmissionsView):
|
|||
)
|
||||
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")
|
||||
if action == "rejudge":
|
||||
return self.rejudge_response(id_range, languages, results)
|
||||
return self.rejudge_response(id_range, languages, results, contest)
|
||||
elif action == "download":
|
||||
return self.download_response(id_range, languages, results)
|
||||
return self.download_response(id_range, languages, results, contest)
|
||||
else:
|
||||
return Http404()
|
||||
|
||||
|
||||
class PreviewActionSubmissionsView(BaseActionSubmissionsView):
|
||||
def generate_response(self, id_range, languages, results):
|
||||
def generate_response(self, id_range, languages, results, contest):
|
||||
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()))
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: lqdoj2\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"
|
||||
"Last-Translator: Icyene\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"
|
||||
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
|
||||
msgid "%d submission 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"
|
||||
msgstr "Đang chạy MOSS"
|
||||
|
||||
#: judge/tasks/submission.py:45
|
||||
#: judge/tasks/submission.py:47
|
||||
msgid "Modifying submissions"
|
||||
msgstr "Chỉnh sửa bài nộp"
|
||||
|
||||
#: judge/tasks/submission.py:65
|
||||
#: judge/tasks/submission.py:67
|
||||
msgid "Recalculating user points"
|
||||
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"
|
||||
msgstr "Nộp bài cho %(problem)s"
|
||||
|
||||
#: judge/views/problem.py:1204
|
||||
#: judge/views/problem.py:1207
|
||||
msgid "Clone Problem"
|
||||
msgstr "Nhân bản bài tập"
|
||||
|
||||
|
@ -3143,17 +3143,17 @@ msgstr "File init.yml cho %s"
|
|||
msgid "Managing submissions for %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
|
||||
msgid "Rejudging selected submissions for %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
|
||||
msgid "Rescoring all submissions for %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
|
||||
msgid "Successfully scheduled %d submission 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:"
|
||||
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"
|
||||
msgstr "Hành động"
|
||||
|
||||
#: templates/problem/manage_submission.html:165
|
||||
#: templates/problem/manage_submission.html:169
|
||||
msgid "Rejudge selected submissions"
|
||||
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"
|
||||
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
|
||||
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?"
|
||||
|
||||
#: templates/problem/manage_submission.html:177
|
||||
#: templates/problem/manage_submission.html:181
|
||||
msgid "Rescore all submissions"
|
||||
msgstr "Tính điểm lại các bài nộp"
|
||||
|
||||
|
@ -5022,11 +5026,11 @@ msgstr "Lọc"
|
|||
msgid "Random"
|
||||
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."
|
||||
msgstr "Code phải chứa không quá 65536 ký tự."
|
||||
|
||||
#: templates/problem/submit.html:175
|
||||
#: templates/problem/submit.html:179
|
||||
#, python-format
|
||||
msgid ""
|
||||
"<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>, "
|
||||
"không được sử dụng trong bài này."
|
||||
|
||||
#: templates/problem/submit.html:186
|
||||
#: templates/problem/submit.html:190
|
||||
#, fuzzy, python-format
|
||||
#| msgid ""
|
||||
#| "\n"
|
||||
|
@ -5058,15 +5062,15 @@ msgstr[0] ""
|
|||
" 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"
|
||||
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."
|
||||
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!"
|
||||
msgstr "Nộp bài!"
|
||||
|
||||
|
|
|
@ -157,6 +157,10 @@
|
|||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
{% if in_contest %}
|
||||
<label for="in-contest" name="in_contest">{{ _('In current contest') }}:</label>
|
||||
<input type="checkbox" name="in_contest">
|
||||
{% endif %}
|
||||
</form>
|
||||
</div>
|
||||
<div class="pane">
|
||||
|
|
Loading…
Reference in a new issue