from django.contrib.auth.mixins import LoginRequiredMixin from django.db.models import Q from django.utils.translation import gettext_lazy as _ from django.views.generic import DetailView from django_tables2.views import SingleTableView from member.models import TFJMUser from .models import Tournament, Team from .tables import TournamentTable, TeamTable 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) 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")) 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 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 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