Skip to content

Commit

Permalink
Pridana validacia season code na semestri
Browse files Browse the repository at this point in the history
  • Loading branch information
kovacspe committed Nov 24, 2024
1 parent b1c9959 commit 85083bb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions competition/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions competition/serializers.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 85083bb

Please sign in to comment.