diff --git a/tournaments/migrations/0104_remove_tournament_target_team_count.py b/tournaments/migrations/0104_remove_tournament_target_team_count.py new file mode 100644 index 0000000..3550ec0 --- /dev/null +++ b/tournaments/migrations/0104_remove_tournament_target_team_count.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.11 on 2024-12-20 13:33 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('tournaments', '0103_remove_unregisteredplayer_reason_and_more'), + ] + + operations = [ + migrations.RemoveField( + model_name='tournament', + name='target_team_count', + ), + ] diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index a9a5b1c..ed2bc24 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -69,7 +69,6 @@ class Tournament(models.Model): enable_online_registration = models.BooleanField(default=False) # Equivalent to Bool = false registration_date_limit = models.DateTimeField(null=True, blank=True) # Equivalent to Date? = nil opening_registration_date = models.DateTimeField(null=True, blank=True) # Equivalent to Date? = nil - target_team_count = models.IntegerField(null=True, blank=True) # Equivalent to Int? = nil waiting_list_limit = models.IntegerField(null=True, blank=True) # Equivalent to Int? = nil account_is_required = models.BooleanField(default=True) license_is_required = models.BooleanField(default=True) @@ -307,14 +306,17 @@ class Tournament(models.Model): if team.team_registration.id == team_registration.id: index = i - # Check if target_team_count exists - if self.target_team_count: + # Check if team_count exists + if self.team_count: # Team is not in list - if index < self.target_team_count: + if index < self.team_count: + print("Team is not in list", index, self.team_count) return -1 # Return position in waiting list relative to target count - return index - self.target_team_count + print("Return position in waiting list relative to target count", index, self.team_count) + return index - self.team_count else: + print("else", index, self.team_count) return -1 def teams(self, includeWaitingList): @@ -380,7 +382,7 @@ class Tournament(models.Model): # print(f"Group stage members count: {group_stage_members_count}") if self.team_sorting == TeamSortingType.INSCRIPTION_DATE: - complete_teams.sort(key=lambda s: (s.date is None, s.date or datetime.min, s.initial_weight, s.team_registration.id)) + complete_teams.sort(key=lambda s: (s.registration_date is None, s.registration_date or datetime.min, s.initial_weight, s.team_registration.id)) else: complete_teams.sort(key=lambda s: (s.initial_weight, s.team_registration.id)) @@ -409,7 +411,7 @@ class Tournament(models.Model): if waiting_list_count > 0: waiting_teams = waiting_teams + complete_teams[-waiting_list_count:] if self.team_sorting == TeamSortingType.INSCRIPTION_DATE: - waiting_teams.sort(key=lambda s: (s.date is None, s.date or datetime.min, s.initial_weight, s.team_registration.id)) + waiting_teams.sort(key=lambda s: (s.registration_date is None, s.registration_date or datetime.min, s.initial_weight, s.team_registration.id)) else: waiting_teams.sort(key=lambda s: (s.initial_weight, s.team_registration.id)) else: @@ -923,8 +925,8 @@ class Tournament(models.Model): options.append(f"Clôture des inscriptions le {date}") # Cible d'équipes - if self.target_team_count: - options.append(f"Maximum {self.target_team_count} équipes") + if self.team_count: + options.append(f"Maximum {self.team_count} équipes") # Liste d'attente if self.waiting_list_limit: @@ -973,11 +975,11 @@ class Tournament(models.Model): return False # Check target team count and waiting list limit - if self.target_team_count is not None: + if self.team_count is not None: current_team_count = len([tr for tr in self.teamregistration_set.all() if tr.out_of_tournament() is False]) - if current_team_count >= self.target_team_count: + if current_team_count >= self.team_count: if self.waiting_list_limit is not None: - waiting_list_count = current_team_count - self.target_team_count + waiting_list_count = current_team_count - self.team_count if waiting_list_count >= self.waiting_list_limit: return False return True @@ -1002,12 +1004,12 @@ class Tournament(models.Model): if now > timezoned_datetime: return OnlineRegistrationStatus.ENDED - if self.target_team_count is not None: + if self.team_count is not None: # Get all team registrations excluding walk_outs current_team_count = len([tr for tr in self.teamregistration_set.all() if tr.out_of_tournament() is False]) - if current_team_count >= self.target_team_count: + if current_team_count >= self.team_count: if self.waiting_list_limit is not None: - waiting_list_count = current_team_count - self.target_team_count + waiting_list_count = current_team_count - self.team_count if waiting_list_count >= self.waiting_list_limit: return OnlineRegistrationStatus.WAITING_LIST_FULL return OnlineRegistrationStatus.WAITING_LIST_POSSIBLE @@ -1035,19 +1037,19 @@ class Tournament(models.Model): def get_waiting_list_position(self): # If no target team count exists, no one goes to waiting list - if self.target_team_count is None: + if self.team_count is None: return -1 # Get count of active teams (not walked out) current_team_count = len([tr for tr in self.teamregistration_set.all() if tr.out_of_tournament() is False]) # If current count is less than target count, next team is not in waiting list - if current_team_count < self.target_team_count: + if current_team_count < self.team_count: return -1 # If we have a waiting list limit if self.waiting_list_limit is not None: - waiting_list_count = current_team_count - self.target_team_count + waiting_list_count = current_team_count - self.team_count # If waiting list is full if waiting_list_count >= self.waiting_list_limit: return -1 @@ -1055,7 +1057,7 @@ class Tournament(models.Model): return waiting_list_count # In waiting list with no limit - return current_team_count - self.target_team_count + return current_team_count - self.team_count def build_tournament_details_str(self): tournament_details = [] @@ -1178,7 +1180,7 @@ class TeamSummon: class TeamItem: def __init__(self, team_registration): self.names = team_registration.team_names() - self.date = team_registration.local_call_date() + self.registration_date = team_registration.registration_date self.weight = team_registration.weight self.initial_weight = team_registration.initial_weight() self.image = team_registration.logo @@ -1193,7 +1195,7 @@ class TeamItem: def to_dict(self): return { "names": self.names, - "date": self.date, + "registration_date": self.registration_date, "weight": self.weight, "initial_weight": self.initial_weight, "image": self.image, diff --git a/tournaments/services/tournament_registration.py b/tournaments/services/tournament_registration.py index 8550c14..c5d7168 100644 --- a/tournaments/services/tournament_registration.py +++ b/tournaments/services/tournament_registration.py @@ -3,7 +3,7 @@ from ..forms import TournamentRegistrationForm, AddPlayerForm from ..repositories import TournamentRegistrationRepository from .email_service import TournamentEmailService from django.contrib import messages -from ..validators import LicenseValidator +from ..utils.licence_validator import LicenseValidator from ..utils.player_search import get_player_name_from_csv from tournaments.models import PlayerRegistration @@ -138,7 +138,7 @@ class TournamentRegistrationService: def _get_authenticated_user_data(self): from ..utils.player_search import get_player_name_from_csv - from ..validators import LicenseValidator + from ..utils.licence_validator import LicenseValidator user = self.request.user validator = LicenseValidator(user.licence_id) diff --git a/tournaments/templates/tournaments/team_row.html b/tournaments/templates/tournaments/team_row.html index 09867b8..324a0b7 100644 --- a/tournaments/templates/tournaments/team_row.html +++ b/tournaments/templates/tournaments/team_row.html @@ -12,6 +12,10 @@
{{ name }}
{% endfor %} + {% else %} +
+
Réservé
+
{% endif %} {% if tournament.hide_teams_weight %}
diff --git a/tournaments/templates/tournaments/tournament_info.html b/tournaments/templates/tournaments/tournament_info.html index ce77a9b..583c1ea 100644 --- a/tournaments/templates/tournaments/tournament_info.html +++ b/tournaments/templates/tournaments/tournament_info.html @@ -121,21 +121,22 @@

Votre équipe

-
+
{% if team.is_in_waiting_list >= 0 %} Vous êtes en liste d'attente. +
{% if team.is_in_waiting_list == 1 %} - {{ tournament.get_waiting_list_position }} équipe en liste d'attente devant vous - {% elif tournament.get_waiting_list_position > 1 %} - {{ tournament.get_waiting_list_position }} équipes en liste d'attente devant vous - {% elif tournament.get_waiting_list_position == 0 %} + {{ team.is_in_waiting_list }} équipe en liste d'attente devant vous + {% elif team.is_in_waiting_list > 1 %} + {{ team.is_in_waiting_list }} équipes en liste d'attente devant vous + {% elif team.is_in_waiting_list == 0 %} Aucune équipe en liste d'attente devant vous {% endif %} +
{% endif %}
-

-

+
{% for player in team.players %}
{{ player.name }}
{% endfor %} @@ -158,7 +159,7 @@ class="rounded-button destructive-button" onclick="return confirm('Êtes-vous sûr de vouloir vous désinscrire ?');"> {% if team.is_in_waiting_list >= 0 %} - Se retirer de la liste d'attente {{ team.is_in_waiting_list }} + Se retirer de la liste d'attente {% else %} Se désinscrire {% endif %}