fix mixte management in registration process

sync_v2
Razmig Sarkissian 5 months ago
parent a7c33a9ee0
commit 1ce168847a
  1. 21
      tournaments/services/tournament_registration.py
  2. 6
      tournaments/utils/player_search.py

@ -156,6 +156,7 @@ class RegistrationCartManager:
def add_player(self, player_data):
"""Add a player to the registration cart"""
print("add_player", player_data)
if self.is_cart_expired():
return False, "Votre session d'inscription a expiré, veuillez réessayer."
@ -190,21 +191,30 @@ class RegistrationCartManager:
return result # Return the error
tournament_federal_category = tournament.federal_category
if tournament_federal_category == FederalCategory.MIXED and len(players) == 1:
other_player_is_woman = players[0].get('is_woman', False)
if other_player_is_woman is False:
tournament_federal_category = FederalCategory.WOMEN
if licence_id:
# Get federation data
fed_data, found = get_player_name_from_csv(tournament_federal_category, licence_id)
if found is False and fed_data:
is_woman = fed_data.get('is_woman', False)
if tournament_federal_category == FederalCategory.MIXED and len(players) == 1:
other_player_is_woman = players[0].get('is_woman', False)
if other_player_is_woman == is_woman:
is_woman = not is_woman
player_data.update({
'rank': fed_data['rank'],
'is_woman': fed_data['is_woman'],
'is_woman': is_woman,
})
if found and fed_data:
# Use federation data (including check for eligibility)
if tournament_federal_category == FederalCategory.MIXED and len(players) == 1:
is_woman = fed_data.get('is_woman', False)
other_player_is_woman = players[0].get('is_woman', False)
if other_player_is_woman == is_woman:
return False, f"En mixte l'équipe doit obligatoirement contenir une joueuse et un joueur. La licence {licence_id} correspond à {'une' if is_woman else 'un'} {'femme' if is_woman else 'homme'}."
player_register_check = tournament.player_register_check(licence_id)
if player_register_check:
return False, ", ".join(player_register_check)
@ -227,6 +237,7 @@ class RegistrationCartManager:
})
elif not first_name or not last_name:
# License not required or not found, but name is needed
print("Le prénom et le nom sont obligatoires pour les joueurs dont la licence n'a pas été trouvée.")
self.first_tournament = True
return False, "Le prénom et le nom sont obligatoires pour les joueurs dont la licence n'a pas été trouvée."
elif not tournament.license_is_required:

@ -5,6 +5,7 @@ from datetime import datetime
from django.conf import settings
from tournaments.models.enums import FederalCategory
from string import printable
def clean_licence_id(licence_id):
# This regex matches the trailing letters (non-digits) and removes them
@ -29,7 +30,7 @@ def get_player_name_from_csv(category, licence_id, base_folder=None):
else:
cleaned_licence_id = None
print("get_player_name_from_csv", cleaned_licence_id)
print("get_player_name_from_csv", cleaned_licence_id, folder_path)
def extract_date(file_name):
"""
@ -108,12 +109,13 @@ def get_player_name_from_csv(category, licence_id, base_folder=None):
return None, False
print("Look for woman", FederalCategory.WOMEN)
dames_file = find_most_recent_file("CLASSEMENT-PADEL-DAMES-")
result, found = search_file(dames_file, True)
if found or category is FederalCategory.WOMEN:
return result, found
print("Look for man")
messieurs_file = find_most_recent_file("CLASSEMENT-PADEL-MESSIEURS-")
result, found = search_file(messieurs_file, False)
return result, found

Loading…
Cancel
Save