|
|
|
@ -1,3 +1,4 @@ |
|
|
|
|
|
|
|
from time import daylight |
|
|
|
from zoneinfo import ZoneInfo |
|
|
|
from zoneinfo import ZoneInfo |
|
|
|
from django.db import models |
|
|
|
from django.db import models |
|
|
|
from typing import TYPE_CHECKING |
|
|
|
from typing import TYPE_CHECKING |
|
|
|
@ -232,15 +233,16 @@ class Tournament(models.Model): |
|
|
|
|
|
|
|
|
|
|
|
def team_summons(self): |
|
|
|
def team_summons(self): |
|
|
|
summons = [] |
|
|
|
summons = [] |
|
|
|
print('>>> team_summons') |
|
|
|
|
|
|
|
if self.supposedly_in_progress() and self.end_date is None: |
|
|
|
if self.supposedly_in_progress() and self.end_date is None: |
|
|
|
|
|
|
|
print('>>> team_summons supposedly_in_progress') |
|
|
|
for team in self.teams(False): |
|
|
|
for team in self.teams(False): |
|
|
|
names = team.names |
|
|
|
names = team.names |
|
|
|
stage = team.stage |
|
|
|
stage = team.stage |
|
|
|
weight = team.weight |
|
|
|
weight = team.weight |
|
|
|
summon = TeamSummon(names, team.date, weight, stage, "", team.image) |
|
|
|
summon = TeamSummon(names, team.date, weight, stage, "", team.image, self.day_duration) |
|
|
|
summons.append(summon) |
|
|
|
summons.append(summon) |
|
|
|
else: |
|
|
|
else: |
|
|
|
|
|
|
|
print('>>> team_summons') |
|
|
|
for team_registration in self.teamregistration_set.all(): |
|
|
|
for team_registration in self.teamregistration_set.all(): |
|
|
|
if team_registration.is_valid_for_summon(): |
|
|
|
if team_registration.is_valid_for_summon(): |
|
|
|
next_match = team_registration.next_match() |
|
|
|
next_match = team_registration.next_match() |
|
|
|
@ -248,7 +250,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.local_start_date(), weight, stage, next_match.court_name(next_match.court_index), team_registration.logo) |
|
|
|
summon = TeamSummon(names, next_match.local_start_date(), weight, stage, next_match.court_name(next_match.court_index), team_registration.logo, self.day_duration) |
|
|
|
summons.append(summon) |
|
|
|
summons.append(summon) |
|
|
|
|
|
|
|
|
|
|
|
summons.sort(key=lambda s: (s.date is None, s.date or datetime.min)) |
|
|
|
summons.sort(key=lambda s: (s.date is None, s.date or datetime.min)) |
|
|
|
@ -484,7 +486,21 @@ class Tournament(models.Model): |
|
|
|
def create_match_group(self, name, matches): |
|
|
|
def create_match_group(self, name, matches): |
|
|
|
matches = list(matches) |
|
|
|
matches = list(matches) |
|
|
|
live_matches = [match.live_match() for match in matches] |
|
|
|
live_matches = [match.live_match() for match in matches] |
|
|
|
return MatchGroup(name, live_matches) |
|
|
|
# Filter out matches that have a start_date of None |
|
|
|
|
|
|
|
valid_matches = [match for match in matches if match.start_date is not None] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
formatted_schedule = '' |
|
|
|
|
|
|
|
if valid_matches and self.day_duration >= 7: |
|
|
|
|
|
|
|
# Find the first match by start date |
|
|
|
|
|
|
|
first_match = min(valid_matches, key=lambda match: match.start_date) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Format the date |
|
|
|
|
|
|
|
timezone = first_match.tournament().timezone() |
|
|
|
|
|
|
|
local_start = first_match.start_date.astimezone(timezone) |
|
|
|
|
|
|
|
time_format = 'l d M' |
|
|
|
|
|
|
|
formatted_schedule = f" - {formats.date_format(local_start, format=time_format)}" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return MatchGroup(name, live_matches, formatted_schedule) |
|
|
|
|
|
|
|
|
|
|
|
def live_group_stages(self): |
|
|
|
def live_group_stages(self): |
|
|
|
group_stages = self.get_computed_group_stage() |
|
|
|
group_stages = self.get_computed_group_stage() |
|
|
|
@ -855,9 +871,10 @@ class Tournament(models.Model): |
|
|
|
return True |
|
|
|
return True |
|
|
|
|
|
|
|
|
|
|
|
class MatchGroup: |
|
|
|
class MatchGroup: |
|
|
|
def __init__(self, name, matches): |
|
|
|
def __init__(self, name, matches, formatted_schedule): |
|
|
|
self.name = name |
|
|
|
self.name = name |
|
|
|
self.matches = matches |
|
|
|
self.matches = matches |
|
|
|
|
|
|
|
self.formatted_schedule = formatted_schedule |
|
|
|
|
|
|
|
|
|
|
|
def add_match(self, match): |
|
|
|
def add_match(self, match): |
|
|
|
self.matches.append(match) |
|
|
|
self.matches.append(match) |
|
|
|
@ -866,16 +883,20 @@ class MatchGroup: |
|
|
|
self.matches = matches |
|
|
|
self.matches = matches |
|
|
|
|
|
|
|
|
|
|
|
class TeamSummon: |
|
|
|
class TeamSummon: |
|
|
|
def __init__(self, names, date, weight, stage, court, image): |
|
|
|
def __init__(self, names, date, weight, stage, court, image, day_duration): |
|
|
|
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.court = court |
|
|
|
self.image = image |
|
|
|
self.image = image |
|
|
|
|
|
|
|
self.day_duration = day_duration |
|
|
|
|
|
|
|
|
|
|
|
def formatted_date(self): |
|
|
|
def formatted_date(self): |
|
|
|
if self.date: |
|
|
|
if self.date: |
|
|
|
|
|
|
|
if self.day_duration >= 7: |
|
|
|
|
|
|
|
return formats.date_format(self.date, format='l d M H:i') |
|
|
|
|
|
|
|
else: |
|
|
|
return formats.date_format(self.date, format='l H:i') |
|
|
|
return formats.date_format(self.date, format='l H:i') |
|
|
|
else: |
|
|
|
else: |
|
|
|
return '' |
|
|
|
return '' |
|
|
|
|