|
|
|
@ -5,7 +5,7 @@ from typing import TYPE_CHECKING |
|
|
|
if TYPE_CHECKING: |
|
|
|
if TYPE_CHECKING: |
|
|
|
from tournaments.models import group_stage |
|
|
|
from tournaments.models import group_stage |
|
|
|
|
|
|
|
|
|
|
|
from . import Event, TournamentPayment, FederalMatchCategory, FederalCategory, FederalLevelCategory, FederalAgeCategory |
|
|
|
from . import Event, TournamentPayment, FederalMatchCategory, FederalCategory, FederalLevelCategory, FederalAgeCategory, OnlineRegistrationStatus |
|
|
|
import uuid |
|
|
|
import uuid |
|
|
|
from django.utils import timezone, formats |
|
|
|
from django.utils import timezone, formats |
|
|
|
from datetime import datetime, timedelta |
|
|
|
from datetime import datetime, timedelta |
|
|
|
@ -219,12 +219,19 @@ class Tournament(models.Model): |
|
|
|
return f"{len(teams)} {word}" |
|
|
|
return f"{len(teams)} {word}" |
|
|
|
else: |
|
|
|
else: |
|
|
|
return None |
|
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
registration_status = None |
|
|
|
|
|
|
|
if self.online_register_is_enabled() is True: |
|
|
|
|
|
|
|
registration_status = self.get_online_registration_status().status_localized() |
|
|
|
if teams is not None and len(teams) > 0: |
|
|
|
if teams is not None and len(teams) > 0: |
|
|
|
word = "inscription" |
|
|
|
word = "inscription" |
|
|
|
if len(teams) > 1: |
|
|
|
if len(teams) > 1: |
|
|
|
word = word + "s" |
|
|
|
word = word + "s" |
|
|
|
return f"{len(teams)} {word}" |
|
|
|
if registration_status is not None: |
|
|
|
|
|
|
|
return f"{registration_status}\n{len(teams)} {word}" |
|
|
|
else: |
|
|
|
else: |
|
|
|
|
|
|
|
if registration_status is not None: |
|
|
|
|
|
|
|
return f"{registration_status}" |
|
|
|
return None |
|
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
def name_and_event(self): |
|
|
|
def name_and_event(self): |
|
|
|
@ -277,6 +284,7 @@ class Tournament(models.Model): |
|
|
|
def rankings(self): |
|
|
|
def rankings(self): |
|
|
|
rankings = [] |
|
|
|
rankings = [] |
|
|
|
for team_registration in self.teamregistration_set.all(): |
|
|
|
for team_registration in self.teamregistration_set.all(): |
|
|
|
|
|
|
|
|
|
|
|
if team_registration.walk_out is False and team_registration.final_ranking is not None: |
|
|
|
if team_registration.walk_out is False and team_registration.final_ranking is not None: |
|
|
|
names = team_registration.team_names() |
|
|
|
names = team_registration.team_names() |
|
|
|
ranking = team_registration.final_ranking |
|
|
|
ranking = team_registration.final_ranking |
|
|
|
@ -309,8 +317,7 @@ class Tournament(models.Model): |
|
|
|
if team_registration.registration_date is None: |
|
|
|
if team_registration.registration_date is None: |
|
|
|
is_valid = True |
|
|
|
is_valid = True |
|
|
|
# print(f"Is valid: {is_valid}") |
|
|
|
# print(f"Is valid: {is_valid}") |
|
|
|
|
|
|
|
if team_registration.out_of_tournament() is False: |
|
|
|
if team_registration.walk_out is False: |
|
|
|
|
|
|
|
team = TeamItem(team_registration) |
|
|
|
team = TeamItem(team_registration) |
|
|
|
# print(f"Created team: {team}") |
|
|
|
# print(f"Created team: {team}") |
|
|
|
if team_registration.group_stage_position is not None: |
|
|
|
if team_registration.group_stage_position is not None: |
|
|
|
@ -880,28 +887,117 @@ class Tournament(models.Model): |
|
|
|
return False |
|
|
|
return False |
|
|
|
return True |
|
|
|
return True |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def options_online_registration(self): |
|
|
|
|
|
|
|
options = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Date d'ouverture |
|
|
|
|
|
|
|
if self.opening_registration_date: |
|
|
|
|
|
|
|
date = formats.date_format(self.opening_registration_date, format='j F Y H:i') |
|
|
|
|
|
|
|
options.append(f"Ouverture des inscriptions le {date}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Date limite |
|
|
|
|
|
|
|
if self.registration_date_limit: |
|
|
|
|
|
|
|
date = formats.date_format(self.registration_date_limit, format='j F Y H:i') |
|
|
|
|
|
|
|
options.append(f"Clôture des inscriptions le {date}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Cible d'équipes |
|
|
|
|
|
|
|
if self.target_team_count: |
|
|
|
|
|
|
|
options.append(f"Maximum {self.target_team_count} équipes") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Liste d'attente |
|
|
|
|
|
|
|
if self.waiting_list_limit: |
|
|
|
|
|
|
|
options.append(f"Liste d'attente limitée à {self.waiting_list_limit} équipes") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Options d'inscription |
|
|
|
|
|
|
|
if self.account_is_required: |
|
|
|
|
|
|
|
options.append("Compte requis") |
|
|
|
|
|
|
|
if self.license_is_required: |
|
|
|
|
|
|
|
options.append("Licence requise") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Joueurs par équipe |
|
|
|
|
|
|
|
min_players = self.minimum_player_per_team |
|
|
|
|
|
|
|
max_players = self.maximum_player_per_team |
|
|
|
|
|
|
|
if min_players == max_players: |
|
|
|
|
|
|
|
options.append(f"{min_players} joueurs par équipe") |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
options.append(f"Entre {min_players} et {max_players} joueurs par équipe") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return options |
|
|
|
|
|
|
|
|
|
|
|
def online_register_is_enabled(self): |
|
|
|
def online_register_is_enabled(self): |
|
|
|
if self.supposedly_in_progress(): |
|
|
|
if self.supposedly_in_progress(): |
|
|
|
return False |
|
|
|
return False |
|
|
|
if self.end_date is not None: |
|
|
|
if self.end_date is not None: |
|
|
|
return False |
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
now = datetime.now() |
|
|
|
now = timezone.now() |
|
|
|
|
|
|
|
|
|
|
|
# Check if online registration is enabled |
|
|
|
# Check if online registration is enabled |
|
|
|
if not self.enable_online_registration: |
|
|
|
if not self.enable_online_registration: |
|
|
|
return False |
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
# Check opening registration date |
|
|
|
# Check opening registration date |
|
|
|
if self.opening_registration_date is not None and now < self.opening_registration_date: |
|
|
|
if self.opening_registration_date is not None: |
|
|
|
|
|
|
|
timezoned_datetime = timezone.localtime(self.opening_registration_date) |
|
|
|
|
|
|
|
if now < timezoned_datetime: |
|
|
|
return False |
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
# Check registration date limit |
|
|
|
# Check registration date limit |
|
|
|
if self.registration_date_limit is not None and now > self.registration_date_limit: |
|
|
|
if self.registration_date_limit is not None: |
|
|
|
|
|
|
|
timezoned_datetime = timezone.localtime(self.registration_date_limit) |
|
|
|
|
|
|
|
if now > timezoned_datetime: |
|
|
|
return False |
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
# All conditions are satisfied |
|
|
|
# Check target team count and waiting list limit |
|
|
|
|
|
|
|
if self.target_team_count is not None: |
|
|
|
|
|
|
|
current_team_count = len([tr for tr in self.teamregistration_set.all() if tr.out_of_tournament() is False]) |
|
|
|
|
|
|
|
if current_team_count >= self.target_team_count: |
|
|
|
|
|
|
|
if self.waiting_list_limit is not None: |
|
|
|
|
|
|
|
waiting_list_count = current_team_count - self.target_team_count |
|
|
|
|
|
|
|
if waiting_list_count >= self.waiting_list_limit: |
|
|
|
|
|
|
|
return False |
|
|
|
return True |
|
|
|
return True |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_online_registration_status(self): |
|
|
|
|
|
|
|
if self.supposedly_in_progress(): |
|
|
|
|
|
|
|
return OnlineRegistrationStatus.IN_PROGRESS |
|
|
|
|
|
|
|
if self.end_date is not None: |
|
|
|
|
|
|
|
return OnlineRegistrationStatus.ENDED_WITH_RESULTS |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
now = timezone.now() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self.opening_registration_date is not None: |
|
|
|
|
|
|
|
timezoned_datetime = timezone.localtime(self.opening_registration_date) |
|
|
|
|
|
|
|
if now < timezoned_datetime: |
|
|
|
|
|
|
|
return OnlineRegistrationStatus.NOT_STARTED |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self.registration_date_limit is not None: |
|
|
|
|
|
|
|
timezoned_datetime = timezone.localtime(self.registration_date_limit) |
|
|
|
|
|
|
|
if now > timezoned_datetime: |
|
|
|
|
|
|
|
return OnlineRegistrationStatus.ENDED |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self.target_team_count is not None: |
|
|
|
|
|
|
|
# Get all team registrations excluding walk_outs |
|
|
|
|
|
|
|
current_team_count = len([tr for tr in self.teamregistration_set.all() if tr.out_of_tournament() is False]) |
|
|
|
|
|
|
|
if current_team_count >= self.target_team_count: |
|
|
|
|
|
|
|
if self.waiting_list_limit is not None: |
|
|
|
|
|
|
|
waiting_list_count = current_team_count - self.target_team_count |
|
|
|
|
|
|
|
if waiting_list_count >= self.waiting_list_limit: |
|
|
|
|
|
|
|
return OnlineRegistrationStatus.WAITING_LIST_FULL |
|
|
|
|
|
|
|
return OnlineRegistrationStatus.WAITING_LIST_POSSIBLE |
|
|
|
|
|
|
|
return OnlineRegistrationStatus.REGISTRATION_FULL |
|
|
|
|
|
|
|
current_team_count = self.teamregistration_set.filter(walk_out=False).count() |
|
|
|
|
|
|
|
if current_team_count >= self.target_team_count: |
|
|
|
|
|
|
|
if self.waiting_list_limit is not None: |
|
|
|
|
|
|
|
waiting_list_count = current_team_count - self.target_team_count |
|
|
|
|
|
|
|
if waiting_list_count >= self.waiting_list_limit: |
|
|
|
|
|
|
|
return OnlineRegistrationStatus.WAITING_LIST_FULL |
|
|
|
|
|
|
|
return OnlineRegistrationStatus.WAITING_LIST_POSSIBLE |
|
|
|
|
|
|
|
return OnlineRegistrationStatus.REGISTRATION_FULL |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return OnlineRegistrationStatus.OPEN |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MatchGroup: |
|
|
|
class MatchGroup: |
|
|
|
def __init__(self, name, matches, formatted_schedule): |
|
|
|
def __init__(self, name, matches, formatted_schedule): |
|
|
|
self.name = name |
|
|
|
self.name = name |
|
|
|
|