From 85083bb45159d790f3df112f056e01bf20a169c8 Mon Sep 17 00:00:00 2001 From: kovacspe Date: Sun, 24 Nov 2024 02:00:23 +0100 Subject: [PATCH 1/2] Pridana validacia season code na semestri --- competition/models.py | 7 +++++++ competition/serializers.py | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/competition/models.py b/competition/models.py index 99da75d..d451a4f 100644 --- a/competition/models.py +++ b/competition/models.py @@ -3,6 +3,7 @@ from django.conf import settings from django.contrib.sites.models import Site +from django.core.exceptions import ValidationError from django.core.files.storage import FileSystemStorage from django.core.validators import validate_slug from django.db import models @@ -236,6 +237,12 @@ class Meta: blank=True, default=None) + def clean(self) -> None: + if self.season_code == 2: + raise ValidationError( + 'Seminár musí byť zimný alebo letný(season_code 0 alebo 1)') + return super().clean() + def save(self, *args, **kwargs) -> None: if not self.frozen_results: self.frozen_results = None diff --git a/competition/serializers.py b/competition/serializers.py index b39c517..d20e541 100644 --- a/competition/serializers.py +++ b/competition/serializers.py @@ -1,6 +1,7 @@ from django.contrib.auth.models import AnonymousUser from django_typomatic import ts_interface from rest_framework import serializers +from rest_framework.exceptions import ValidationError from competition import models from personal.serializers import ProfileShortSerializer, SchoolShortSerializer @@ -392,6 +393,13 @@ class Meta: model = models.Semester exclude = ['frozen_results', 'registration_link'] read_only_fields = ['complete'] + validators = [] + + def validate(self, attrs): + if attrs['season_code'] not in (0, 1): + raise ValidationError( + 'Seminár musí byť zimný alebo letný(season_code 0 alebo 1)') + return super().validate(attrs) def get_complete(self, obj: models.Semester): return obj.complete From 730763e222b2795c8d2ff4d76b38e21b5f2b6676 Mon Sep 17 00:00:00 2001 From: kovacspe Date: Sun, 24 Nov 2024 02:05:54 +0100 Subject: [PATCH 2/2] Ohandlovane chybajuce season_code --- competition/serializers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/competition/serializers.py b/competition/serializers.py index d20e541..c90ce14 100644 --- a/competition/serializers.py +++ b/competition/serializers.py @@ -396,7 +396,7 @@ class Meta: validators = [] def validate(self, attrs): - if attrs['season_code'] not in (0, 1): + if attrs.get('season_code', 0) not in (0, 1): raise ValidationError( 'Seminár musí byť zimný alebo letný(season_code 0 alebo 1)') return super().validate(attrs)