|
|
|
@ -1702,6 +1702,63 @@ def toggle_tournament_private(request, tournament_id): |
|
|
|
messages.error(request, f'Erreur: {str(e)}') |
|
|
|
messages.error(request, f'Erreur: {str(e)}') |
|
|
|
return redirect('tournament-info', tournament_id=tournament_id) |
|
|
|
return redirect('tournament-info', tournament_id=tournament_id) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def private_tournaments(request): |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
View for displaying private tournaments (staff-only). |
|
|
|
|
|
|
|
Similar to index, but shows private tournaments instead. |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
if not request.user.is_staff: |
|
|
|
|
|
|
|
messages.error(request, 'Accès non autorisé') |
|
|
|
|
|
|
|
return redirect('index') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
now = timezone.now() |
|
|
|
|
|
|
|
thirty_days_ago = now - timedelta(days=30) |
|
|
|
|
|
|
|
thirty_days_future = now + timedelta(days=30) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Custom query for private tournaments |
|
|
|
|
|
|
|
queries = [ |
|
|
|
|
|
|
|
Q(is_private=True, is_deleted=False, event__club__isnull=False) |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Filter by date range for future tournaments |
|
|
|
|
|
|
|
future_query = queries.copy() |
|
|
|
|
|
|
|
future_query.append(Q(start_date__gt=now, start_date__lte=thirty_days_future)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Filter for live tournaments |
|
|
|
|
|
|
|
live_query = queries.copy() |
|
|
|
|
|
|
|
live_query.append(Q(start_date__lte=now, end_date__isnull=True) | Q(start_date__lte=now, end_date__gt=now)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Filter for ended tournaments |
|
|
|
|
|
|
|
ended_query = queries.copy() |
|
|
|
|
|
|
|
ended_query.append(Q(end_date__lte=now, end_date__gte=thirty_days_ago)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Get the tournaments from the database |
|
|
|
|
|
|
|
future_tournaments = Tournament.objects.filter(*future_query).prefetch_related( |
|
|
|
|
|
|
|
'group_stages', 'rounds', 'team_registrations').order_by('start_date') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
live_tournaments = Tournament.objects.filter(*live_query).prefetch_related( |
|
|
|
|
|
|
|
'group_stages', 'rounds', 'team_registrations').order_by('start_date') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ended_tournaments = Tournament.objects.filter(*ended_query).prefetch_related( |
|
|
|
|
|
|
|
'group_stages', 'rounds', 'team_registrations').order_by('-end_date') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Filter tournaments that should be displayed |
|
|
|
|
|
|
|
future = [t for t in future_tournaments if t.display_tournament()] |
|
|
|
|
|
|
|
live = [t for t in live_tournaments if t.display_tournament()] |
|
|
|
|
|
|
|
ended = [t for t in ended_tournaments if t.display_tournament()] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return render( |
|
|
|
|
|
|
|
request, |
|
|
|
|
|
|
|
"tournaments/tournaments.html", |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
'future': future[:10], |
|
|
|
|
|
|
|
'live': live[:10], |
|
|
|
|
|
|
|
'ended': ended[:10], |
|
|
|
|
|
|
|
'is_private_section': True, # Flag to indicate we're in the private tournaments section |
|
|
|
|
|
|
|
'section_title': 'Tournois privés', # Title for the private tournaments page |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
class UserListExportView(LoginRequiredMixin, View): |
|
|
|
class UserListExportView(LoginRequiredMixin, View): |
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
users = CustomUser.objects.order_by('date_joined') |
|
|
|
users = CustomUser.objects.order_by('date_joined') |
|
|
|
|