diff --git a/api/views.py b/api/views.py index 5513011..54f2b3d 100644 --- a/api/views.py +++ b/api/views.py @@ -317,7 +317,7 @@ def process_refund(request, team_registration_id): return Response({ 'success': success, 'message': message, - 'players': team_registration.players.all() + 'players': team_registration.players_sorted_by_rank }) except Exception as e: return Response({ diff --git a/tournaments/models/group_stage.py b/tournaments/models/group_stage.py index 5c43b3c..e9177c1 100644 --- a/tournaments/models/group_stage.py +++ b/tournaments/models/group_stage.py @@ -220,7 +220,7 @@ class GroupStageTeam: self.set_diff = 0 self.game_diff = 0 self.display_set_difference = False - if team_registration.player_registrations.count() == 0: + if team_registration.players_sorted_by_rank.count() == 0: weight = None else: weight = team_registration.weight diff --git a/tournaments/models/team_registration.py b/tournaments/models/team_registration.py index d8dc972..c9d6d28 100644 --- a/tournaments/models/team_registration.py +++ b/tournaments/models/team_registration.py @@ -56,7 +56,7 @@ class TeamRegistration(SideStoreModel): return None def player_names_as_list(self): - players = list(self.player_registrations.all()) + players = list(self.players_sorted_by_rank) if len(players) == 0: return [] elif len(players) == 1: @@ -74,7 +74,7 @@ class TeamRegistration(SideStoreModel): if self.name: return [self.name] #add an empty line if it's a team name else: - players = list(self.player_registrations.all()) + players = list(self.players_sorted_by_rank) if len(players) == 0: if self.wild_card_bracket: return ['Place réservée wildcard'] @@ -88,7 +88,7 @@ class TeamRegistration(SideStoreModel): return [pr.shortened_name() for pr in players] @property - def players(self): + def players_sorted_by_rank(self): # Fetch related PlayerRegistration objects return self.player_registrations.all().order_by('rank') @@ -103,7 +103,7 @@ class TeamRegistration(SideStoreModel): def formatted_team_names(self): if self.name: return self.name - names = [pr.last_name for pr in self.player_registrations.all()][:2] # Take max first 2 + names = [pr.last_name for pr in self.players_sorted_by_rank][:2] # Take max first 2 joined_names = " / ".join(names) if joined_names: return f"Paire {joined_names}" @@ -135,11 +135,11 @@ class TeamRegistration(SideStoreModel): return "--" def set_weight(self): - self.weight = self.player_registrations.aggregate(total_weight=models.Sum('computed_rank'))['total_weight'] or 0 + self.weight = self.players_sorted_by_rank.aggregate(total_weight=models.Sum('computed_rank'))['total_weight'] or 0 self.save() # Save the updated weight if necessary def is_valid_for_summon(self): - return self.player_registrations.count() > 0 or self.name is not None + return self.players_sorted_by_rank.count() > 0 or self.name is not None def initial_weight(self): if self.locked_weight is None: @@ -167,7 +167,7 @@ class TeamRegistration(SideStoreModel): return self.walk_out def get_other_player(self, player): - for p in self.player_registrations.all(): + for p in self.players_sorted_by_rank: if p != player: return p return None @@ -298,7 +298,7 @@ class TeamRegistration(SideStoreModel): return None def has_registered_online(self): - for p in self.player_registrations.all(): + for p in self.players_sorted_by_rank: if p.registered_online: return True return False @@ -311,7 +311,7 @@ class TeamRegistration(SideStoreModel): return "" def set_time_to_confirm(self, ttc): - for p in self.player_registrations.all(): + for p in self.players_sorted_by_rank: if p.registered_online: p.time_to_confirm = ttc if ttc is None: @@ -324,18 +324,18 @@ class TeamRegistration(SideStoreModel): """Check if this team needs to confirm their registration""" # Check if any player has status PENDING and is registered online return any(p.registration_status == RegistrationStatus.PENDING and p.registered_online - for p in self.player_registrations.all()) + for p in self.players_sorted_by_rank) def get_confirmation_deadline(self): """Get the confirmation deadline for this team""" - deadlines = [p.time_to_confirm for p in self.player_registrations.all() if p.time_to_confirm is not None] + deadlines = [p.time_to_confirm for p in self.players_sorted_by_rank if p.time_to_confirm is not None] return max(deadlines) if deadlines else None def confirm_registration(self, payment_intent_id=None): """Confirm the team's registration after being moved from waiting list""" now = timezone.now() # Update all players in the team - for player in self.player_registrations.all(): + for player in self.players_sorted_by_rank: player.time_to_confirm = None player.payment_id = payment_intent_id if payment_intent_id is not None: @@ -357,7 +357,7 @@ class TeamRegistration(SideStoreModel): - 'MIXED': If some players have paid and others haven't (unusual case) """ # Get all player registrations for this team - player_registrations = self.player_registrations.all() + player_registrations = self.players_sorted_by_rank # If we have no players, return None if not player_registrations.exists(): diff --git a/tournaments/models/team_score.py b/tournaments/models/team_score.py index cbf9eee..b9f8dc6 100644 --- a/tournaments/models/team_score.py +++ b/tournaments/models/team_score.py @@ -114,7 +114,7 @@ class TeamScore(SideStoreModel): id = self.team_registration.id image = self.team_registration.logo is_winner = self.team_registration.id == match.winning_team_id - if self.team_registration.player_registrations.count() == 0: + if self.team_registration.players_sorted_by_rank.count() == 0: weight = None else: weight = self.team_registration.weight diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index d411e4c..48f0129 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -1824,7 +1824,7 @@ class TeamItem: self.names = team_registration.team_names() self.date = team_registration.local_call_date() self.registration_date = team_registration.registration_date - if team_registration.player_registrations.count() == 0: + if team_registration.players_sorted_by_rank.count() == 0: weight = None else: weight = team_registration.weight diff --git a/tournaments/services/email_service.py b/tournaments/services/email_service.py index beca95d..0514c3c 100644 --- a/tournaments/services/email_service.py +++ b/tournaments/services/email_service.py @@ -2,7 +2,6 @@ from django.core.mail import EmailMessage from enum import Enum from ..models.enums import RegistrationStatus from ..models.tournament import TeamSortingType -import django.utils.timezone class TeamEmailType(Enum): REGISTERED = "registered" @@ -484,7 +483,7 @@ class TournamentEmailService: @staticmethod def notify_team(team, tournament, message_type: TeamEmailType): # Notify both players separately if there is no captain or the captain is unavailable - players = list(team.player_registrations.all()) + players = list(team.players_sorted_by_rank) if len(players) == 2: print("TournamentEmailService.notify_team 2p", team) first_player, second_player = players @@ -533,7 +532,7 @@ class TournamentEmailService: team_registration: The team registration refund_details: The refund details from Stripe """ - player_registrations = team_registration.player_registrations.all() + player_registrations = team_registration.players_sorted_by_rank refund_amount = None if refund_details and 'amount' in refund_details: # Convert cents to euros diff --git a/tournaments/services/tournament_unregistration.py b/tournaments/services/tournament_unregistration.py index f531a49..c22b927 100644 --- a/tournaments/services/tournament_unregistration.py +++ b/tournaments/services/tournament_unregistration.py @@ -83,7 +83,7 @@ class TournamentUnregistrationService: unregistration_date=timezone.now(), ) - for player in team_registration.player_registrations.all(): + for player in team_registration.players_sorted_by_rank: UnregisteredPlayer.objects.create( unregistered_team=unregistered_team, first_name=player.first_name, diff --git a/tournaments/templates/tournaments/match_cell.html b/tournaments/templates/tournaments/match_cell.html index e973ba8..3205329 100644 --- a/tournaments/templates/tournaments/match_cell.html +++ b/tournaments/templates/tournaments/match_cell.html @@ -15,24 +15,29 @@ {% for team in match.teams %}