Skip to content

Commit

Permalink
Pridana validácia datumov na event
Browse files Browse the repository at this point in the history
  • Loading branch information
kovacspe committed Dec 14, 2024
1 parent aafd56f commit 67bc3ca
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions competition/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,26 @@ class Meta:
model = models.Event
fields = '__all__'

def validate_school_year(self, value: str):
try:
school_year_validator(value)
return value
except exceptions.ValidationError as exc:
raise ValidationError('Nesprávny formát šk. roku') from exc

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}')
return super().validate(attrs)

def create(self, validated_data):
registration_link = validated_data.pop('registration_link', None)

Expand Down

0 comments on commit 67bc3ca

Please sign in to comment.