Add contest field to manage submission page

This commit is contained in:
cuom1999 2023-11-28 20:04:02 -06:00
parent 038aa8674a
commit e1054077fa
6 changed files with 96 additions and 70 deletions

View file

@ -467,7 +467,7 @@ class Contest(models.Model, PageVotable, Bookmarkable):
) )
def __str__(self): def __str__(self):
return self.name return f"{self.name} ({self.key})"
def get_absolute_url(self): def get_absolute_url(self):
return reverse("contest_view", args=(self.key,)) return reverse("contest_view", args=(self.key,))

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, contest): def apply_submission_filter(queryset, id_range, languages, results, contests):
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,8 +16,8 @@ def apply_submission_filter(queryset, id_range, languages, results, contest):
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: if contests:
queryset = queryset.filter(contest_object=contest) queryset = queryset.filter(contest_object__in=contests)
queryset = queryset.exclude(status__in=Submission.IN_PROGRESS_GRADING_STATUS) queryset = queryset.exclude(status__in=Submission.IN_PROGRESS_GRADING_STATUS)
return queryset return queryset

View file

@ -78,12 +78,12 @@ 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 context["current_contest"] = None
if ( if (
self.request.in_contest_mode self.request.in_contest_mode
and self.object in self.request.participation.contest.problems.all() and self.object in self.request.participation.contest.problems.all()
): ):
context["in_contest"] = True context["current_contest"] = self.request.participation.contest
return context return context
@ -106,20 +106,12 @@ class BaseActionSubmissionsView(
try: try:
languages = list(map(int, self.request.POST.getlist("language"))) languages = list(map(int, self.request.POST.getlist("language")))
results = list(map(int, self.request.POST.getlist("result")))
contests = list(map(int, self.request.POST.getlist("contest")))
except ValueError: except ValueError:
return HttpResponseBadRequest() return HttpResponseBadRequest()
contest = None return self.generate_response(id_range, languages, results, contests)
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"), contest
)
def generate_response(self, id_range, languages, results, contest): def generate_response(self, id_range, languages, results, contest):
raise NotImplementedError() raise NotImplementedError()

View file

@ -85,10 +85,17 @@ class ProblemSelect2View(Select2View):
class ContestSelect2View(Select2View): class ContestSelect2View(Select2View):
def get(self, request, *args, **kwargs):
self.problem_id = kwargs.get("problem_id", request.GET.get("problem_id", ""))
return super(ContestSelect2View, self).get(request, *args, **kwargs)
def get_queryset(self): def get_queryset(self):
return Contest.get_visible_contests(self.request.user).filter( q = Contest.get_visible_contests(self.request.user).filter(
Q(key__icontains=self.term) | Q(name__icontains=self.term) Q(key__icontains=self.term) | Q(name__icontains=self.term)
) )
if self.problem_id:
q = q.filter(problems=self.problem_id)
return q
class CommentSelect2View(Select2View): class CommentSelect2View(Select2View):

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-11-28 08:35+0700\n" "POT-Creation-Date: 2023-11-29 08:53+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"
@ -46,7 +46,7 @@ msgstr ""
msgid "Recent" msgid "Recent"
msgstr "Gần đây" msgstr "Gần đây"
#: chat_box/views.py:420 templates/base.html:187 #: chat_box/views.py:420 templates/base.html:189
#: templates/comments/content-list.html:78 #: templates/comments/content-list.html:78
#: templates/contest/contest-list-tabs.html:4 #: templates/contest/contest-list-tabs.html:4
#: templates/contest/ranking-table.html:47 #: templates/contest/ranking-table.html:47
@ -196,7 +196,7 @@ msgstr "Tính toán lại kết quả"
msgid "username" msgid "username"
msgstr "tên đăng nhập" msgstr "tên đăng nhập"
#: judge/admin/contest.py:504 templates/base.html:239 #: judge/admin/contest.py:504 templates/base.html:241
msgid "virtual" msgid "virtual"
msgstr "ảo" msgstr "ảo"
@ -409,7 +409,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:302 judge/views/problem_manage.py:226 #: judge/admin/submission.py:302 judge/views/problem_manage.py:228
#, 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."
@ -531,55 +531,55 @@ msgstr "Thành viên mới"
msgid "These usernames don't exist: {usernames}" msgid "These usernames don't exist: {usernames}"
msgstr "Các tên đăng nhập này không tồn tại: {usernames}" msgstr "Các tên đăng nhập này không tồn tại: {usernames}"
#: judge/forms.py:421 #: judge/forms.py:422
msgid "Username/Email" msgid "Username/Email"
msgstr "Tên đăng nhập / Email" msgstr "Tên đăng nhập / Email"
#: judge/forms.py:422 judge/views/email.py:22 #: judge/forms.py:424 judge/views/email.py:22
#: templates/registration/registration_form.html:46 #: templates/registration/registration_form.html:46
#: templates/registration/registration_form.html:60 #: templates/registration/registration_form.html:60
#: templates/user/edit-profile.html:108 templates/user/import/table_csv.html:5 #: templates/user/edit-profile.html:108 templates/user/import/table_csv.html:5
msgid "Password" msgid "Password"
msgstr "Mật khẩu" msgstr "Mật khẩu"
#: judge/forms.py:448 #: judge/forms.py:450
msgid "Two Factor Authentication tokens must be 6 decimal digits." msgid "Two Factor Authentication tokens must be 6 decimal digits."
msgstr "Two Factor Authentication phải chứa 6 chữ số." msgstr "Two Factor Authentication phải chứa 6 chữ số."
#: judge/forms.py:461 templates/registration/totp_auth.html:32 #: judge/forms.py:463 templates/registration/totp_auth.html:32
msgid "Invalid Two Factor Authentication token." msgid "Invalid Two Factor Authentication token."
msgstr "Token Two Factor Authentication không hợp lệ." msgstr "Token Two Factor Authentication không hợp lệ."
#: judge/forms.py:468 judge/models/problem.py:130 #: judge/forms.py:470 judge/models/problem.py:130
msgid "Problem code must be ^[a-z0-9]+$" msgid "Problem code must be ^[a-z0-9]+$"
msgstr "Mã bài phải có dạng ^[a-z0-9]+$" msgstr "Mã bài phải có dạng ^[a-z0-9]+$"
#: judge/forms.py:475 #: judge/forms.py:477
msgid "Problem with code already exists." msgid "Problem with code already exists."
msgstr "Mã bài đã tồn tại." msgstr "Mã bài đã tồn tại."
#: judge/forms.py:482 judge/models/contest.py:95 #: judge/forms.py:484 judge/models/contest.py:95
msgid "Contest id must be ^[a-z0-9]+$" msgid "Contest id must be ^[a-z0-9]+$"
msgstr "Mã kỳ thi phải có dạng ^[a-z0-9]+$" msgstr "Mã kỳ thi phải có dạng ^[a-z0-9]+$"
#: judge/forms.py:489 templates/contest/clone.html:47 #: judge/forms.py:491 templates/contest/clone.html:47
#: templates/problem/search-form.html:39 #: templates/problem/search-form.html:39
msgid "Group" msgid "Group"
msgstr "Nhóm" msgstr "Nhóm"
#: judge/forms.py:497 #: judge/forms.py:499
msgid "Contest with key already exists." msgid "Contest with key already exists."
msgstr "Mã kỳ thi đã tồn tại." msgstr "Mã kỳ thi đã tồn tại."
#: judge/forms.py:505 #: judge/forms.py:507
msgid "Group doesn't exist." msgid "Group doesn't exist."
msgstr "Nhóm không tồn tại." msgstr "Nhóm không tồn tại."
#: judge/forms.py:507 #: judge/forms.py:509
msgid "You don't have permission in this group." msgid "You don't have permission in this group."
msgstr "Bạn không có quyền trong nhóm này." msgstr "Bạn không có quyền trong nhóm này."
#: judge/forms.py:557 #: judge/forms.py:559
msgid "This problem is duplicated." msgid "This problem is duplicated."
msgstr "Bài này bị lặp" msgstr "Bài này bị lặp"
@ -3302,17 +3302,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:135 #: judge/views/problem_manage.py:137
#, 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:195 #: judge/views/problem_manage.py:197
#, 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:210 #: judge/views/problem_manage.py:212
#, 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."
@ -3568,7 +3568,7 @@ msgid "Updated on site"
msgstr "Được cập nhật trên web" msgstr "Được cập nhật trên web"
#: judge/views/user.py:431 templates/admin/auth/user/change_form.html:14 #: judge/views/user.py:431 templates/admin/auth/user/change_form.html:14
#: templates/admin/auth/user/change_form.html:17 templates/base.html:199 #: templates/admin/auth/user/change_form.html:17 templates/base.html:201
#: templates/user/user-tabs.html:11 #: templates/user/user-tabs.html:11
msgid "Edit profile" msgid "Edit profile"
msgstr "Chỉnh sửa thông tin" msgstr "Chỉnh sửa thông tin"
@ -3671,48 +3671,48 @@ msgstr "Chat"
msgid "Notification" msgid "Notification"
msgstr "Thông báo" msgstr "Thông báo"
#: templates/base.html:173 #: templates/base.html:174
msgid "Dark Mode" msgid "Dark Mode"
msgstr "" msgstr ""
#: templates/base.html:183 #: templates/base.html:185
msgid "Profile" msgid "Profile"
msgstr "Trang cá nhân" msgstr "Trang cá nhân"
#: templates/base.html:192 #: templates/base.html:194
msgid "Internal" msgid "Internal"
msgstr "Nội bộ" msgstr "Nội bộ"
#: templates/base.html:195 #: templates/base.html:197
msgid "Stats" msgid "Stats"
msgstr "Thống kê" msgstr "Thống kê"
#: templates/base.html:208 #: templates/base.html:210
msgid "Log out" msgid "Log out"
msgstr "Đăng xuất" msgstr "Đăng xuất"
#: templates/base.html:218 #: templates/base.html:220
#: templates/registration/password_reset_complete.html:4 #: templates/registration/password_reset_complete.html:4
msgid "Log in" msgid "Log in"
msgstr "Đăng nhập" msgstr "Đăng nhập"
#: templates/base.html:219 #: templates/base.html:221
msgid "Sign up" msgid "Sign up"
msgstr "Đăng ký" msgstr "Đăng ký"
#: templates/base.html:233 #: templates/base.html:235
msgid "spectating" msgid "spectating"
msgstr "đang theo dõi" msgstr "đang theo dõi"
#: templates/base.html:245 #: templates/base.html:247
msgid "Compete" msgid "Compete"
msgstr "Thi" msgstr "Thi"
#: templates/base.html:247 #: templates/base.html:249
msgid "General" msgid "General"
msgstr "Chung" msgstr "Chung"
#: templates/base.html:254 #: templates/base.html:256
msgid "This site works best with JavaScript enabled." msgid "This site works best with JavaScript enabled."
msgstr "" msgstr ""
@ -4823,79 +4823,87 @@ msgstr "Để trống nếu không lọc theo ngôn ngữ"
msgid "Leave empty to not filter by result" msgid "Leave empty to not filter by result"
msgstr "Để trống nếu không lọc theo kết quả" msgstr "Để trống nếu không lọc theo kết quả"
#: templates/problem/manage_submission.html:79 #: templates/problem/manage_submission.html:64
msgid "Leave empty to not filter by contest"
msgstr "Để trống nếu không lọc theo kỳ thi"
#: templates/problem/manage_submission.html:94
msgid "Need valid values for both start and end IDs." msgid "Need valid values for both start and end IDs."
msgstr "Cần số liệu hợp lệ cho ID bắt đầu và kết thúc." msgstr "Cần số liệu hợp lệ cho ID bắt đầu và kết thúc."
#: templates/problem/manage_submission.html:82 #: templates/problem/manage_submission.html:97
msgid "End ID must be after start ID." msgid "End ID must be after start ID."
msgstr "ID kết thúc phải lớn hơn hoặc bằng ID khởi đầu." msgstr "ID kết thúc phải lớn hơn hoặc bằng ID khởi đầu."
#: templates/problem/manage_submission.html:95 #: templates/problem/manage_submission.html:110
#, python-brace-format #, python-brace-format
msgid "" msgid ""
"You are about to {action} {count} submissions. Are you sure you want to do " "You are about to {action} {count} submissions. Are you sure you want to do "
"this?" "this?"
msgstr "Bạn chuẩn bị {action} {count} bài nộp. Tiếp tục?" msgstr "Bạn chuẩn bị {action} {count} bài nộp. Tiếp tục?"
#: templates/problem/manage_submission.html:102 #: templates/problem/manage_submission.html:117
#, python-brace-format #, python-brace-format
msgid "" msgid ""
"You are about to {action} a few submissions. Are you sure you want to do " "You are about to {action} a few submissions. Are you sure you want to do "
"this?" "this?"
msgstr "Bạn chuẩn bị {action} vài bài nộp. Tiếp tục?" msgstr "Bạn chuẩn bị {action} vài bài nộp. Tiếp tục?"
#: templates/problem/manage_submission.html:126 #: templates/problem/manage_submission.html:141
#: templates/submission/list.html:337 #: templates/submission/list.html:337
msgid "Filter submissions" msgid "Filter submissions"
msgstr "Lọc bài nộp" msgstr "Lọc bài nộp"
#: templates/problem/manage_submission.html:131 #: templates/problem/manage_submission.html:146
msgid "Filter by ID:" msgid "Filter by ID:"
msgstr "Lọc theo ID:" msgstr "Lọc theo ID:"
#: templates/problem/manage_submission.html:134 #: templates/problem/manage_submission.html:149
msgid "Starting ID:" msgid "Starting ID:"
msgstr "ID bắt đầu:" msgstr "ID bắt đầu:"
#: templates/problem/manage_submission.html:138 #: templates/problem/manage_submission.html:153
msgid "Ending ID:" msgid "Ending ID:"
msgstr "ID kết thúc:" msgstr "ID kết thúc:"
#: templates/problem/manage_submission.html:142 #: templates/problem/manage_submission.html:157
msgid "This range includes both endpoints." msgid "This range includes both endpoints."
msgstr "Bao gồm hai đầu mút." msgstr "Bao gồm hai đầu mút."
#: templates/problem/manage_submission.html:145 #: templates/problem/manage_submission.html:160
msgid "Filter by language:" msgid "Filter by language:"
msgstr "Lọc theo ngôn ngữ:" msgstr "Lọc theo ngôn ngữ:"
#: templates/problem/manage_submission.html:153 #: templates/problem/manage_submission.html:168
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:161 #: templates/problem/manage_submission.html:176
msgid "In current contest" msgid "In current contest"
msgstr "Trong kỳ thi hiện tại" msgstr "Trong kỳ thi hiện tại"
#: templates/problem/manage_submission.html:167 #: templates/problem/manage_submission.html:180
msgid "Filter by contest:"
msgstr "Lọc theo kỳ thi:"
#: templates/problem/manage_submission.html:188
msgid "Action" msgid "Action"
msgstr "Hành động" msgstr "Hành động"
#: templates/problem/manage_submission.html:169 #: templates/problem/manage_submission.html:190
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:174 #: templates/problem/manage_submission.html:195
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:180 #: templates/problem/manage_submission.html:201
#, 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:181 #: templates/problem/manage_submission.html:202
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"

View file

@ -59,6 +59,21 @@
placeholder: '{{ _('Leave empty to not filter by result') }}' placeholder: '{{ _('Leave empty to not filter by result') }}'
}); });
$('#by-contest-filter').select2({
multiple: true,
placeholder: '{{ _('Leave empty to not filter by contest') }}',
ajax: {
url: "{{url('contest_select2')}}",
data: function(params) {
return {
term: params.term,
problem_id: {{problem.id}}
};
},
delay: 250,
}
});
$('#rescore-all').click(function (e) { $('#rescore-all').click(function (e) {
e.preventDefault(); e.preventDefault();
if (confirm(this.dataset.warning)) { if (confirm(this.dataset.warning)) {
@ -157,10 +172,14 @@
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
{% if in_contest %} <div class="control-group">
<label for="in-contest" name="in_contest">{{ _('In current contest') }}:</label> <label for="by-contest-filter">{{ _('Filter by contest:') }}</label>
<input type="checkbox" name="in_contest"> <select id="by-contest-filter" name="contest" multiple>
{% endif %} {% if current_contest %}
<option selected value="{{current_contest.id}}">{{ current_contest }}</option>
{% endif %}
</select>
</div>
</form> </form>
</div> </div>
<div class="pane"> <div class="pane">