diff --git a/insalan/tournament/admin.py b/insalan/tournament/admin.py index fb28c49d..d2a7eea2 100644 --- a/insalan/tournament/admin.py +++ b/insalan/tournament/admin.py @@ -27,8 +27,14 @@ from django.utils.decorators import method_decorator from insalan.mailer import MailManager -from .models import Event, Tournament, Game, Team, Player, Manager, Substitute, Caster, PaymentStatus, Group, GroupMatch, KnockoutMatch, Bracket, Seeding, MatchStatus, Score, SwissRound, SwissMatch, SwissSeeding, BestofType, BracketSet, TournamentMailer -from insalan.tournament.manage import create_group_matchs, create_empty_knockout_matchs, create_swiss_matchs +from .models import (Event, Tournament, Game, Team, Player, Manager, + Substitute, Caster, PaymentStatus, Group, GroupMatch, + KnockoutMatch, Bracket, Seeding, MatchStatus, Score, + SwissRound, SwissMatch, SwissSeeding, BestofType, + BracketSet, TournamentMailer, Seating) +from insalan.tournament.manage import (create_group_matchs, + create_empty_knockout_matchs, + create_swiss_matchs) sensitive_post_parameters_m = method_decorator(sensitive_post_parameters()) @@ -39,6 +45,7 @@ 'Game', 'Tournament', 'Team', + 'Seating', 'Player', 'Manager', 'Substitute', @@ -856,3 +863,15 @@ def launch_swiss_matchs_action(self,request,queryset): self.message_user(request,_("Les matchs ont bien été lancés")) admin.site.register(SwissMatch, SwissMatchAdmin) + + +class SeatingAdmin(admin.ModelAdmin): + """Admin handler for Seating""" + + list_display = ("id", "event", "tournament", "team") + search_fields = ["event", "tournament", "team"] + + list_filter = ["tournament", "tournament__event", "tournament__game"] + + +admin.site.register(Seating, SeatingAdmin) diff --git a/insalan/tournament/models/__init__.py b/insalan/tournament/models/__init__.py index 9054f511..b8dac903 100644 --- a/insalan/tournament/models/__init__.py +++ b/insalan/tournament/models/__init__.py @@ -12,5 +12,6 @@ from .team import Team from .tournament import Tournament, in_thirty_days from .mailer import TournamentMailer +from .seating import Seating from .validators import * \ No newline at end of file diff --git a/insalan/tournament/models/seating.py b/insalan/tournament/models/seating.py new file mode 100644 index 00000000..6b30086b --- /dev/null +++ b/insalan/tournament/models/seating.py @@ -0,0 +1,52 @@ +from django.db import models +from django.utils.translation import gettext_lazy as _ + + +class Seating(models.Model): + """ + Represents a single seat + """ + + event = models.ForeignKey( + "Event", + null=False, + blank=False, + on_delete=models.CASCADE, + verbose_name=_("Évènement"), + ) + x = models.IntegerField( + null=False, + blank=False, + verbose_name=_("Position horizontale"), + ) + y = models.IntegerField( + null=False, + blank=False, + verbose_name=_("Position verticale"), + ) + + tournament = models.ForeignKey( + "Tournament", + null=True, + blank=True, + on_delete=models.CASCADE, + verbose_name=_("Tournoi"), + ) + team = models.ForeignKey( + "Team", + null=True, + blank=True, + on_delete=models.CASCADE, + verbose_name=_("Équipe"), + ) + + class Meta: + """Meta Options""" + + verbose_name = _("Place") + verbose_name_plural = _("Places") + constraints = [ + models.UniqueConstraint( + fields=["event", "x", "y"], name="one_seat_per_position_per_event" + ) + ] diff --git a/insalan/tournament/serializers.py b/insalan/tournament/serializers.py index 54138df6..c70ae75a 100644 --- a/insalan/tournament/serializers.py +++ b/insalan/tournament/serializers.py @@ -11,8 +11,13 @@ from insalan.user.models import User -from .models import Event, Tournament, Game, Team, Player, Manager, Substitute, Caster, Group, GroupMatch, Bracket, KnockoutMatch, SwissRound, SwissMatch, Score -from .models import unique_event_registration_validator, tournament_announced, max_players_per_team_reached, tournament_registration_full, max_substitue_per_team_reached, valid_name +from .models import (Event, Tournament, Game, Team, Player, Manager, + Substitute, Caster, Group, GroupMatch, Bracket, + KnockoutMatch, SwissRound, SwissMatch, Score, Seating) +from .models import (unique_event_registration_validator, tournament_announced, + max_players_per_team_reached, + tournament_registration_full, + max_substitue_per_team_reached, valid_name) class ScoreSerializer(serializers.ModelSerializer): @@ -415,6 +420,15 @@ class Meta: def to_representation(self, instance): """Turn a Django object into a serialized representation""" return instance.id + +class SeatingSerializer(serializers.ModelSerializer): + """Serializer for a Seating""" + + class Meta: + """Meta options for the serializer""" + + model = Seating + fields = "__all__" class FullDerefSwissMatchSerializer(serializers.ModelSerializer): """Serializer for a Swiss Match in a tournament""" diff --git a/insalan/tournament/views/tournament.py b/insalan/tournament/views/tournament.py index 404600f3..bd49fcab 100644 --- a/insalan/tournament/views/tournament.py +++ b/insalan/tournament/views/tournament.py @@ -14,7 +14,11 @@ from insalan.user.models import User import insalan.tournament.serializers as serializers -from ..models import Player, Manager, Substitute, Event, Tournament, Game, Team, PaymentStatus, Group, Bracket, SwissRound, GroupMatch, KnockoutMatch, SwissMatch, Seeding, Score, BracketType, BracketSet, MatchStatus, BestofType, SwissSeeding +from ..models import (Player, Manager, Substitute, Event, Tournament, Game, + Team, PaymentStatus, Group, Bracket, SwissRound, + GroupMatch, KnockoutMatch, SwissMatch, Seeding, Score, + BracketType, BracketSet, MatchStatus, BestofType, + SwissSeeding, Seating) from .permissions import ReadOnly, Patch from rest_framework.exceptions import NotFound @@ -350,6 +354,10 @@ def get(self, request, primary_key: int): swiss["teams"] = SwissSeeding.objects.filter(swiss=swiss["id"]).values_list("team", flat=True) + tourney_serialized["seatings"] = serializers.SeatingSerializer( + Seating.objects.filter(tournament=tourney), context={"request": request}, many=True + ).data + return Response(tourney_serialized, status=status.HTTP_200_OK)