Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pridana validacia season code na semestri #453

Merged
merged 2 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.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)

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