Delete contest in form before adding

This commit is contained in:
cuom1999 2024-09-03 10:48:01 -05:00
parent a230441862
commit 88845aebd8
2 changed files with 13 additions and 3 deletions

View file

@ -19,7 +19,7 @@ from moss import (
MOSS_LANG_PYTHON, MOSS_LANG_PYTHON,
MOSS_LANG_PASCAL, MOSS_LANG_PASCAL,
) )
from datetime import timedelta from datetime import timedelta, datetime
from judge import contest_format from judge import contest_format
from judge.models.problem import Problem from judge.models.problem import Problem
@ -371,6 +371,13 @@ class Contest(models.Model, PageVotable, Bookmarkable):
) )
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
earliest_start_time = datetime(2020, 1, 1).replace(tzinfo=timezone.utc)
if self.start_time < earliest_start_time:
self.start_time = earliest_start_time
if self.end_time < self.start_time:
self.end_time = self.start_time + timedelta(hours=1)
one_year_later = self.start_time + timedelta(days=365) one_year_later = self.start_time + timedelta(days=365)
if self.end_time > one_year_later: if self.end_time > one_year_later:
self.end_time = one_year_later self.end_time = one_year_later

View file

@ -991,12 +991,15 @@ class EditOrganizationContest(
return res return res
problem_formset = self.get_problem_formset(True) problem_formset = self.get_problem_formset(True)
if problem_formset.is_valid(): if problem_formset.is_valid():
for problem_form in problem_formset:
if problem_form.cleaned_data.get("DELETE") and problem_form.instance.pk:
problem_form.instance.delete()
for problem_form in problem_formset.save(commit=False): for problem_form in problem_formset.save(commit=False):
if problem_form: if problem_form:
problem_form.contest = self.contest problem_form.contest = self.contest
problem_form.save() problem_form.save()
for problem_form in problem_formset.deleted_objects:
problem_form.delete()
super().post(request, *args, **kwargs) super().post(request, *args, **kwargs)
return HttpResponseRedirect( return HttpResponseRedirect(
reverse( reverse(