|
|
|
|
@ -1,6 +1,6 @@ |
|
|
|
|
from django.db import models |
|
|
|
|
# from tournaments.models import group_stage |
|
|
|
|
from . import SideStoreModel, Round, GroupStage, FederalMatchCategory |
|
|
|
|
from . import TournamentSubModel, Round, GroupStage, FederalMatchCategory |
|
|
|
|
from django.utils import timezone, formats |
|
|
|
|
from datetime import datetime, timedelta |
|
|
|
|
|
|
|
|
|
@ -8,7 +8,7 @@ import uuid |
|
|
|
|
|
|
|
|
|
from ..utils.extensions import format_seconds |
|
|
|
|
|
|
|
|
|
class Match(SideStoreModel): |
|
|
|
|
class Match(TournamentSubModel): |
|
|
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True) |
|
|
|
|
round = models.ForeignKey(Round, null=True, blank=True, on_delete=models.SET_NULL, related_name='matches') |
|
|
|
|
group_stage = models.ForeignKey(GroupStage, null=True, blank=True, on_delete=models.SET_NULL, related_name='matches') |
|
|
|
|
@ -39,29 +39,29 @@ class Match(SideStoreModel): |
|
|
|
|
else: |
|
|
|
|
return f"{self.stage_name()}" |
|
|
|
|
|
|
|
|
|
def save(self, *args, **kwargs): |
|
|
|
|
self.store_id = str(self.get_tournament_id()) |
|
|
|
|
super().save(*args, **kwargs) |
|
|
|
|
# def save(self, *args, **kwargs): |
|
|
|
|
# self.store_id = str(self.get_tournament_id()) |
|
|
|
|
# super().save(*args, **kwargs) |
|
|
|
|
|
|
|
|
|
def tournament(self): |
|
|
|
|
def get_tournament(self): # mandatory method for TournamentSubModel |
|
|
|
|
if self.round: |
|
|
|
|
return self.round.tournament |
|
|
|
|
elif self.group_stage: |
|
|
|
|
return self.group_stage.tournament |
|
|
|
|
return None |
|
|
|
|
|
|
|
|
|
def get_tournament_id(self): |
|
|
|
|
tournament = self.tournament() |
|
|
|
|
if tournament: |
|
|
|
|
return tournament.id |
|
|
|
|
else: |
|
|
|
|
return None |
|
|
|
|
# def get_tournament_id(self): |
|
|
|
|
# tournament = self.get_tournament() |
|
|
|
|
# if tournament: |
|
|
|
|
# return tournament.id |
|
|
|
|
# else: |
|
|
|
|
# return None |
|
|
|
|
|
|
|
|
|
def court_name(self, index): |
|
|
|
|
club = None |
|
|
|
|
tournament = self.tournament() |
|
|
|
|
tournament = self.get_tournament() |
|
|
|
|
if tournament and tournament.event: |
|
|
|
|
club = self.tournament().event.club |
|
|
|
|
club = self.get_tournament().event.club |
|
|
|
|
|
|
|
|
|
if club: |
|
|
|
|
return club.court_name(index) |
|
|
|
|
@ -167,7 +167,6 @@ class Match(SideStoreModel): |
|
|
|
|
|
|
|
|
|
return self.index |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def player_names(self): |
|
|
|
|
return map(lambda ts: ts.player_names(), self.team_scores.all()) |
|
|
|
|
|
|
|
|
|
@ -303,7 +302,7 @@ class Match(SideStoreModel): |
|
|
|
|
return teams |
|
|
|
|
|
|
|
|
|
def local_start_date(self): |
|
|
|
|
timezone = self.tournament().timezone() |
|
|
|
|
timezone = self.get_tournament().timezone() |
|
|
|
|
return self.start_date.astimezone(timezone) |
|
|
|
|
|
|
|
|
|
def formatted_start_date(self): |
|
|
|
|
@ -327,10 +326,10 @@ class Match(SideStoreModel): |
|
|
|
|
return 'À suivre' |
|
|
|
|
else: |
|
|
|
|
# timezoned_datetime = timezone.localtime(self.start_date) |
|
|
|
|
timezone = self.tournament().timezone() |
|
|
|
|
timezone = self.get_tournament().timezone() |
|
|
|
|
local_start = self.start_date.astimezone(timezone) |
|
|
|
|
time_format ='l H:i' |
|
|
|
|
if self.tournament().day_duration >= 7: |
|
|
|
|
if self.get_tournament().day_duration >= 7: |
|
|
|
|
time_format = 'l d M à H:i' |
|
|
|
|
if self.confirmed: |
|
|
|
|
return formats.date_format(local_start, format=time_format) |
|
|
|
|
|