From 4dd68654c0749bac3823a1a12b4e33b1a9f0291f Mon Sep 17 00:00:00 2001 From: kovacspe Date: Sat, 14 Dec 2024 19:43:12 +0100 Subject: [PATCH] Check school year only if it is present --- competition/serializers.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/competition/serializers.py b/competition/serializers.py index 5864adb..36f4add 100644 --- a/competition/serializers.py +++ b/competition/serializers.py @@ -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):