From 67060c7fc0ee50382a7b170cd0803cb84bbf7199 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Am=C3=A9lie=20=22Lymkwi=22=20Gonz=C3=A1lez?= Date: Sun, 15 Oct 2023 21:01:32 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=92=20Several=20tournament=20models=20?= =?UTF-8?q?modifications?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Models in the tournament field are modified thusly: - The whole file is formatted - A team is now always attached to a tournament, including when it is not validated. A boolean is added in `Team` to know if it has been validated - Both player and manager registrations now have a foreign key to their ticket, which is null until the payment of their ticket has succeeded - Admin view updated - Tests updated --- insalan/tournament/admin.py | 6 +-- insalan/tournament/models.py | 84 ++++++++++++++++++++---------------- insalan/tournament/tests.py | 54 +++++++++-------------- 3 files changed, 71 insertions(+), 73 deletions(-) diff --git a/insalan/tournament/admin.py b/insalan/tournament/admin.py index 2ce710ba..5cb1f4ab 100644 --- a/insalan/tournament/admin.py +++ b/insalan/tournament/admin.py @@ -43,7 +43,7 @@ class TournamentAdmin(admin.ModelAdmin): class TeamAdmin(admin.ModelAdmin): """Admin handler for Team""" - list_display = ("id", "name", "tournament") + list_display = ("id", "name", "tournament", "validated") search_fields = ["name", "tournament"] @@ -53,7 +53,7 @@ class TeamAdmin(admin.ModelAdmin): class PlayerAdmin(admin.ModelAdmin): """Admin handler for Player Registrations""" - list_display = ("id", "user", "team", "payment_status") + list_display = ("id", "user", "team", "payment_status", "ticket") search_fields = ["user", "team", "payment_status"] @@ -63,7 +63,7 @@ class PlayerAdmin(admin.ModelAdmin): class ManagerAdmin(admin.ModelAdmin): """Admin handler for Manager Registrations""" - list_display = ("id", "user", "team", "payment_status") + list_display = ("id", "user", "team", "payment_status", "ticket") search_fields = ["user", "team", "payment_status"] diff --git a/insalan/tournament/models.py b/insalan/tournament/models.py index fd25a627..d38537c6 100644 --- a/insalan/tournament/models.py +++ b/insalan/tournament/models.py @@ -40,22 +40,20 @@ class Event(models.Model): null=False, ) description = models.CharField( - verbose_name=_("Description de l'évènement"), max_length=128, default="", blank=True + verbose_name=_("Description de l'évènement"), + max_length=128, + default="", + blank=True, ) year = models.IntegerField( - verbose_name=_("Année"), - null=False, - validators=[MinValueValidator(2003)] + verbose_name=_("Année"), null=False, validators=[MinValueValidator(2003)] ) month = models.IntegerField( verbose_name=_("Mois"), null=False, - validators=[MinValueValidator(1),MaxValueValidator(12)] - ) - ongoing = models.BooleanField( - verbose_name=_("En cours"), - default=False + validators=[MinValueValidator(1), MaxValueValidator(12)], ) + ongoing = models.BooleanField(verbose_name=_("En cours"), default=False) logo: models.FileField = models.FileField( verbose_name=_("Logo"), blank=True, @@ -68,6 +66,7 @@ class Event(models.Model): class Meta: """Meta options""" + verbose_name = _("Évènement") verbose_name_plural = _("Évènements") @@ -93,8 +92,10 @@ class Game(models.Model): """ A Game is the representation of a Game that is being played at InsaLan """ + class Meta: """Meta options""" + verbose_name = _("Jeu") verbose_name_plural = _("Jeux") @@ -131,15 +132,9 @@ class Tournament(models.Model): """ event = models.ForeignKey( - Event, - verbose_name=_("Évènement"), - on_delete=models.CASCADE - ) - game = models.ForeignKey( - Game, - verbose_name=_("Jeu"), - on_delete=models.CASCADE + Event, verbose_name=_("Évènement"), on_delete=models.CASCADE ) + game = models.ForeignKey(Game, verbose_name=_("Jeu"), on_delete=models.CASCADE) name = models.CharField( verbose_name=_("Nom du tournoi"), validators=[MinLengthValidator(3)], @@ -164,6 +159,7 @@ class Tournament(models.Model): class Meta: """Meta options""" + verbose_name = _("Tournoi") verbose_name_plural = _("Tournois") @@ -204,10 +200,10 @@ class Team(models.Model): tournament = models.ForeignKey( Tournament, - null=True, - blank=True, - on_delete=models.SET_NULL, - verbose_name=_("Tournoi") + null=False, + blank=False, + on_delete=models.CASCADE, + verbose_name=_("Tournoi"), ) name = models.CharField( max_length=42, @@ -215,9 +211,13 @@ class Team(models.Model): null=False, verbose_name=_("Nom d'équipe"), ) + validated = models.BooleanField( + default=False, blank=True, verbose_name=_("Équipe validée") + ) class Meta: """Meta Options""" + verbose_name = _("Équipe") verbose_name_plural = _("Équipes") constraints = [ @@ -228,7 +228,7 @@ class Meta: def __str__(self) -> str: """Format this team to a str""" - if self.tournament is not None: + if self.tournament is not None: return f"{self.name} ({self.tournament.event})" return f"{self.name} (???)" @@ -290,14 +290,12 @@ class Meta: verbose_name_plural = _("Inscription de joueur⋅euses") user = models.ForeignKey( - User, - on_delete=models.CASCADE, - verbose_name=_("Utilisateur⋅ice") + User, on_delete=models.CASCADE, verbose_name=_("Utilisateur⋅ice") ) team = models.ForeignKey( "tournament.Team", on_delete=models.CASCADE, - verbose_name = _("Équipe"), + verbose_name=_("Équipe"), ) payment_status = models.CharField( max_length=10, @@ -305,7 +303,15 @@ class Meta: default=PaymentStatus.NOT_PAID, choices=PaymentStatus.choices, null=False, - verbose_name = _("Statut du paiement"), + verbose_name=_("Statut du paiement"), + ) + ticket = models.ForeignKey( + Ticket, + on_delete=models.SET_NULL, + verbose_name=_("Ticket"), + null=True, + blank=True, + default=None, ) def __str__(self) -> str: @@ -352,13 +358,12 @@ class Manager(models.Model): A Manager is someone in charge of heading a team of players. """ - user = models.ForeignKey(User, - verbose_name=_("Utilisateur⋅ice"), - on_delete=models.CASCADE + user = models.ForeignKey( + User, verbose_name=_("Utilisateur⋅ice"), on_delete=models.CASCADE + ) + team = models.ForeignKey( + "tournament.Team", verbose_name=_("Équipe"), on_delete=models.CASCADE ) - team = models.ForeignKey("tournament.Team", - verbose_name=_("Équipe"), - on_delete=models.CASCADE) payment_status = models.CharField( verbose_name=_("Statut du paiement"), max_length=10, @@ -367,6 +372,14 @@ class Manager(models.Model): choices=PaymentStatus.choices, null=False, ) + ticket = models.ForeignKey( + Ticket, + on_delete=models.SET_NULL, + verbose_name=_("Ticket"), + null=True, + blank=True, + default=None, + ) class Meta: """Meta Options""" @@ -381,9 +394,7 @@ class Meta: def __str__(self) -> str: """Format this manager registration as a str""" - return ( - f"(Manager) {self.user.username} for {self.team}" - ) + return f"(Manager) {self.user.username} for {self.team}" def as_user(self) -> User: """Return the current player as a User object""" @@ -393,4 +404,5 @@ def get_team(self): """Return the Team object of the current team""" return self.team + # vim: set cc=80 tw=80: diff --git a/insalan/tournament/tests.py b/insalan/tournament/tests.py index c8fee3ae..cabffe72 100644 --- a/insalan/tournament/tests.py +++ b/insalan/tournament/tests.py @@ -473,23 +473,6 @@ def test_payment_status_set(self): self.assertEqual(PaymentStatus.PAY_LATER, play_reg.payment_status) - def test_get_full_null_tournament(self): - """Get a team with a null tournament""" - team = Team.objects.create(name="LaZone", tournament=None) - - team.full_clean() - - self.assertIsNone(team.get_tournament()) - - def test_team_null_tourney_repr(self): - """ - Test that the representation of a Team when its tournament is null is as - expectde. - """ - team = Team.objects.create(name="LaZone", tournament=None) - - self.assertEqual(str(team), "LaZone (???)") - def test_get_team_players(self): """Get the players of a Team""" team = Team.objects.get(name="LaLooze") @@ -550,18 +533,6 @@ def test_team_name_too_long(self): team.name = "C" * 42 team.full_clean() - def test_tournament_deletion_set_null(self): - """Verify that a Team is deleted when its Tournament is""" - team = Team.objects.all()[0] - tourney = team.tournament - - Team.objects.get(id=team.id) - - # Delete and verify - tourney.delete() - - self.assertIsInstance(Team.objects.get(id=team.id).tournament, NoneType) - # Player Class Tests class PlayerTestCase(TestCase): @@ -773,8 +744,10 @@ def test_get_player_team_correct(self): def test_player_team_deletion(self): """Verify the behaviour of a Player when their team gets deleted""" user_obj = User.objects.get(username="testplayer") + event = Event.objects.get(year=2023, month=8) + trnm = Tournament.objects.get(event=event) # Create a team and player - team_obj = Team.objects.create(name="La Team Test", tournament=None) + team_obj = Team.objects.create(name="La Team Test Player", tournament=trnm) play_obj = Player.objects.create(team=team_obj, user=user_obj) Player.objects.get(id=play_obj.id) @@ -787,8 +760,10 @@ def test_player_team_deletion(self): def test_user_deletion(self): """Verify that a Player registration is deleted along with its user""" user_obj = User.objects.get(username="testplayer") + event = Event.objects.get(year=2023, month=8) + trnm = Tournament.objects.get(event=event) # Create a Player registration - team_obj = Team.objects.create(name="La Team Test", tournament=None) + team_obj = Team.objects.create(name="La Team Test User", tournament=trnm) play_obj = Player.objects.create(team=team_obj, user=user_obj) # Test @@ -1167,8 +1142,13 @@ def test_one_manager_many_teams_diff_event_diff_tournament_diff_team(self): def test_manager_team_deletion(self): """Verify the behaviour of a Manager when their team gets deleted""" user_obj = User.objects.get(username="testplayer") + event = Event.objects.create( + name="InsaLan Test", year=2023, month=8, description="" + ) + game = Game.objects.create(name="Test Game") + trnm = Tournament.objects.create(game=game, event=event) # Create a team and player - team_obj = Team.objects.create(name="La Team Test", tournament=None) + team_obj = Team.objects.create(name="La Team Test", tournament=trnm) play_obj = Manager.objects.create(team=team_obj, user=user_obj) Manager.objects.get(id=play_obj.id) @@ -1181,8 +1161,14 @@ def test_manager_team_deletion(self): def test_user_deletion(self): """Verify that a Manager registration is deleted along with its user""" user_obj = User.objects.get(username="testplayer") - # Create a Manager registration - team_obj = Team.objects.create(name="La Team Test", tournament=None) + event = Event.objects.create( + name="InsaLan Test", year=2023, month=8, description="" + ) + game = Game.objects.create(name="Test Game") + trnm = Tournament.objects.create( + game=game, event=event + ) # Create a Manager registration + team_obj = Team.objects.create(name="La Team Test", tournament=trnm) man_obj = Manager.objects.create(team=team_obj, user=user_obj) # Test