Skip to content

Commit

Permalink
Delete contest in form before adding
Browse files Browse the repository at this point in the history
  • Loading branch information
cuom1999 committed Sep 3, 2024
1 parent a230441 commit 88845ae
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 8 additions & 1 deletion judge/models/contest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
MOSS_LANG_PYTHON,
MOSS_LANG_PASCAL,
)
from datetime import timedelta
from datetime import timedelta, datetime

from judge import contest_format
from judge.models.problem import Problem
Expand Down Expand Up @@ -371,6 +371,13 @@ def clean(self):
)

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)
if self.end_time > one_year_later:
self.end_time = one_year_later
Expand Down
7 changes: 5 additions & 2 deletions judge/views/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,12 +991,15 @@ def post(self, request, *args, **kwargs):
return res
problem_formset = self.get_problem_formset(True)
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):
if problem_form:
problem_form.contest = self.contest
problem_form.save()
for problem_form in problem_formset.deleted_objects:
problem_form.delete()

super().post(request, *args, **kwargs)
return HttpResponseRedirect(
reverse(
Expand Down

0 comments on commit 88845ae

Please sign in to comment.