Skip to content

Commit

Permalink
Add model for representing seats
Browse files Browse the repository at this point in the history
  • Loading branch information
3akev committed Jul 19, 2024
1 parent e5224bc commit d0e8159
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 5 deletions.
23 changes: 21 additions & 2 deletions insalan/tournament/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand All @@ -39,6 +45,7 @@
'Game',
'Tournament',
'Team',
'Seating',
'Player',
'Manager',
'Substitute',
Expand Down Expand Up @@ -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)
1 change: 1 addition & 0 deletions insalan/tournament/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
52 changes: 52 additions & 0 deletions insalan/tournament/models/seating.py
Original file line number Diff line number Diff line change
@@ -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"
)
]
18 changes: 16 additions & 2 deletions insalan/tournament/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down Expand Up @@ -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"""
Expand Down
10 changes: 9 additions & 1 deletion insalan/tournament/views/tournament.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)


Expand Down

0 comments on commit d0e8159

Please sign in to comment.