Laurent 4 months ago
commit c9ad392ce1
  1. 3
      tournaments/models/team_registration.py
  2. 25
      tournaments/models/tournament.py
  3. 4
      tournaments/views.py

@ -519,3 +519,6 @@ class TeamRegistration(TournamentSubModel):
if self.group_stage_position is not None:
return False
return True
def is_positioned(self):
return self.bracket_position is not None or self.group_stage_position is not None

@ -1013,6 +1013,13 @@ class Tournament(BaseModel):
def will_start_soon(self, hour_delta=2):
return self.has_started(hour_delta=hour_delta)
def are_teams_positioned(self):
teams = self.team_registrations.all()
filtered_teams = [t for t in teams if t.is_positioned()]
if len(filtered_teams) > 3:
return True
return False
def supposedly_in_progress(self):
start = self.start_date - timedelta(hours=1)
end = self.start_date + timedelta(days=self.day_duration + 1)
@ -1143,7 +1150,8 @@ class Tournament(BaseModel):
options.append(f"Clôture des inscriptions le {date}")
# Période de désinscription
options.append(f"Désinscription possible jusqu'à {self.unregister_delta_in_hours}h avant le tournoi")
formatted_period = self.format_time_period(self.unregister_delta_in_hours)
options.append(f"Désinscription possible jusqu'à {formatted_period} avant le tournoi")
options.append(self.get_selection_status_localized)
@ -1186,6 +1194,21 @@ class Tournament(BaseModel):
return options
def format_time_period(self, hours):
"""
Format time period in hours to a more readable format.
Examples:
- 24 hours -> "24h"
- 48 hours -> "2 jours"
- 168 hours -> "7 jours"
- 25 hours -> "25h"
"""
if hours % 24 == 0 and hours > 24:
days = hours // 24
return f"{days} jours"
else:
return f"{hours}h"
def get_selection_status_localized(self):
if self.team_sorting == TeamSortingType.RANK:
return "La sélection se fait par le poids de l'équipe"

@ -88,7 +88,7 @@ def index(request):
live = []
future = []
for t in display_tournament:
if t.supposedly_in_progress():
if t.supposedly_in_progress() and t.are_teams_positioned():
live.append(t)
elif t.starts_in_the_future():
future.append(t)
@ -165,7 +165,7 @@ def finished_tournaments(club_id, limit=None):
def live_tournaments(club_id, limit=None):
tournaments = tournaments_query(Q(end_date__isnull=True), club_id, True, limit)
return [t for t in tournaments if t.display_tournament() and t.supposedly_in_progress()]
return [t for t in tournaments if t.display_tournament() and t.supposedly_in_progress() and t.are_teams_positioned()]
def future_tournaments(club_id, limit=None):
tournaments = tournaments_query(Q(end_date__isnull=True), club_id, True, limit)

Loading…
Cancel
Save