From 495f42e594d6fe228f3167a308a9338fb8ea87be Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Wed, 20 May 2020 15:47:45 +0200 Subject: [PATCH] Better final handle --- apps/tournament/views.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/apps/tournament/views.py b/apps/tournament/views.py index 184378d..e3aaeea 100644 --- a/apps/tournament/views.py +++ b/apps/tournament/views.py @@ -105,13 +105,17 @@ class TournamentDetailView(DetailView): 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)) + if self.object.final: + team_users = TFJMUser.objects.filter(team__selected_for_final=True) + valid_team_users = team_users + else: + 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] @@ -403,7 +407,11 @@ class SolutionsOrgaListView(OrgaMixin, SingleTableView): def get_queryset(self): qs = super().get_queryset() if not self.request.user.admin: - qs = qs.filter(Q(team__tournament__organizers=self.request.user) | Q(pools__juries=self.request.user)) + if self.request.user in Tournament.get_final().organizers.all(): + qs = qs.filter(Q(team__tournament__organizers=self.request.user) | Q(pools__juries=self.request.user) + | Q(final=True)) + else: + qs = qs.filter(Q(team__tournament__organizers=self.request.user) | Q(pools__juries=self.request.user)) return qs.order_by('final', 'team__tournament__date_start', 'team__tournament__name', 'team__trigram', 'problem',).distinct() @@ -529,7 +537,11 @@ class SynthesesOrgaListView(OrgaMixin, SingleTableView): def get_queryset(self): qs = super().get_queryset() if not self.request.user.admin: - qs = qs.filter(Q(team__tournament__organizers=self.request.user) | Q(team__pools__juries=self.request.user)) + if self.request.user in Tournament.get_final().organizers.all(): + qs = qs.filter(Q(team__tournament__organizers=self.request.user) | Q(pools__juries=self.request.user) + | Q(final=True)) + else: + qs = qs.filter(Q(team__tournament__organizers=self.request.user) | Q(pools__juries=self.request.user)) return qs.order_by('final', 'team__tournament__date_start', 'team__tournament__name', 'team__trigram', 'round', 'source',).distinct()