From 3fdda5a0305b7224b81b20294c552c5acacf84b5 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Wed, 29 Apr 2020 17:58:11 +0200 Subject: [PATCH] Display teams --- apps/tournament/models.py | 10 ++--- apps/tournament/tables.py | 5 +++ apps/tournament/urls.py | 3 +- apps/tournament/views.py | 14 +++++- templates/tournament/team_detail.html | 49 +++++++++++++++++++++ templates/tournament/tournament_detail.html | 1 + 6 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 templates/tournament/team_detail.html diff --git a/apps/tournament/models.py b/apps/tournament/models.py index 6c94ac0..23163b9 100644 --- a/apps/tournament/models.py +++ b/apps/tournament/models.py @@ -126,23 +126,23 @@ class Team(models.Model): @property def valid(self): - return self.validation_status == "valid" + return self.validation_status == "2valid" @property def waiting(self): - return self.validation_status == "waiting" + return self.validation_status == "1waiting" @property def invalid(self): - return self.validation_status == "invalid" + return self.validation_status == "0invalid" @property def encadrants(self): - return self.users.filter(role="encadrant") + return self.users.all().filter(role="2coach") @property def participants(self): - return self.users.filter(role="participant") + return self.users.all().filter(role="3participant") class Meta: verbose_name = _("team") diff --git a/apps/tournament/tables.py b/apps/tournament/tables.py index 67d01d2..8f100a8 100644 --- a/apps/tournament/tables.py +++ b/apps/tournament/tables.py @@ -27,6 +27,11 @@ class TournamentTable(tables.Table): class TeamTable(tables.Table): + name = tables.LinkColumn( + "tournament:team_detail", + args=[A("pk")], + ) + class Meta: model = Team fields = ("name", "trigram", "validation_status", ) diff --git a/apps/tournament/urls.py b/apps/tournament/urls.py index 4bd0ed5..4086472 100644 --- a/apps/tournament/urls.py +++ b/apps/tournament/urls.py @@ -1,10 +1,11 @@ from django.urls import path -from .views import TournamentListView, TournamentDetailView +from .views import TournamentListView, TournamentDetailView, TeamDetailView app_name = "tournament" urlpatterns = [ path('list/', TournamentListView.as_view(), name="list"), path('/', TournamentDetailView.as_view(), name="detail"), + path('team//', TeamDetailView.as_view(), name="team_detail"), ] diff --git a/apps/tournament/views.py b/apps/tournament/views.py index 3f5f4a0..124017e 100644 --- a/apps/tournament/views.py +++ b/apps/tournament/views.py @@ -1,10 +1,11 @@ +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 +from .models import Tournament, Team from .tables import TournamentTable, TeamTable @@ -49,3 +50,14 @@ class TournamentDetailView(DetailView): 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 diff --git a/templates/tournament/team_detail.html b/templates/tournament/team_detail.html new file mode 100644 index 0000000..2fd0bb2 --- /dev/null +++ b/templates/tournament/team_detail.html @@ -0,0 +1,49 @@ +{% extends "base.html" %} + +{% load getconfig i18n django_tables2 static %} + +{% block content %} +
+
+

{% trans "Team" %} {{ team.name }}

+
+
+
+
{% trans 'name'|capfirst %}
+
{{ team.name }}
+ +
{% trans 'trigram'|capfirst %}
+
{{ team.trigram }}
+ +
{% trans 'tournament'|capfirst %}
+
{{ team.tournament }}
+ +
{% trans 'coachs'|capfirst %}
+
{{ team.encadrants.all|join:", " }}
+ +
{% trans 'participants'|capfirst %}
+
{{ team.participants.all|join:", " }}
+
+
+ + {% if user.admin or user in team.tournament.organizers.all %} + + {% endif %} +
+ +
+ +

{% trans "Documents" %}

+ + {% if team.motivation_letters %} +
+ {% blocktrans with version=team.motivation_letters.count %}Motivation letter (version {{ version }}):{% endblocktrans %} + {% trans "Download" %} +
+ {% endif %} +{% endblock %} diff --git a/templates/tournament/tournament_detail.html b/templates/tournament/tournament_detail.html index a1cf89d..5eb0062 100644 --- a/templates/tournament/tournament_detail.html +++ b/templates/tournament/tournament_detail.html @@ -54,6 +54,7 @@
+

{% trans "Teams" %}

{% render_table teams %}