2023-03-22 11:26:27 +00:00
|
|
|
# Copyright (C) 2023 by Animath
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2023-04-04 17:52:44 +00:00
|
|
|
from django.conf import settings
|
2023-03-22 14:24:15 +00:00
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
2023-03-22 17:44:49 +00:00
|
|
|
from django.views.generic import TemplateView, DetailView
|
2023-03-22 11:26:27 +00:00
|
|
|
|
2023-03-22 14:24:15 +00:00
|
|
|
from participation.models import Tournament
|
2023-03-22 11:26:27 +00:00
|
|
|
|
2023-03-22 14:24:15 +00:00
|
|
|
|
|
|
|
class DisplayView(LoginRequiredMixin, TemplateView):
|
2023-04-04 17:52:44 +00:00
|
|
|
"""
|
|
|
|
This view is the main interface of the drawing system, which is working
|
|
|
|
with Javascript and websockets.
|
|
|
|
"""
|
2023-03-22 11:26:27 +00:00
|
|
|
template_name = 'draw/index.html'
|
2023-03-22 14:24:15 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
|
|
|
|
reg = self.request.user.registration
|
|
|
|
if reg.is_admin:
|
2023-04-04 17:52:44 +00:00
|
|
|
# Administrators can manage all tournaments
|
2023-03-22 17:44:49 +00:00
|
|
|
tournaments = Tournament.objects.order_by('id').all()
|
2023-03-22 14:24:15 +00:00
|
|
|
elif reg.is_volunteer:
|
2023-04-04 17:52:44 +00:00
|
|
|
# A volunteer can see their tournaments
|
2023-03-26 09:08:03 +00:00
|
|
|
tournaments = reg.interesting_tournaments
|
2023-03-22 14:24:15 +00:00
|
|
|
else:
|
2023-04-04 17:52:44 +00:00
|
|
|
# A participant can see its own tournament, or the final if necessary
|
2023-03-22 14:24:15 +00:00
|
|
|
tournaments = [reg.team.participation.tournament]
|
2023-04-04 17:52:44 +00:00
|
|
|
if reg.team.participation.final:
|
|
|
|
tournaments.append(Tournament.final_tournament())
|
|
|
|
|
2023-03-22 17:44:49 +00:00
|
|
|
context['tournaments'] = tournaments
|
2023-04-04 17:52:44 +00:00
|
|
|
# This will be useful for JavaScript data
|
2023-03-22 17:44:49 +00:00
|
|
|
context['tournaments_simplified'] = [{'id': t.id, 'name': t.name} for t in tournaments]
|
2023-04-04 17:52:44 +00:00
|
|
|
context['problems'] = settings.PROBLEMS
|
2023-03-22 14:24:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
return context
|