plateforme-tfjm2/draw/views.py

33 lines
1.0 KiB
Python

# Copyright (C) 2023 by Animath
# SPDX-License-Identifier: GPL-3.0-or-later
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic import TemplateView, DetailView
from participation.models import Tournament
class DisplayView(LoginRequiredMixin, TemplateView):
template_name = 'draw/index.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
reg = self.request.user.registration
if reg.is_admin:
tournaments = Tournament.objects.order_by('id').all()
elif reg.is_volunteer:
tournaments = reg.interesting_tournaments
else:
tournaments = [reg.team.participation.tournament]
context['tournaments'] = tournaments
context['tournaments_simplified'] = [{'id': t.id, 'name': t.name} for t in tournaments]
return context
class DisplayContentView(LoginRequiredMixin, DetailView):
model = Tournament
template_name = 'draw/tournament_content.html'