1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2024-12-25 06:22:22 +00:00

Display teams

This commit is contained in:
Yohann D'ANELLO 2020-04-29 16:59:59 +02:00
parent e865910ee3
commit f57d7554e7
7 changed files with 139 additions and 7 deletions

View File

@ -166,6 +166,25 @@ class Command(BaseCommand):
TFJMUser.objects.create(**obj_dict) TFJMUser.objects.create(**obj_dict)
self.stdout.write(self.style.SUCCESS("Users imported")) 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 @transaction.atomic
def import_documents(self): def import_documents(self):
self.stdout.write("Importing documents...") self.stdout.write("Importing documents...")

9
apps/member/tables.py Normal file
View File

@ -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",)

View File

@ -39,7 +39,7 @@ class Tournament(models.Model):
) )
date_end = models.DateField( date_end = models.DateField(
verbose_name=_("date start"), verbose_name=_("date end"),
) )
date_inscription = models.DateTimeField( date_inscription = models.DateTimeField(
@ -89,6 +89,7 @@ class Team(models.Model):
tournament = models.ForeignKey( tournament = models.ForeignKey(
Tournament, Tournament,
on_delete=models.PROTECT, on_delete=models.PROTECT,
related_name="teams",
verbose_name=_("tournament"), verbose_name=_("tournament"),
) )
@ -102,7 +103,7 @@ class Team(models.Model):
choices=[ choices=[
("0invalid", _("Registration not validated")), ("0invalid", _("Registration not validated")),
("1waiting", _("Waiting for validation")), ("1waiting", _("Waiting for validation")),
("1valid", _("Registration validated")), ("2valid", _("Registration validated")),
], ],
verbose_name=_("validation status"), verbose_name=_("validation status"),
) )

View File

@ -1,10 +1,16 @@
import django_tables2 as tables import django_tables2 as tables
from django.utils.translation import gettext as _ 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): class TournamentTable(tables.Table):
name = tables.LinkColumn(
"tournament:detail",
args=[A("pk")],
)
date_start = tables.Column( date_start = tables.Column(
verbose_name=_("dates").capitalize(), verbose_name=_("dates").capitalize(),
) )
@ -18,3 +24,12 @@ class TournamentTable(tables.Table):
attrs = { attrs = {
'class': 'table table-condensed table-striped table-hover' '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'
}

View File

@ -1,9 +1,10 @@
from django.urls import path from django.urls import path
from .views import TournamentListView from .views import TournamentListView, TournamentDetailView
app_name = "tournament" app_name = "tournament"
urlpatterns = [ urlpatterns = [
path('list/', TournamentListView.as_view(), name="list"), path('list/', TournamentListView.as_view(), name="list"),
path('<int:pk>/', TournamentDetailView.as_view(), name="detail"),
] ]

View File

@ -1,10 +1,11 @@
from django.db.models import Q from django.db.models import Q
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views.generic import DetailView
from django_tables2.views import SingleTableView from django_tables2.views import SingleTableView
from member.models import TFJMUser from member.models import TFJMUser
from .models import Tournament from .models import Tournament
from .tables import TournamentTable from .tables import TournamentTable, TeamTable
class TournamentListView(SingleTableView): class TournamentListView(SingleTableView):
@ -15,10 +16,36 @@ class TournamentListView(SingleTableView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
team_users = TFJMUser.objects.filter(Q(team__isnull=False) | Q(role="admin") | Q(role="organizer")) 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")) .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["team_users_emails"] = [user.email for user in team_users]
context["valid_team_users_emails"] = [user.email for user in valid_team_users] context["valid_team_users_emails"] = [user.email for user in valid_team_users]
return context 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

View File

@ -0,0 +1,60 @@
{% extends "base.html" %}
{% load getconfig i18n django_tables2 %}
{% block content %}
<div class="card bg-light shadow">
<div class="card-header text-center">
<h4>{{ title }}</h4>
</div>
<div class="card-body">
<dl class="row">
<dt class="col-xl-6 text-right">{% trans 'organizers'|capfirst %}</dt>
<dd class="col-xl-6">{{ tournament.organizers.all|join:", " }}</dd>
<dt class="col-xl-6 text-right">{% trans 'size'|capfirst %}</dt>
<dd class="col-xl-6">{{ tournament.size }}</dd>
<dt class="col-xl-6 text-right">{% trans 'place'|capfirst %}</dt>
<dd class="col-xl-6">{{ tournament.place }}</dd>
<dt class="col-xl-6 text-right">{% trans 'price'|capfirst %}</dt>
<dd class="col-xl-6">{% if tournament.price %}{{ tournament.price }} €{% else %}{% trans "Free" %}{% endif %}</dd>
<dt class="col-xl-6 text-right">{% trans 'dates'|capfirst %}</dt>
<dd class="col-xl-6">{% trans "From" %} {{ tournament.date_start }} {% trans "to" %} {{ tournament.date_end }}</dd>
<dt class="col-xl-6 text-right">{% trans 'date of registration closing'|capfirst %}</dt>
<dd class="col-xl-6">{{ tournament.date_inscription }}</dd>
<dt class="col-xl-6 text-right">{% trans 'date of maximal solution submission'|capfirst %}</dt>
<dd class="col-xl-6">{{ tournament.date_solutions }}</dd>
<dt class="col-xl-6 text-right">{% trans 'date of maximal syntheses submission'|capfirst %}</dt>
<dd class="col-xl-6">{{ tournament.date_syntheses }}</dd>
<dt class="col-xl-6 text-right">{% trans 'description'|capfirst %}</dt>
<dd class="col-xl-6">{{ tournament.description }}</dd>
</dl>
{% if user.is_authenticated and user.admin %}
<div class="alert alert-info">
<a href="mailto:contact@tfm.org?subject=TFJM²%20{{ "TFJM_YEAR"|get_env }}&bcc={{ team_users_emails|join:"," }}">{% trans "Send a mail to all people in this tournament" %}</a><br>
<a href="mailto:contact@tfm.org?subject=TFJM²%20{{ "TFJM_YEAR"|get_env }}&bcc={{ valid_team_users_emails|join:"," }}">{% trans "Send a mail to all people in this tournament that are in a valid team" %}</a>
</div>
{% endif %}
</div>
{% if user.admin or user in tournament.organizers.all %}
<div class="card-footer text-center">
<button class="btn btn-secondary">{% trans "Edit tournament" %}</button>
</div>
{% endif %}
</div>
<hr>
<div id="teams_table">
{% render_table teams %}
</div>
{% endblock %}