add a section for private tournaments for staff members

sync3
Razmig Sarkissian 5 months ago
parent ae1a24a083
commit ace8801ecc
  1. 2
      tournaments/templates/tournaments/navigation_base.html
  2. 1
      tournaments/urls.py
  3. 57
      tournaments/views.py

@ -1,4 +1,3 @@
<nav class="margin10">
<a href="{% url 'index' %}" class="orange">Accueil</a>
<a href="{% url 'clubs' %}" class="orange">Clubs</a>
@ -11,6 +10,7 @@
{% endif %}
<a href="{% url 'shop:product_list' %}">La boutique</a>
{% if user.is_authenticated and user.is_staff %}
<a href="{% url 'private-tournaments' %}" class="orange">Tournois privés</a>
<a href="{% url 'admin:tournaments_tournament_dashboard' %}" class="download-button">Tableau de bord</a>
{% else %}
<a href="{% url 'download' %}" class="download-button">Ajouter vos tournois</a>

@ -81,5 +81,6 @@ urlpatterns = [
path('stripe-onboarding-complete/', views.stripe_onboarding_complete, name='stripe-onboarding-complete'),
path('stripe-refresh-account-link/', views.stripe_refresh_account_link, name='stripe-refresh-account-link'),
path('tournaments/<str:tournament_id>/toggle-private/', views.toggle_tournament_private, name='toggle_tournament_private'),
path("private-tournaments/", views.private_tournaments, name="private-tournaments"),
]

@ -1702,6 +1702,63 @@ def toggle_tournament_private(request, tournament_id):
messages.error(request, f'Erreur: {str(e)}')
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):
def get(self, request, *args, **kwargs):
users = CustomUser.objects.order_by('date_joined')

Loading…
Cancel
Save