|
|
|
|
@ -102,20 +102,28 @@ def future_tournaments(club_id): |
|
|
|
|
|
|
|
|
|
def tournament_info(request, tournament_id): |
|
|
|
|
tournament = get_object_or_404(Tournament, pk=tournament_id) |
|
|
|
|
is_registered = False |
|
|
|
|
registered_user = None |
|
|
|
|
team_registration = None |
|
|
|
|
|
|
|
|
|
if request.user.is_authenticated: |
|
|
|
|
# Assuming user's licence_id is stored in the user profile (e.g., request.user.profile.licence_id) |
|
|
|
|
# Assuming user's licence_id is stored in the user profile (e.g., request.user.licence_id) |
|
|
|
|
user_licence_id = request.user.licence_id |
|
|
|
|
# Check if there is a PlayerRegistration for this user in this tournament |
|
|
|
|
is_registered = PlayerRegistration.objects.filter( |
|
|
|
|
licence_id__startswith=user_licence_id, |
|
|
|
|
team_registration__tournament=tournament |
|
|
|
|
).exists() |
|
|
|
|
if user_licence_id is not None: |
|
|
|
|
validator = LicenseValidator(user_licence_id) |
|
|
|
|
stripped_license = validator.stripped_license |
|
|
|
|
# Check if there is a PlayerRegistration for this user in this tournament |
|
|
|
|
registered_user = PlayerRegistration.objects.filter( |
|
|
|
|
licence_id__startswith=stripped_license, |
|
|
|
|
team_registration__tournament=tournament |
|
|
|
|
).first() |
|
|
|
|
|
|
|
|
|
# If the user is registered, retrieve their team registration |
|
|
|
|
if registered_user: |
|
|
|
|
team_registration = registered_user.team_registration |
|
|
|
|
|
|
|
|
|
return render(request, 'tournaments/tournament_info.html', { |
|
|
|
|
'tournament': tournament, |
|
|
|
|
'is_registered': is_registered, |
|
|
|
|
'team': team_registration, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -552,8 +560,19 @@ def send_verification_email(request, user): |
|
|
|
|
def profile(request): |
|
|
|
|
user = request.user # Get the currently authenticated user |
|
|
|
|
|
|
|
|
|
# Query tournaments where the user is registered |
|
|
|
|
tournaments = Tournament.objects.all() |
|
|
|
|
# Assuming the authenticated user has a `licence_id` attribute |
|
|
|
|
user_licence_id = request.user.licence_id |
|
|
|
|
|
|
|
|
|
# Check if licence_id is None |
|
|
|
|
if user_licence_id is None: |
|
|
|
|
tournaments = Tournament.objects.none() # Return an empty queryset |
|
|
|
|
else: |
|
|
|
|
validator = LicenseValidator(user_licence_id) |
|
|
|
|
stripped_license = validator.stripped_license |
|
|
|
|
# Filter tournaments where the authenticated user's licence_id starts with the given value |
|
|
|
|
tournaments = Tournament.objects.filter( |
|
|
|
|
teamregistration__playerregistration__licence_id__startswith=stripped_license |
|
|
|
|
).distinct().order_by('-start_date') |
|
|
|
|
|
|
|
|
|
return render(request, 'registration/profile.html', { |
|
|
|
|
'tournaments': tournaments, |
|
|
|
|
|