tournament: add: les crampte
This commit is contained in:
@ -1,15 +1,13 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from django.db.models.query import QuerySet
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from .models import TournamentModel
|
||||
|
||||
from profiles.models import ProfileModel
|
||||
from profiles.serializers.ProfileSerializer import ProfileSerializer
|
||||
from games.serializers import GameSerializer
|
||||
|
||||
nb_participants = [2 ** i for i in range(2, 6)]
|
||||
|
||||
class TournamentSerializer(serializers.ModelSerializer):
|
||||
|
||||
state = serializers.SerializerMethodField(read_only=True, required=False)
|
||||
@ -30,16 +28,6 @@ class TournamentSerializer(serializers.ModelSerializer):
|
||||
return ["waiting", "started", "finished"][instance.started + instance.finished]
|
||||
|
||||
def validate_nb_participants(self, value: int):
|
||||
if (value < 2):
|
||||
raise serializers.ValidationError("The numbers of participants must be greather than 2.")
|
||||
return value
|
||||
|
||||
def validate_nb_participants_by_game(self, value: int):
|
||||
if (value < 2):
|
||||
raise serializers.ValidationError("The numbers of participants by game must be greather than 2.")
|
||||
nb_participants: str = self.initial_data.get("nb_participants")
|
||||
if (nb_participants is not None and nb_participants.isnumeric()):
|
||||
nb_participants: int = int(nb_participants)
|
||||
if (value > nb_participants):
|
||||
raise serializers.ValidationError("The numbers of participants by game must be smaller than the numbers of participants.")
|
||||
if (value not in nb_participants):
|
||||
raise serializers.ValidationError(f"The numbers of participants must be {str(nb_participants)}.")
|
||||
return value
|
Reference in New Issue
Block a user