Add duplication check for contest edit in group
This commit is contained in:
parent
0da2098bbe
commit
97d0239963
6 changed files with 64 additions and 25 deletions
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue