Skip to content

Commit

Permalink
Add end time limit to a contest
Browse files Browse the repository at this point in the history
  • Loading branch information
cuom1999 committed Aug 14, 2024
1 parent 1f91299 commit 37cdd2d
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 211 deletions.
12 changes: 9 additions & 3 deletions judge/models/contest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
MOSS_LANG_PYTHON,
MOSS_LANG_PASCAL,
)
from datetime import timedelta

from judge import contest_format
from judge.models.problem import Problem
Expand Down Expand Up @@ -354,9 +355,7 @@ def DENY_ALL(obj, attr_name, is_setting):
def clean(self):
# Django will complain if you didn't fill in start_time or end_time, so we don't have to.
if self.start_time and self.end_time and self.start_time >= self.end_time:
raise ValidationError(
"What is this? A contest that ended before it starts?"
)
raise ValidationError(_("End time must be after start time"))
self.format_class.validate(self.format_config)

try:
Expand All @@ -371,6 +370,13 @@ def clean(self):
"Contest problem label script: script should return a string."
)

def save(self, *args, **kwargs):
one_year_later = self.start_time + timedelta(days=365)
if self.end_time > one_year_later:
self.end_time = one_year_later

super().save(*args, **kwargs)

def is_in_contest(self, user):
if user.is_authenticated:
profile = user.profile
Expand Down
Loading

0 comments on commit 37cdd2d

Please sign in to comment.