From f57d7554e747483b9e0b332eed1396d485939c21 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Wed, 29 Apr 2020 16:59:59 +0200 Subject: [PATCH] Display teams --- .../management/commands/import_olddb.py | 19 ++++++ apps/member/tables.py | 9 +++ apps/tournament/models.py | 5 +- apps/tournament/tables.py | 17 +++++- apps/tournament/urls.py | 3 +- apps/tournament/views.py | 33 +++++++++- templates/tournament/tournament_detail.html | 60 +++++++++++++++++++ 7 files changed, 139 insertions(+), 7 deletions(-) create mode 100644 apps/member/tables.py create mode 100644 templates/tournament/tournament_detail.html diff --git a/apps/member/management/commands/import_olddb.py b/apps/member/management/commands/import_olddb.py index d0b1318..7df074a 100644 --- a/apps/member/management/commands/import_olddb.py +++ b/apps/member/management/commands/import_olddb.py @@ -166,6 +166,25 @@ class Command(BaseCommand): TFJMUser.objects.create(**obj_dict) self.stdout.write(self.style.SUCCESS("Users imported")) + self.stdout.write("Importing organizers...") + with open("import_olddb/organizers.csv") as f: + first_line = True + for line in f: + if first_line: + first_line = False + continue + + line = line[:-1].replace("\"", "") + args = line.split(";") + args = [arg if arg and arg != "NULL" else None for arg in args] + + with transaction.atomic(): + tournament = Tournament.objects.get(pk=args[2]) + organizer = TFJMUser.objects.get(pk=args[1]) + tournament.organizers.add(organizer) + tournament.save() + self.stdout.write(self.style.SUCCESS("Organizers imported")) + @transaction.atomic def import_documents(self): self.stdout.write("Importing documents...") diff --git a/apps/member/tables.py b/apps/member/tables.py new file mode 100644 index 0000000..451756d --- /dev/null +++ b/apps/member/tables.py @@ -0,0 +1,9 @@ +import django_tables2 as tables + +from member.models import TFJMUser + + +class UserTable(tables.Table): + class Meta: + model = TFJMUser + fields = ("last_name", "first_name", "role",) diff --git a/apps/tournament/models.py b/apps/tournament/models.py index 702c7da..6c94ac0 100644 --- a/apps/tournament/models.py +++ b/apps/tournament/models.py @@ -39,7 +39,7 @@ class Tournament(models.Model): ) date_end = models.DateField( - verbose_name=_("date start"), + verbose_name=_("date end"), ) date_inscription = models.DateTimeField( @@ -89,6 +89,7 @@ class Team(models.Model): tournament = models.ForeignKey( Tournament, on_delete=models.PROTECT, + related_name="teams", verbose_name=_("tournament"), ) @@ -102,7 +103,7 @@ class Team(models.Model): choices=[ ("0invalid", _("Registration not validated")), ("1waiting", _("Waiting for validation")), - ("1valid", _("Registration validated")), + ("2valid", _("Registration validated")), ], verbose_name=_("validation status"), ) diff --git a/apps/tournament/tables.py b/apps/tournament/tables.py index 99e2c80..67d01d2 100644 --- a/apps/tournament/tables.py +++ b/apps/tournament/tables.py @@ -1,10 +1,16 @@ import django_tables2 as tables from django.utils.translation import gettext as _ +from django_tables2 import A -from .models import Tournament +from .models import Tournament, Team class TournamentTable(tables.Table): + name = tables.LinkColumn( + "tournament:detail", + args=[A("pk")], + ) + date_start = tables.Column( verbose_name=_("dates").capitalize(), ) @@ -18,3 +24,12 @@ class TournamentTable(tables.Table): attrs = { 'class': 'table table-condensed table-striped table-hover' } + + +class TeamTable(tables.Table): + class Meta: + model = Team + fields = ("name", "trigram", "validation_status", ) + attrs = { + 'class': 'table table-condensed table-striped table-hover' + } diff --git a/apps/tournament/urls.py b/apps/tournament/urls.py index 6c2fc3f..4bd0ed5 100644 --- a/apps/tournament/urls.py +++ b/apps/tournament/urls.py @@ -1,9 +1,10 @@ from django.urls import path -from .views import TournamentListView +from .views import TournamentListView, TournamentDetailView app_name = "tournament" urlpatterns = [ path('list/', TournamentListView.as_view(), name="list"), + path('/', TournamentDetailView.as_view(), name="detail"), ] diff --git a/apps/tournament/views.py b/apps/tournament/views.py index 8ddc81c..3f5f4a0 100644 --- a/apps/tournament/views.py +++ b/apps/tournament/views.py @@ -1,10 +1,11 @@ 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 .tables import TournamentTable +from .tables import TournamentTable, TeamTable class TournamentListView(SingleTableView): @@ -15,10 +16,36 @@ class TournamentListView(SingleTableView): 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")) - valid_team_users = team_users.filter(Q(team__validation_status="valid") | Q(role="admin") | Q(role="organizer")) + 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 diff --git a/templates/tournament/tournament_detail.html b/templates/tournament/tournament_detail.html new file mode 100644 index 0000000..a1cf89d --- /dev/null +++ b/templates/tournament/tournament_detail.html @@ -0,0 +1,60 @@ +{% extends "base.html" %} + +{% load getconfig i18n django_tables2 %} + +{% block content %} +
+
+

{{ title }}

+
+
+
+
{% trans 'organizers'|capfirst %}
+
{{ tournament.organizers.all|join:", " }}
+ +
{% trans 'size'|capfirst %}
+
{{ tournament.size }}
+ +
{% trans 'place'|capfirst %}
+
{{ tournament.place }}
+ +
{% trans 'price'|capfirst %}
+
{% if tournament.price %}{{ tournament.price }} €{% else %}{% trans "Free" %}{% endif %}
+ +
{% trans 'dates'|capfirst %}
+
{% trans "From" %} {{ tournament.date_start }} {% trans "to" %} {{ tournament.date_end }}
+ +
{% trans 'date of registration closing'|capfirst %}
+
{{ tournament.date_inscription }}
+ +
{% trans 'date of maximal solution submission'|capfirst %}
+
{{ tournament.date_solutions }}
+ +
{% trans 'date of maximal syntheses submission'|capfirst %}
+
{{ tournament.date_syntheses }}
+ +
{% trans 'description'|capfirst %}
+
{{ tournament.description }}
+
+ + {% if user.is_authenticated and user.admin %} + + {% endif %} +
+ + {% if user.admin or user in tournament.organizers.all %} + + {% endif %} +
+ +
+ +
+ {% render_table teams %} +
+{% endblock %}