|
|
|
|
@ -9,6 +9,7 @@ from django.core.files.storage import default_storage |
|
|
|
|
from django.core.files.base import ContentFile |
|
|
|
|
|
|
|
|
|
from tournaments.models.device_token import DeviceToken |
|
|
|
|
from tournaments.models.player_enums import PlayerDataSource |
|
|
|
|
|
|
|
|
|
from .models import Court, DateInterval, Club, Tournament, CustomUser, Event, Round, GroupStage, Match, TeamScore, TeamRegistration, PlayerRegistration, Purchase, FailedApiCall |
|
|
|
|
from .models import TeamSummon |
|
|
|
|
@ -104,6 +105,7 @@ def tournament_info(request, tournament_id): |
|
|
|
|
tournament = get_object_or_404(Tournament, pk=tournament_id) |
|
|
|
|
registered_user = None |
|
|
|
|
team_registration = None |
|
|
|
|
is_captain = False |
|
|
|
|
|
|
|
|
|
if request.user.is_authenticated: |
|
|
|
|
# Assuming user's licence_id is stored in the user profile (e.g., request.user.licence_id) |
|
|
|
|
@ -119,11 +121,13 @@ def tournament_info(request, tournament_id): |
|
|
|
|
|
|
|
|
|
# If the user is registered, retrieve their team registration |
|
|
|
|
if registered_user: |
|
|
|
|
is_captain = registered_user.captain |
|
|
|
|
team_registration = registered_user.team_registration |
|
|
|
|
|
|
|
|
|
return render(request, 'tournaments/tournament_info.html', { |
|
|
|
|
'tournament': tournament, |
|
|
|
|
'team': team_registration, |
|
|
|
|
'is_captain': is_captain |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -574,8 +578,19 @@ def profile(request): |
|
|
|
|
teamregistration__playerregistration__licence_id__startswith=stripped_license |
|
|
|
|
).distinct().order_by('-start_date') |
|
|
|
|
|
|
|
|
|
# Current time |
|
|
|
|
current_time = timezone.now() |
|
|
|
|
|
|
|
|
|
# Separate tournaments into categories |
|
|
|
|
upcoming_tournaments = tournaments.filter(start_date__gt=current_time) |
|
|
|
|
running_tournaments = tournaments.filter(start_date__lte=current_time, end_date=None) |
|
|
|
|
ended_tournaments = tournaments.filter(end_date__isnull=False) |
|
|
|
|
|
|
|
|
|
return render(request, 'registration/profile.html', { |
|
|
|
|
'tournaments': tournaments, |
|
|
|
|
'upcoming_tournaments': upcoming_tournaments, |
|
|
|
|
'running_tournaments': running_tournaments, |
|
|
|
|
'ended_tournaments': ended_tournaments, |
|
|
|
|
'user_name': user.username |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
@ -638,10 +653,11 @@ def register_tournament(request, tournament_id): |
|
|
|
|
else: |
|
|
|
|
if add_player_form.first_tournament is False: |
|
|
|
|
# Retrieve player names from the CSV file |
|
|
|
|
first_name, last_name = get_player_name_from_csv(licence_id) |
|
|
|
|
if first_name and last_name: |
|
|
|
|
first_name, last_name, rank = get_player_name_from_csv(licence_id) |
|
|
|
|
if first_name and last_name and rank: |
|
|
|
|
player_data['first_name'] = first_name |
|
|
|
|
player_data['last_name'] = last_name |
|
|
|
|
player_data['rank'] = rank |
|
|
|
|
# If validation passes, add the player to the session without clearing previous ones |
|
|
|
|
request.session['team_registration'].append(player_data) |
|
|
|
|
request.session.modified = True # Ensure session is updated |
|
|
|
|
@ -656,17 +672,33 @@ def register_tournament(request, tournament_id): |
|
|
|
|
tournament=tournament, |
|
|
|
|
registration_date=timezone.now() |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
stripped_license = None |
|
|
|
|
if request.user.licence_id is not None: |
|
|
|
|
stripped_license = LicenseValidator(request.user.licence_id).stripped_license |
|
|
|
|
|
|
|
|
|
# Create PlayerRegistration objects for each player in the session |
|
|
|
|
for player_data in request.session['team_registration']: |
|
|
|
|
is_captain = False |
|
|
|
|
player_licence_id = player_data['licence_id'] |
|
|
|
|
if player_licence_id is not None and stripped_license is not None: |
|
|
|
|
if player_licence_id.startswith(stripped_license): |
|
|
|
|
is_captain = True |
|
|
|
|
|
|
|
|
|
player_registration = PlayerRegistration.objects.create( |
|
|
|
|
team_registration=team_registration, |
|
|
|
|
captain=is_captain, |
|
|
|
|
source=PlayerDataSource.ONLINE_REGISTRATION, |
|
|
|
|
first_name=player_data['first_name'], |
|
|
|
|
last_name=player_data['last_name'], |
|
|
|
|
rank = player_data.get('rank', 70000), |
|
|
|
|
licence_id=player_data['licence_id'], |
|
|
|
|
email = player_data.get('email', None), |
|
|
|
|
phone_number = player_data.get('phone_number', None) |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
team_registration.set_weight() |
|
|
|
|
|
|
|
|
|
request.session['team_registration'] = [] |
|
|
|
|
registration_successful = True |
|
|
|
|
else: |
|
|
|
|
@ -688,6 +720,13 @@ def register_tournament(request, tournament_id): |
|
|
|
|
'phone': request.user.phone, |
|
|
|
|
'licence_id': request.user.licence_id, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
first_name, last_name, rank = get_player_name_from_csv(request.user.licence_id) |
|
|
|
|
if first_name and last_name and rank: |
|
|
|
|
validator = LicenseValidator(request.user.licence_id) |
|
|
|
|
player_data['licence_id'] = validator.computed_licence_id |
|
|
|
|
player_data['rank'] = rank |
|
|
|
|
|
|
|
|
|
request.session['team_registration'].insert(0, player_data) # Add them as the first player |
|
|
|
|
request.session.modified = True # Ensure session is updated |
|
|
|
|
|
|
|
|
|
|