Use club timezone for matchs, tournaments and summons

tz
Laurent 1 year ago
parent bd941387c2
commit fcf43d1084
  1. 18
      tournaments/migrations/0091_club_timezone.py
  2. 2
      tournaments/models/club.py
  3. 28
      tournaments/models/match.py
  4. 12
      tournaments/models/tournament.py
  5. 2
      tournaments/templates/tournaments/broadcast/broadcasted_match.html
  6. 4
      tournaments/templates/tournaments/match_cell.html
  7. 2
      tournaments/templates/tournaments/summon_row.html
  8. 3
      tournaments/templates/tournaments/tournament_info.html

File diff suppressed because one or more lines are too long

@ -17,7 +17,7 @@ class Club(models.Model):
latitude = models.FloatField(null=True, blank=True) latitude = models.FloatField(null=True, blank=True)
longitude = models.FloatField(null=True, blank=True) longitude = models.FloatField(null=True, blank=True)
timezone = models.CharField( timezone = models.CharField(
max_length=50, max_length=50, null=True, blank=True,
choices=[(tz, tz) for tz in sorted(available_timezones())], choices=[(tz, tz) for tz in sorted(available_timezones())],
default='CET' default='CET'
) )

@ -79,16 +79,16 @@ class Match(models.Model):
def player_names(self): def player_names(self):
return map(lambda ts: ts.player_names(), self.team_scores.all()) return map(lambda ts: ts.player_names(), self.team_scores.all())
def local_start_date(self):
timezone = self.tournament().timezone()
return self.start_date.astimezone(timezone)
def formatted_start_date(self): def formatted_start_date(self):
if self.start_date: if self.start_date:
timezone = self.tournament().timezone() local_start = self.local_start_date()
local_start = self.start_date.astimezone(timezone)
# timezoned_datetime = timezone.localtime(self.start_date)
return formats.date_format(local_start, format='H:i') return formats.date_format(local_start, format='H:i')
# return formats.date_format(self.start_date, format='H:i')
else: else:
return '' return ''
# return str(self.start_date) #.strftime("%H:%M")
def time_indication(self): def time_indication(self):
if self.end_date: if self.end_date:
@ -100,8 +100,10 @@ class Match(models.Model):
if self.started(): if self.started():
return self.formatted_duration() return self.formatted_duration()
else: else:
timezoned_datetime = timezone.localtime(self.start_date) # timezoned_datetime = timezone.localtime(self.start_date)
return formats.date_format(timezoned_datetime, format='l H:i') timezone = self.tournament().timezone()
local_start = self.start_date.astimezone(timezone)
return formats.date_format(local_start, format='l H:i')
else: else:
return 'À venir...' return 'À venir...'
@ -188,14 +190,14 @@ class Match(models.Model):
def live_match(self): def live_match(self):
title = self.name if self.name else self.backup_name() title = self.name if self.name else self.backup_name()
date = self.formatted_start_date() date = self.formatted_start_date()
duration = self.time_indication() time_indication = self.time_indication()
court = self.court_name(self.court_index) court = self.court_name(self.court_index)
group_stage_name = None group_stage_name = None
if self.group_stage: if self.group_stage:
group_stage_name = self.group_stage.display_name() group_stage_name = self.group_stage.display_name()
ended = self.end_date is not None ended = self.end_date is not None
livematch = LiveMatch(title, date, duration, court, self.started(), ended, group_stage_name) livematch = LiveMatch(title, date, time_indication, court, self.started(), ended, group_stage_name)
for team_score in self.sorted_team_scores(): for team_score in self.sorted_team_scores():
if team_score.team_registration: if team_score.team_registration:
@ -257,11 +259,11 @@ class Team:
} }
class LiveMatch: class LiveMatch:
def __init__(self, title, date, duration, court, started, ended, group_stage_name): def __init__(self, title, date, time_indication, court, started, ended, group_stage_name):
self.title = title self.title = title
self.date = date self.date = date
self.teams = [] self.teams = []
self.duration = duration self.time_indication = time_indication
self.court = court self.court = court
self.started = started self.started = started
self.ended = ended self.ended = ended
@ -278,7 +280,7 @@ class LiveMatch:
"title": self.title, "title": self.title,
"date": self.date, "date": self.date,
"teams": [team.to_dict() for team in self.teams], "teams": [team.to_dict() for team in self.teams],
"duration": self.duration, "time_indication": self.time_indication,
"court": self.court, "court": self.court,
"started": self.started, "started": self.started,
"ended": self.ended, "ended": self.ended,
@ -286,7 +288,7 @@ class LiveMatch:
"group_stage_name": self.group_stage_name, "group_stage_name": self.group_stage_name,
} }
def show_duration(self): def show_time_indication(self):
for team in self.teams: for team in self.teams:
if team.walk_out and len(team.scores) == 0: if team.walk_out and len(team.scores) == 0:
return False return False

@ -138,6 +138,13 @@ class Tournament(models.Model):
tz = self.event.club.timezone tz = self.event.club.timezone
return ZoneInfo(tz) return ZoneInfo(tz)
def local_start_date(self):
timezone = self.timezone()
return self.start_date.astimezone(timezone)
def local_start_date_formatted(self):
return formats.date_format(self.local_start_date(), format='j F Y H:i')
def level(self): def level(self):
if self.federal_level_category == 0: if self.federal_level_category == 0:
return "Anim." return "Anim."
@ -240,7 +247,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, 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)
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))
@ -849,8 +856,7 @@ class TeamSummon:
def formatted_date(self): def formatted_date(self):
if self.date: if self.date:
timezoned_datetime = timezone.localtime(self.date) return formats.date_format(self.date, format='l H:i')
return formats.date_format(timezoned_datetime, format='l H:i')
else: else:
return None return None

@ -51,7 +51,7 @@
</template> </template>
<div class="top-margin flex-row"> <div class="top-margin flex-row">
<label class="left-label minor-info bold"><span x-text="match.duration"></span></label> <label class="left-label minor-info bold"><span x-text="match.time_indication"></span></label>
<label class="right-label minor-info semibold"><span x-text="match.court"></span></label> <label class="right-label minor-info semibold"><span x-text="match.court"></span></label>
</div> </div>

@ -42,8 +42,8 @@
<div class="flex-row top-margin"> <div class="flex-row top-margin">
<label class="left-label minor-info bold"> <label class="left-label minor-info bold">
{% if match.show_duration %} {% if match.show_time_indication %}
{{ match.duration }} {{ match.time_indication }}
{% endif %} {% endif %}
</label> </label>
<label class="right-label minor-info"> <label class="right-label minor-info">

@ -9,7 +9,7 @@
</div> </div>
<div class="table-cell left"> <div class="table-cell left">
<div class="table-cell large">{{ summon.date|date:'l H:i' }}</div> <div class="table-cell large">{{ summon.formatted_date }}</div>
<div class="table-cell">{{ summon.court }}</div> <div class="table-cell">{{ summon.court }}</div>
</div> </div>
<div class="table-cell right"><div class="mybox center">{{ summon.stage }}</div></div> <div class="table-cell right"><div class="mybox center">{{ summon.stage }}</div></div>

@ -7,6 +7,7 @@
{% block content %} {% block content %}
{% load static %} {% load static %}
{% load tz %}
{% include 'tournaments/navigation_tournament.html' %} {% include 'tournaments/navigation_tournament.html' %}
@ -17,7 +18,7 @@
<div class="bubble"> <div class="bubble">
<p> <p>
<div class="semibold">{{ tournament.start_date }}</div> <div class="semibold">{{ tournament.local_start_date_formatted }}</div>
<div>{{ tournament.day_duration_formatted }}</div> <div>{{ tournament.day_duration_formatted }}</div>
<div>{{ tournament.court_count }} terrains</div> <div>{{ tournament.court_count }} terrains</div>
</p> </p>

Loading…
Cancel
Save