@ -221,7 +221,7 @@ class Tournament(models.Model):
names = team_registration . team_names ( )
names = team_registration . team_names ( )
stage = next_match . summon_stage_name ( )
stage = next_match . summon_stage_name ( )
weight = team_registration . weight
weight = team_registration . weight
summon = TeamSummon ( names , next_match . start_date , weight , stage , team_registration . logo )
summon = TeamSummon ( names , next_match . start_date , weight , stage , next_match . court_name ( next_match . court_index ) , team_registration . logo )
summons . append ( summon )
summons . append ( summon )
summons . sort ( key = lambda s : s . date )
summons . sort ( key = lambda s : s . date )
@ -372,10 +372,13 @@ class Tournament(models.Model):
groups = [ ]
groups = [ ]
if self . display_matches ( ) :
if self . display_matches ( ) :
for round in self . round_set . filter ( parent = None ) . all ( ) . order_by ( ' index ' ) :
for round in self . round_set . filter ( parent = None , group_stage_loser_bracket = False ) . all ( ) . order_by ( ' index ' ) :
groups . extend ( self . round_match_groups ( round , broadcasted , hide_empty_matches = True ) )
groups . extend ( self . round_match_groups ( round , broadcasted , hide_empty_matches = True ) )
if self . display_group_stages ( ) :
if self . display_group_stages ( ) :
for round in self . round_set . filter ( parent = None , group_stage_loser_bracket = True ) . all ( ) . order_by ( ' index ' ) :
groups . extend ( self . round_match_groups ( round , broadcasted , hide_empty_matches = True ) )
for group_stage in self . groupstage_set . all ( ) . order_by ( ' index ' ) :
for group_stage in self . groupstage_set . all ( ) . order_by ( ' index ' ) :
group = self . group_stage_match_group ( group_stage , broadcasted , hide_empty_matches = True )
group = self . group_stage_match_group ( group_stage , broadcasted , hide_empty_matches = True )
if group :
if group :
@ -390,6 +393,8 @@ class Tournament(models.Model):
else :
else :
matches = [ m for m in matches if m . disabled is False ]
matches = [ m for m in matches if m . disabled is False ]
matches . sort ( key = lambda m : ( m . start_date is None , m . end_date is not None , m . start_date , m . index ) )
if matches :
if matches :
return self . create_match_group ( group_stage . display_name ( ) , matches )
return self . create_match_group ( group_stage . display_name ( ) , matches )
else :
else :
@ -405,6 +410,7 @@ class Tournament(models.Model):
matches = [ m for m in matches if m . disabled is False ]
matches = [ m for m in matches if m . disabled is False ]
if matches :
if matches :
matches . sort ( key = lambda m : m . index )
group = self . create_match_group ( round . name ( ) , matches )
group = self . create_match_group ( round . name ( ) , matches )
groups . append ( group )
groups . append ( group )
@ -415,6 +421,7 @@ class Tournament(models.Model):
ranking_matches = [ m for m in ranking_matches if m . disabled is False ]
ranking_matches = [ m for m in ranking_matches if m . disabled is False ]
if len ( ranking_matches ) > 0 :
if len ( ranking_matches ) > 0 :
ranking_matches . sort ( key = lambda m : m . index )
group = self . create_match_group ( ' Matchs de classement ' , ranking_matches )
group = self . create_match_group ( ' Matchs de classement ' , ranking_matches )
groups . append ( group )
groups . append ( group )
@ -422,7 +429,6 @@ class Tournament(models.Model):
def create_match_group ( self , name , matches ) :
def create_match_group ( self , name , matches ) :
matches = list ( matches )
matches = list ( matches )
matches . sort ( key = lambda m : m . index )
live_matches = [ match . live_match ( ) for match in matches ]
live_matches = [ match . live_match ( ) for match in matches ]
return MatchGroup ( name , live_matches )
return MatchGroup ( name , live_matches )
@ -438,13 +444,14 @@ class Tournament(models.Model):
# if now is before the first match, we want to show the summons + group stage or first matches
# if now is before the first match, we want to show the summons + group stage or first matches
# change timezone to datetime to avoid the bug RuntimeWarning: DateTimeField Tournament.start_date received a naive datetime (2024-05-16 00:00:00) while time zone support is active.
# change timezone to datetime to avoid the bug RuntimeWarning: DateTimeField Tournament.start_date received a naive datetime (2024-05-16 00:00:00) while time zone support is active.
if date time. now ( ) . date ( ) < self . start_date . date ( ) :
if timezon e . now ( ) < self . start_date :
team_summons_dicts = [ summon . to_dict ( ) for summon in self . team_summons ( ) ]
team_summons_dicts = [ summon . to_dict ( ) for summon in self . team_summons ( ) ]
if group_stages :
if group_stages :
return {
return {
' matches ' : [ ] ,
' matches ' : [ ] ,
' group_stages ' : group_stages_dicts ,
' group_stages ' : group_stages_dicts ,
' summons ' : team_summons_dicts ,
' summons ' : team_summons_dicts ,
' rankings ' : [ ]
}
}
else :
else :
live_matches_dicts = [ match . live_match ( ) . to_dict ( ) for match in matches ]
live_matches_dicts = [ match . live_match ( ) . to_dict ( ) for match in matches ]
@ -452,13 +459,24 @@ class Tournament(models.Model):
' matches ' : live_matches_dicts ,
' matches ' : live_matches_dicts ,
' group_stages ' : [ ] ,
' group_stages ' : [ ] ,
' summons ' : team_summons_dicts ,
' summons ' : team_summons_dicts ,
' rankings ' : [ ]
}
}
elif self . end_date is not None :
live_matches_dicts = [ match . live_match ( ) . to_dict ( ) for match in matches ]
team_rankings_dicts = [ ranking . to_dict ( ) for ranking in self . rankings ( ) ]
return {
' matches ' : live_matches_dicts ,
' group_stages ' : [ ] ,
' summons ' : [ ] ,
' rankings ' : team_rankings_dicts
}
else : # we want to display the broadcasted content
else : # we want to display the broadcasted content
live_matches_dicts = [ match . live_match ( ) . to_dict ( ) for match in matches ]
live_matches_dicts = [ match . live_match ( ) . to_dict ( ) for match in matches ]
return {
return {
' matches ' : live_matches_dicts ,
' matches ' : live_matches_dicts ,
' group_stages ' : group_stages_dicts ,
' group_stages ' : group_stages_dicts ,
' summons ' : [ ] ,
' summons ' : [ ] ,
' rankings ' : [ ]
}
}
def broadcasted_matches_and_group_stages ( self ) :
def broadcasted_matches_and_group_stages ( self ) :
@ -473,19 +491,26 @@ class Tournament(models.Model):
matches . extend ( first_round . get_matches_recursive ( True ) )
matches . extend ( first_round . get_matches_recursive ( True ) )
else :
else :
current_round = self . round_to_show ( )
current_round = self . round_to_show ( )
print ( " current_round " , current_round )
if current_round :
if current_round :
# Add full matches from the next rounds
# Add full matches from the next rounds
print ( " Add full matches from the next rounds " )
next_round = self . round_for_index ( current_round . index - 1 )
next_round = self . round_for_index ( current_round . index - 1 )
if next_round :
if next_round :
print ( " next_round " , next_round )
matches . extend ( next_round . get_matches_recursive ( True ) )
matches . extend ( next_round . get_matches_recursive ( True ) )
# Add matches from the previous round or group_stages
# Add matches from the previous round or group_stages
print ( " Add matches from the previous round or group_stages " )
previous_round = self . round_for_index ( current_round . index + 1 )
previous_round = self . round_for_index ( current_round . index + 1 )
if previous_round :
if previous_round :
print ( " previous_round " , previous_round )
print ( ' test 1 ' )
matches . extend ( current_round . get_matches_recursive ( True ) )
matches . extend ( current_round . get_matches_recursive ( True ) )
matches . extend ( previous_round . get_matches_recursive ( True ) )
matches . extend ( previous_round . get_matches_recursive ( True ) )
else :
else :
print ( " else " )
matches . extend ( current_round . all_matches ( True ) )
matches . extend ( current_round . all_matches ( True ) )
group_stages = self . live_group_stages ( )
group_stages = self . live_group_stages ( )
@ -654,13 +679,20 @@ class Tournament(models.Model):
first_match_start_date = self . first_match_start_date ( bracket_matches )
first_match_start_date = self . first_match_start_date ( bracket_matches )
if first_match_start_date is None :
if first_match_start_date is None :
return date time. now ( ) . date ( ) > = self . start_date . date ( )
return timezon e . now ( ) > = self . start_date
bracket_start_date = self . getEightAm ( first_match_start_date )
bracket_start_date = self . getEightAm ( first_match_start_date )
if bracket_start_date < self . start_date :
if bracket_start_date < self . start_date :
bracket_start_date = self . start_date
bracket_start_date = self . start_date
if datetime . now ( ) . date ( ) > = bracket_start_date . date ( ) :
group_stage_start_date = self . group_stage_start_date ( )
if group_stage_start_date is not None :
if bracket_start_date < group_stage_start_date :
return False
if timezone . now ( ) > = bracket_start_date :
return True
return True
return False
return False
@ -679,7 +711,7 @@ class Tournament(models.Model):
return min ( matches , key = lambda m : m . start_date ) . start_date
return min ( matches , key = lambda m : m . start_date ) . start_date
def getEightAm ( self , date ) :
def getEightAm ( self , date ) :
return date . replace ( hour = 8 , minute = 0 , second = 0 , microsecond = 0 )
return date . replace ( hour = 8 , minute = 0 , second = 0 , microsecond = 0 , tzinfo = date . tzinfo )
def supposedly_in_progress ( self ) :
def supposedly_in_progress ( self ) :
end = self . start_date + timedelta ( days = self . day_duration + 1 )
end = self . start_date + timedelta ( days = self . day_duration + 1 )
@ -721,11 +753,12 @@ class MatchGroup:
self . matches = matches
self . matches = matches
class TeamSummon :
class TeamSummon :
def __init__ ( self , names , date , weight , stage , image ) :
def __init__ ( self , names , date , weight , stage , court , image ) :
self . names = names
self . names = names
self . date = date
self . date = date
self . weight = weight
self . weight = weight
self . stage = stage
self . stage = stage
self . court = court
self . image = image
self . image = image
def formatted_date ( self ) :
def formatted_date ( self ) :
@ -741,6 +774,7 @@ class TeamSummon:
" date " : self . formatted_date ( ) ,
" date " : self . formatted_date ( ) ,
" weight " : self . weight ,
" weight " : self . weight ,
" stage " : self . stage ,
" stage " : self . stage ,
" court " : self . court ,
" image " : self . image ,
" image " : self . image ,
}
}