@ -67,6 +67,7 @@ class Tournament(BaseModel):
initial_seed_round = models . IntegerField ( default = 0 )
initial_seed_count = models . IntegerField ( default = 0 )
enable_online_registration = models . BooleanField ( default = False ) # Equivalent to Bool = false
team_count_limit = models . BooleanField ( default = True )
registration_date_limit = models . DateTimeField ( null = True , blank = True ) # Equivalent to Date? = nil
opening_registration_date = models . DateTimeField ( null = True , blank = True ) # Equivalent to Date? = nil
waiting_list_limit = models . IntegerField ( null = True , blank = True ) # Equivalent to Int? = nil
@ -397,7 +398,7 @@ class Tournament(BaseModel):
complete_teams . append ( team )
else :
waiting_teams . append ( team )
wildcard_bracket = [ ]
return complete_teams , wildcard_bracket , wildcard_group_stage , waiting_teams
def sort_teams ( self , include_waiting_list , complete_teams , wildcard_bracket , wildcard_group_stage , waiting_teams ) :
@ -1051,19 +1052,22 @@ class Tournament(BaseModel):
def options_online_registration ( self ) :
options = [ ]
timezone = self . timezone ( )
# Date d'ouverture
if self . opening_registration_date :
date = formats . date_format ( timezone . localtime ( self . opening_registration_dat e) , format = ' j F Y H:i ' )
date = formats . date_format ( self . opening_registration_date . astimezone ( timezon e) , 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 ( timezone . localtime ( self . registration_date_limit ) , format = ' j F Y H:i ' )
date = formats . date_format ( self . registration_date_limit . astimezone ( timezone ) , format = ' j F Y H:i ' )
options . append ( f " Clôture des inscriptions le { date } " )
options . append ( self . get_selection_status_localized )
# Cible d'équipes
if self . team_count :
if self . team_count_limit is True :
options . append ( f " Maximum { self . team_count } équipes " )
# Liste d'attente
@ -1122,11 +1126,17 @@ class Tournament(BaseModel):
return False
return True
def get_selection_status_localized ( self ) :
if self . team_sorting == TeamSortingType . RANK :
return " La sélection se fait par le poids de l ' équipe "
else :
return " La sélection se fait par date d ' inscription "
def get_online_registration_status ( self ) :
if self . supposedly_in_progress ( ) :
return OnlineRegistrationStatus . ENDED
if self . closed_registration_date is not None :
return OnlineRegistrationStatus . ENDED
return OnlineRegistrationStatus . WAITING_LIST_POSSIBLE
if self . end_date is not None :
return OnlineRegistrationStatus . ENDED_WITH_RESULTS
@ -1140,9 +1150,12 @@ class Tournament(BaseModel):
if self . registration_date_limit is not None :
timezoned_datetime = timezone . localtime ( self . registration_date_limit )
if now > timezoned_datetime :
return OnlineRegistrationStatus . ENDED
return OnlineRegistrationStatus . WAITING_LIST_POSSIBLE
if self . team_sorting == TeamSortingType . RANK :
return OnlineRegistrationStatus . OPEN
if self . team_count is not None :
if self . team_count_limit is Tru e :
# Get all team registrations excluding walk_outs
current_team_count = self . team_registrations . exclude ( walk_out = True ) . count ( )
if current_team_count > = self . team_count :
@ -1174,8 +1187,14 @@ class Tournament(BaseModel):
return True
def get_waiting_list_position ( self ) :
current_time = timezone . now ( )
local_registration_federal_limit = self . local_registration_federal_limit ( )
if self . team_sorting == TeamSortingType . RANK and local_registration_federal_limit is not None :
if current_time < local_registration_federal_limit :
return - 1
# If no target team count exists, no one goes to waiting list
if self . team_count is None :
if self . team_count_limit is Fals e:
return - 1
# Get count of active teams (not walked out)
@ -1257,7 +1276,6 @@ class Tournament(BaseModel):
current_year + = 1
user_age = current_year - int ( birth_year )
print ( " user_age " , user_age )
# Check age category restrictions
if self . federal_age_category == FederalAgeCategory . A11_12 and user_age > 12 :
@ -1290,12 +1308,49 @@ class Tournament(BaseModel):
def min_player_rank ( self ) :
return FederalLevelCategory . min_player_rank ( self . federal_level_category , self . federal_category , self . federal_age_category )
def first_waiting_list_team ( self , teams ) :
def local_registration_federal_limit ( self ) :
timezone = self . timezone ( )
if self . registration_date_limit is not None :
return self . registration_date_limit . astimezone ( timezone )
if self . closed_registration_date is not None :
return self . closed_registration_date . astimezone ( timezone )
local_start_date = self . local_start_date ( )
if local_start_date is None :
return None
if self . federal_level_category == FederalLevelCategory . P500 :
# 7 days before at 23:59
return ( local_start_date - timedelta ( days = 7 ) ) . replace ( hour = 23 , minute = 59 , second = 59 )
elif self . federal_level_category in [ FederalLevelCategory . P1000 ,
FederalLevelCategory . P1500 ,
FederalLevelCategory . P2000 ] :
# 14 days before at 23:59
return ( local_start_date - timedelta ( days = 14 ) ) . replace ( hour = 23 , minute = 59 , second = 59 )
return None
def waiting_list_teams ( self , teams ) :
current_time = timezone . now ( )
local_registration_federal_limit = self . local_registration_federal_limit ( )
if self . team_sorting == TeamSortingType . RANK and local_registration_federal_limit is not None :
if current_time < local_registration_federal_limit :
return None
if len ( teams ) < = self . team_count :
return None
waiting_teams = [ team for team in teams if team . stage == " Attente " ]
if len ( waiting_teams ) > 0 :
return waiting_teams [ 0 ] . team_registration
return waiting_teams
def first_waiting_list_team ( self , teams ) :
waiting_list_team = self . waiting_list_teams ( teams )
if waiting_list_team is None :
return None
if len ( waiting_list_team ) > 0 :
return waiting_list_team [ 0 ] . team_registration
else :
return None
def broadcasted_prog ( self ) :
# Get matches from broadcasted_matches_and_group_stages
@ -1418,19 +1473,16 @@ class Tournament(BaseModel):
def umpire_contact ( self ) :
if self . umpire_custom_contact is not None :
print ( self . umpire_custom_contact )
return self . umpire_custom_contact
return self . event . creator . full_name ( )
def umpire_mail ( self ) :
if self . umpire_custom_mail is not None :
print ( self . umpire_custom_mail )
return self . umpire_custom_mail
return self . event . creator . email
def umpire_phone ( self ) :
if self . umpire_custom_phone is not None :
print ( self . umpire_custom_phone )
return self . umpire_custom_phone
return self . event . creator . phone
@ -1486,6 +1538,12 @@ class TeamSummon:
}
class TeamItem :
def __str__ ( self ) :
return f " TeamItem( { self . team_registration . id } , names= { self . names } , stage= { self . stage } ) "
def __repr__ ( self ) :
return self . __str__ ( )
def __init__ ( self , team_registration ) :
self . names = team_registration . team_names ( )
self . date = team_registration . local_call_date ( )