|
|
|
|
@ -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(): |
|
|
|
|
|