|
|
|
|
@ -14,6 +14,7 @@ from zoneinfo import ZoneInfo |
|
|
|
|
from tournaments.utils.player_search import get_player_name_from_csv |
|
|
|
|
from shared.cryptography import encryption_util |
|
|
|
|
from ..utils.extensions import plural_format |
|
|
|
|
from ..utils.licence_validator import LicenseValidator |
|
|
|
|
|
|
|
|
|
class TeamSortingType(models.IntegerChoices): |
|
|
|
|
RANK = 1, 'Rank' |
|
|
|
|
@ -170,7 +171,10 @@ class Tournament(models.Model): |
|
|
|
|
return self.get_federal_age_category_display() |
|
|
|
|
|
|
|
|
|
def formatted_start_date(self): |
|
|
|
|
return self.start_date.strftime("%d/%m/%y") |
|
|
|
|
return formats.date_format(self.start_date, format='d/m/Y') |
|
|
|
|
|
|
|
|
|
def formatted_start_date_short(self): |
|
|
|
|
return formats.date_format(self.start_date, format='l d/m/Y') |
|
|
|
|
|
|
|
|
|
def in_progress(self): |
|
|
|
|
return self.end_date is None |
|
|
|
|
@ -210,33 +214,92 @@ class Tournament(models.Model): |
|
|
|
|
else: |
|
|
|
|
return None |
|
|
|
|
|
|
|
|
|
def tournament_status_display(self): |
|
|
|
|
if self.is_canceled() is True: |
|
|
|
|
return "Annulé" |
|
|
|
|
def status_header(self): |
|
|
|
|
if self.supposedly_in_progress() or self.end_date is not None or self.should_be_over(): |
|
|
|
|
return "Statut" |
|
|
|
|
if self.end_date is not None or self.should_be_over(): |
|
|
|
|
return "Classement" |
|
|
|
|
return "Inscriptions" |
|
|
|
|
|
|
|
|
|
def tournament_status_display(self): |
|
|
|
|
teams = self.teams(True) |
|
|
|
|
if self.supposedly_in_progress() or self.end_date is not None or self.should_be_over(): |
|
|
|
|
teams = [t for t in teams if t.stage != "Attente"] |
|
|
|
|
if teams is not None and len(teams) > 0: |
|
|
|
|
word = "équipe" |
|
|
|
|
if len(teams) > 1: |
|
|
|
|
word = word + "s" |
|
|
|
|
return f"{len(teams)} {word}" |
|
|
|
|
else: |
|
|
|
|
return f"{len(teams)}" |
|
|
|
|
|
|
|
|
|
return f"{len(teams)}" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def tournament_user_team(self, user): |
|
|
|
|
team_registration = None |
|
|
|
|
|
|
|
|
|
if user.is_authenticated: |
|
|
|
|
# Assuming user's licence_id is stored in the user profile (e.g., request.user.licence_id) |
|
|
|
|
user_licence_id = user.licence_id |
|
|
|
|
player_register_check = self.player_register_check(user_licence_id) |
|
|
|
|
registered_user = None |
|
|
|
|
if user_licence_id is not None and player_register_check is None: |
|
|
|
|
validator = LicenseValidator(user_licence_id) |
|
|
|
|
stripped_license = validator.stripped_license |
|
|
|
|
# Check if there is a PlayerRegistration for this user in this tournament |
|
|
|
|
from tournaments.models import PlayerRegistration |
|
|
|
|
registered_user = PlayerRegistration.objects.filter( |
|
|
|
|
licence_id__startswith=stripped_license, |
|
|
|
|
team_registration__tournament=self, |
|
|
|
|
).first() |
|
|
|
|
|
|
|
|
|
# If the user is registered, retrieve their team registration |
|
|
|
|
if registered_user: |
|
|
|
|
team_registration = registered_user.team_registration |
|
|
|
|
|
|
|
|
|
return team_registration |
|
|
|
|
|
|
|
|
|
def tournament_register_status_display(self, user): |
|
|
|
|
# if user.is_authenticated: |
|
|
|
|
# return f"confirmée" |
|
|
|
|
# else: |
|
|
|
|
# return "ouverte" |
|
|
|
|
# |
|
|
|
|
team_registration = None |
|
|
|
|
if user and user.is_authenticated: |
|
|
|
|
team_registration = self.tournament_user_team(user) |
|
|
|
|
team_status = self.team_status(team_registration) |
|
|
|
|
if team_status and team_registration: |
|
|
|
|
if team_status is OnlineRegistrationStatus.ENDED_WITH_RESULTS and team_registration.get_points_earned(): |
|
|
|
|
message = f"+{team_registration.get_points_earned()} pts" |
|
|
|
|
return message, team_status.color(), team_status.text_color() |
|
|
|
|
return team_status.status_localized(), team_status.color(), team_status.text_color() |
|
|
|
|
if team_status: |
|
|
|
|
return team_status.status_localized(), team_status.color(), team_status.text_color() |
|
|
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def team_status(self, team_registration): |
|
|
|
|
if team_registration: |
|
|
|
|
if team_registration.out_of_tournament(): |
|
|
|
|
return OnlineRegistrationStatus.WALKOUT |
|
|
|
|
elif team_registration.is_in_waiting_list() >= 0: |
|
|
|
|
return OnlineRegistrationStatus.WAITING_LIST |
|
|
|
|
elif self.end_date is not None or self.should_be_over(): |
|
|
|
|
return self.get_online_registration_status() |
|
|
|
|
elif self.supposedly_in_progress(): |
|
|
|
|
return OnlineRegistrationStatus.USER_IN_PROGRESS |
|
|
|
|
return OnlineRegistrationStatus.CONFIRMED |
|
|
|
|
|
|
|
|
|
if self.end_date is not None or self.should_be_over(): |
|
|
|
|
return None |
|
|
|
|
|
|
|
|
|
if self.is_canceled() is True: |
|
|
|
|
return OnlineRegistrationStatus.CANCELED |
|
|
|
|
|
|
|
|
|
if self.enable_online_registration is False: |
|
|
|
|
return None |
|
|
|
|
|
|
|
|
|
return self.get_online_registration_status() |
|
|
|
|
registration_status = None |
|
|
|
|
if self.enable_online_registration == True: |
|
|
|
|
registration_status = self.get_online_registration_status().status_localized() |
|
|
|
|
if teams is not None and len(teams) > 0: |
|
|
|
|
word = "inscription" |
|
|
|
|
if len(teams) > 1: |
|
|
|
|
word = word + "s" |
|
|
|
|
if registration_status is not None: |
|
|
|
|
return f"{registration_status}\n{len(teams)} {word}" |
|
|
|
|
else: |
|
|
|
|
return f"{len(teams)} {word}" |
|
|
|
|
else: |
|
|
|
|
if registration_status is not None: |
|
|
|
|
return f"{registration_status}" |
|
|
|
|
return None |
|
|
|
|
@ -1055,12 +1118,12 @@ class Tournament(models.Model): |
|
|
|
|
return True |
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
if self.end_date is not None: |
|
|
|
|
return OnlineRegistrationStatus.ENDED_WITH_RESULTS |
|
|
|
|
if self.supposedly_in_progress(): |
|
|
|
|
return OnlineRegistrationStatus.IN_PROGRESS |
|
|
|
|
|
|
|
|
|
now = timezone.now() |
|
|
|
|
|
|
|
|
|
|