diff --git a/judge/forms.py b/judge/forms.py index 5bc43a9..32fc75e 100644 --- a/judge/forms.py +++ b/judge/forms.py @@ -538,9 +538,37 @@ class ContestProblemForm(ModelForm): } +class ContestProblemModelFormSet(BaseModelFormSet): + def is_valid(self): + valid = super().is_valid() + + if not valid: + return valid + + problems = set() + duplicates = [] + + for form in self.forms: + if form.cleaned_data and not form.cleaned_data.get("DELETE", False): + problem = form.cleaned_data.get("problem") + if problem in problems: + duplicates.append(problem) + else: + problems.add(problem) + + if duplicates: + for form in self.forms: + problem = form.cleaned_data.get("problem") + if problem in duplicates: + form.add_error("problem", _("This problem is duplicated.")) + return False + + return True + + class ContestProblemFormSet( formset_factory( - ContestProblemForm, formset=BaseModelFormSet, extra=6, can_delete=True + ContestProblemForm, formset=ContestProblemModelFormSet, extra=6, can_delete=True ) ): model = ContestProblem diff --git a/judge/views/organization.py b/judge/views/organization.py index 962be71..0576afe 100644 --- a/judge/views/organization.py +++ b/judge/views/organization.py @@ -926,8 +926,12 @@ class EditOrganizationContest( super().post(request, *args, **kwargs) return HttpResponseRedirect( reverse( - "organization_contests", - args=(self.organization_id, self.organization.slug), + "organization_contest_edit", + args=( + self.organization_id, + self.organization.slug, + self.contest.key, + ), ) ) diff --git a/locale/vi/LC_MESSAGES/django.po b/locale/vi/LC_MESSAGES/django.po index d1e8a78..0cb9282 100644 --- a/locale/vi/LC_MESSAGES/django.po +++ b/locale/vi/LC_MESSAGES/django.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: lqdoj2\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-08-26 03:42+0700\n" +"POT-Creation-Date: 2023-08-26 05:31+0700\n" "PO-Revision-Date: 2021-07-20 03:44\n" "Last-Translator: Icyene\n" "Language-Team: Vietnamese\n" @@ -555,6 +555,10 @@ msgstr "" msgid "You don't have permission in this group." msgstr "Bạn không có quyền chấm lại bài." +#: judge/forms.py:563 +msgid "This problem is duplicated." +msgstr "Bài này bị lặp" + #: judge/jinja2/datetime.py:26 templates/blog/blog.html:28 #: templates/blog/dashboard.html:21 msgid "N j, Y, g:i a" @@ -2883,19 +2887,19 @@ msgstr "Thay đổi Email" msgid "Change Email" msgstr "Thay đổi Email" -#: judge/views/email.py:65 templates/user/edit-profile.html:120 +#: judge/views/email.py:71 templates/user/edit-profile.html:120 msgid "Change email" msgstr "Thay đổi email" -#: judge/views/email.py:89 +#: judge/views/email.py:94 msgid "Success" msgstr "Thành công" -#: judge/views/email.py:93 +#: judge/views/email.py:98 msgid "Invalid" msgstr "Không hợp lệ" -#: judge/views/email.py:102 +#: judge/views/email.py:107 msgid "Email change pending" msgstr "Yêu cầu thay đổi email đang đợi xác thực." @@ -4426,8 +4430,8 @@ msgstr "Hoạt động" #: templates/organization/blog/edit.html:36 #: templates/organization/contest/add.html:36 -#: templates/organization/contest/edit.html:87 -#: templates/organization/form.html:24 +#: templates/organization/contest/edit.html:86 +#: templates/organization/form.html:23 msgid "Save" msgstr "Lưu" @@ -4441,12 +4445,15 @@ msgid "Author" msgstr "Tác giả" #: templates/organization/blog/pending.html:14 -#, fuzzy -#| msgid "posted time" msgid "Post time" -msgstr "thời gian đăng" +msgstr "Thời gian đăng" -#: templates/organization/contest/edit.html:61 +#: templates/organization/contest/edit.html:40 +#: templates/organization/form.html:6 +msgid "Please fix below errors" +msgstr "Vui lòng sửa các lỗi bên dưới" + +#: templates/organization/contest/edit.html:60 msgid "If you run out of rows, click Save" msgstr "Ấn nút lưu lại nếu cần thêm hàng" diff --git a/resources/widgets.scss b/resources/widgets.scss index f33882d..085d508 100644 --- a/resources/widgets.scss +++ b/resources/widgets.scss @@ -606,6 +606,14 @@ ul.select2-selection__rendered { background: gray; } +ul.errorlist { + margin: 0px; + text-align: right; + list-style: none; + padding: 0px; + color: red; +} + .registration-form { .sortedm2m-container, .sortedm2m-container p.selector-filter { width: 300px; @@ -682,12 +690,6 @@ ul.select2-selection__rendered { width: 450px; } - ul.errorlist { - margin: 0px; - text-align: right; - list-style: none; - } - .full-textfield { padding-top: 0.5em; } diff --git a/templates/organization/contest/edit.html b/templates/organization/contest/edit.html index 101bfbf..5682504 100644 --- a/templates/organization/contest/edit.html +++ b/templates/organization/contest/edit.html @@ -34,11 +34,10 @@ {% block middle_content %}