|
|
|
|
@ -690,32 +690,34 @@ class CustomPasswordResetConfirmView(PasswordResetConfirmView): |
|
|
|
|
|
|
|
|
|
@login_required |
|
|
|
|
def my_tournaments(request): |
|
|
|
|
user = request.user # Get the currently authenticated user |
|
|
|
|
|
|
|
|
|
# Assuming the authenticated user has a `licence_id` attribute |
|
|
|
|
user = request.user |
|
|
|
|
user_licence_id = request.user.licence_id |
|
|
|
|
|
|
|
|
|
# Check if licence_id is None |
|
|
|
|
# If no licence_id, return empty lists |
|
|
|
|
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/my_tournaments.html', { |
|
|
|
|
'upcoming_tournaments': [], |
|
|
|
|
'running_tournaments': [], |
|
|
|
|
'ended_tournaments': [], |
|
|
|
|
'user_name': user.username |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
# Get all tournaments for the user based on their licence |
|
|
|
|
validator = LicenseValidator(user_licence_id) |
|
|
|
|
stripped_license = validator.stripped_license |
|
|
|
|
|
|
|
|
|
# Current time |
|
|
|
|
current_time = timezone.now() |
|
|
|
|
def filter_user_tournaments(tournaments): |
|
|
|
|
return [t for t in tournaments if t.teamregistration_set.filter( |
|
|
|
|
playerregistration__licence_id__startswith=stripped_license, |
|
|
|
|
walk_out=False |
|
|
|
|
).exists()] |
|
|
|
|
|
|
|
|
|
# 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) |
|
|
|
|
# Get filtered tournaments using the helper function |
|
|
|
|
upcoming_tournaments = filter_user_tournaments(future_tournaments(None)) |
|
|
|
|
running_tournaments = filter_user_tournaments(live_tournaments(None)) |
|
|
|
|
ended_tournaments = filter_user_tournaments(finished_tournaments(None)) |
|
|
|
|
|
|
|
|
|
return render(request, 'registration/my_tournaments.html', { |
|
|
|
|
'tournaments': tournaments, |
|
|
|
|
'upcoming_tournaments': upcoming_tournaments, |
|
|
|
|
'running_tournaments': running_tournaments, |
|
|
|
|
'ended_tournaments': ended_tournaments, |
|
|
|
|
|