diff --git a/insalan/tournament/admin.py b/insalan/tournament/admin.py index d2a7eea2..3235c94b 100644 --- a/insalan/tournament/admin.py +++ b/insalan/tournament/admin.py @@ -31,7 +31,7 @@ Substitute, Caster, PaymentStatus, Group, GroupMatch, KnockoutMatch, Bracket, Seeding, MatchStatus, Score, SwissRound, SwissMatch, SwissSeeding, BestofType, - BracketSet, TournamentMailer, Seating) + BracketSet, TournamentMailer, Seat, SeatSlot) from insalan.tournament.manage import (create_group_matchs, create_empty_knockout_matchs, create_swiss_matchs) @@ -45,7 +45,8 @@ 'Game', 'Tournament', 'Team', - 'Seating', + 'Seat', + 'SeatSlot', 'Player', 'Manager', 'Substitute', @@ -865,13 +866,23 @@ def launch_swiss_matchs_action(self,request,queryset): admin.site.register(SwissMatch, SwissMatchAdmin) -class SeatingAdmin(admin.ModelAdmin): +# TODO: better admin for seating +class SeatAdmin(admin.ModelAdmin): """Admin handler for Seating""" - list_display = ("id", "event", "tournament", "team") - search_fields = ["event", "tournament", "team"] + list_display = ("id", "slot", "x", "y") + search_fields = ["event", "slot"] - list_filter = ["tournament", "tournament__event", "tournament__game"] + list_filter = ["event"] -admin.site.register(Seating, SeatingAdmin) +admin.site.register(Seat, SeatAdmin) + +class SeatSlotAdmin(admin.ModelAdmin): + """Admin handler for SeatSlot""" + list_display = ("id", "tournament", "team") + search_fields = ["tournament", "team"] + list_filter = ["tournament"] + +admin.site.register(SeatSlot, SeatSlotAdmin) + diff --git a/insalan/tournament/models/__init__.py b/insalan/tournament/models/__init__.py index b8dac903..23cd592c 100644 --- a/insalan/tournament/models/__init__.py +++ b/insalan/tournament/models/__init__.py @@ -12,6 +12,7 @@ from .team import Team from .tournament import Tournament, in_thirty_days from .mailer import TournamentMailer -from .seating import Seating +from .seat import Seat +from .seat_slot import SeatSlot -from .validators import * \ No newline at end of file +from .validators import * diff --git a/insalan/tournament/models/seating.py b/insalan/tournament/models/seat.py similarity index 73% rename from insalan/tournament/models/seating.py rename to insalan/tournament/models/seat.py index 6b30086b..604721b8 100644 --- a/insalan/tournament/models/seating.py +++ b/insalan/tournament/models/seat.py @@ -2,7 +2,7 @@ from django.utils.translation import gettext_lazy as _ -class Seating(models.Model): +class Seat(models.Model): """ Represents a single seat """ @@ -14,6 +14,13 @@ class Seating(models.Model): on_delete=models.CASCADE, verbose_name=_("Évènement"), ) + slot = models.ForeignKey( + "SeatSlot", + null=False, + blank=False, + on_delete=models.CASCADE, + verbose_name=_("Slot"), + ) x = models.IntegerField( null=False, blank=False, @@ -25,21 +32,6 @@ class Seating(models.Model): 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""" @@ -50,3 +42,6 @@ class Meta: fields=["event", "x", "y"], name="one_seat_per_position_per_event" ) ] + + def __str__(self): + return f"{self.event} - {self.slot} - ({self.x}, {self.y})" diff --git a/insalan/tournament/models/seat_slot.py b/insalan/tournament/models/seat_slot.py new file mode 100644 index 00000000..0c4bd149 --- /dev/null +++ b/insalan/tournament/models/seat_slot.py @@ -0,0 +1,28 @@ +from django.db import models +from django.utils.translation import gettext_lazy as _ + + +class SeatSlot(models.Model): + """ + Represents a single seat + """ + tournament = models.ForeignKey( + "Tournament", + null=False, + blank=False, + on_delete=models.CASCADE, + verbose_name=_("Tournoi"), + ) + team = models.ForeignKey( + "Team", + null=True, + blank=True, + on_delete=models.SET_NULL, + verbose_name=_("Équipe"), + ) + + class Meta: + """Meta Options""" + + verbose_name = _("Slot") + verbose_name_plural = _("Slots") diff --git a/insalan/tournament/serializers.py b/insalan/tournament/serializers.py index c70ae75a..b8c188cf 100644 --- a/insalan/tournament/serializers.py +++ b/insalan/tournament/serializers.py @@ -13,7 +13,8 @@ from .models import (Event, Tournament, Game, Team, Player, Manager, Substitute, Caster, Group, GroupMatch, Bracket, - KnockoutMatch, SwissRound, SwissMatch, Score, Seating) + KnockoutMatch, SwissRound, SwissMatch, Score, Seat, + SeatSlot) from .models import (unique_event_registration_validator, tournament_announced, max_players_per_team_reached, tournament_registration_full, @@ -421,13 +422,13 @@ def to_representation(self, instance): """Turn a Django object into a serialized representation""" return instance.id -class SeatingSerializer(serializers.ModelSerializer): +class SeatSlotSerializer(serializers.ModelSerializer): """Serializer for a Seating""" class Meta: """Meta options for the serializer""" - model = Seating + model = SeatSlot fields = "__all__" class FullDerefSwissMatchSerializer(serializers.ModelSerializer): diff --git a/insalan/tournament/tests.py b/insalan/tournament/tests.py index 8a3ce476..f55fb943 100644 --- a/insalan/tournament/tests.py +++ b/insalan/tournament/tests.py @@ -22,7 +22,7 @@ Tournament, Event, Game, - Seating, + SeatSlot, ) from insalan.user.models import User @@ -1151,14 +1151,11 @@ def test_example(self): sub = Substitute.objects.create(user=uobj_four, team=team_one, name_in_game="substitute") team_one.save() - seat_one = Seating.objects.create( - event=evobj, - x=1, - y=1, + seatslot_one = SeatSlot.objects.create( tournament=tourneyobj_one, team=team_one ) - seat_one.save() + seatslot_one.save() request = self.client.get( reverse("tournament/details-full", args=[tourneyobj_one.id]), format="json" @@ -1230,12 +1227,9 @@ def test_example(self): "groups" : [], "brackets" : [], "swissRounds" : [], - "seatings": [ + "seatslots": [ { - "id": seat_one.id, - "x": 1, - "y": 1, - "event": evobj.id, + "id": seatslot_one.id, "tournament": tourneyobj_one.id, "team": team_one.id } diff --git a/insalan/tournament/views/tournament.py b/insalan/tournament/views/tournament.py index bd49fcab..181a76b3 100644 --- a/insalan/tournament/views/tournament.py +++ b/insalan/tournament/views/tournament.py @@ -18,7 +18,7 @@ Team, PaymentStatus, Group, Bracket, SwissRound, GroupMatch, KnockoutMatch, SwissMatch, Seeding, Score, BracketType, BracketSet, MatchStatus, BestofType, - SwissSeeding, Seating) + SwissSeeding, SeatSlot) from .permissions import ReadOnly, Patch from rest_framework.exceptions import NotFound @@ -354,8 +354,8 @@ 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 + tourney_serialized["seatslots"] = serializers.SeatSlotSerializer( + SeatSlot.objects.filter(tournament=tourney), context={"request": request}, many=True ).data return Response(tourney_serialized, status=status.HTTP_200_OK)