Skip to content

Commit

Permalink
Check school year only if it is present
Browse files Browse the repository at this point in the history
  • Loading branch information
kovacspe committed Dec 14, 2024
1 parent 67bc3ca commit 4dd6865
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions competition/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,15 +449,16 @@ def validate_school_year(self, value: str):

def validate(self, attrs):
school_year = attrs.get('school_year')
start_year, end_year = school_year.split('/')
start = attrs.get('start')
end = attrs.get('end')
if start and start.date() < datetime.date(year=int(start_year), month=7, day=1):
raise ValidationError(
f'Začiatok súťaže ({start}) nie je v školskom roku {school_year}')
if end and end.date() > datetime.date(year=int(end_year), month=8, day=31):
raise ValidationError(
f'Koniec súťaže ({end}) nie je v školskom roku {school_year}')
if school_year is not None:
start = attrs.get('start')
end = attrs.get('end')
start_year, end_year = school_year.split('/')
if start and start.date() < datetime.date(year=int(start_year), month=7, day=1):
raise ValidationError(
f'Začiatok súťaže ({start}) nie je v školskom roku {school_year}')
if end and end.date() > datetime.date(year=int(end_year), month=8, day=31):
raise ValidationError(
f'Koniec súťaže ({end}) nie je v školskom roku {school_year}')
return super().validate(attrs)

def get_complete(self, obj: models.Semester):
Expand Down

0 comments on commit 4dd6865

Please sign in to comment.