plateforme-tfjm2/apps/tournament/views.py

64 lines
2.1 KiB
Python
Raw Normal View History

2020-04-29 15:58:11 +00:00
from django.contrib.auth.mixins import LoginRequiredMixin
2020-04-29 14:26:52 +00:00
from django.db.models import Q
from django.utils.translation import gettext_lazy as _
2020-04-29 14:59:59 +00:00
from django.views.generic import DetailView
2020-04-29 14:26:52 +00:00
from django_tables2.views import SingleTableView
2020-04-29 02:06:02 +00:00
2020-04-29 14:26:52 +00:00
from member.models import TFJMUser
2020-04-29 15:58:11 +00:00
from .models import Tournament, Team
2020-04-29 14:59:59 +00:00
from .tables import TournamentTable, TeamTable
2020-04-29 14:26:52 +00:00
class TournamentListView(SingleTableView):
model = Tournament
table_class = TournamentTable
extra_context = dict(title=_("Tournaments list"),)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
2020-04-29 14:59:59 +00:00
team_users = TFJMUser.objects.filter(Q(team__isnull=False) | Q(role="admin") | Q(role="organizer"))\
.order_by('-role')
valid_team_users = team_users.filter(
Q(team__validation_status="2valid") | Q(role="admin") | Q(role="organizer"))
2020-04-29 14:26:52 +00:00
context["team_users_emails"] = [user.email for user in team_users]
context["valid_team_users_emails"] = [user.email for user in valid_team_users]
return context
2020-04-29 14:59:59 +00:00
class TournamentDetailView(DetailView):
model = Tournament
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["title"] = _("Tournament of {name}").format(name=self.object.name)
team_users = TFJMUser.objects.filter(
Q(team__tournament=self.object)
| Q(organized_tournaments=self.object)).order_by('role')
valid_team_users = team_users.filter(
Q(team__validation_status="2valid")
| Q(role="admin")
| Q(organized_tournaments=self.object))
context["team_users_emails"] = [user.email for user in team_users]
context["valid_team_users_emails"] = [user.email for user in valid_team_users]
context["teams"] = TeamTable(self.object.teams.all())
return context
2020-04-29 15:58:11 +00:00
class TeamDetailView(LoginRequiredMixin, DetailView):
model = Team
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["title"] = _("Information about team")
return context