Display the tournament list

This commit is contained in:
Yohann D'ANELLO 2020-12-30 12:13:05 +01:00
parent e2e2c97584
commit 03144ae58e
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
6 changed files with 54 additions and 6 deletions

View File

@ -129,7 +129,7 @@ class Tournament(models.Model):
)
date_end = models.DateField(
verbose_name=_("start"),
verbose_name=_("end"),
default=timezone.now,
)

View File

@ -1,10 +1,10 @@
# Copyright (C) 2020 by Animath
# SPDX-License-Identifier: GPL-3.0-or-later
from django.utils.text import format_lazy
from django.utils.translation import gettext_lazy as _
import django_tables2 as tables
from .models import Team
from .models import Team, Tournament
# noinspection PyTypeChecker
@ -54,3 +54,16 @@ class ParticipationTable(tables.Table):
model = Team
fields = ('name', 'trigram', 'problem',)
template_name = 'django_tables2/bootstrap4.html'
class TournamentTable(tables.Table):
def render_date(self, record):
return format_lazy(_("From {start} to {end}"), start=record.start, end=record.end)
class Meta:
attrs = {
'class': 'table table condensed table-striped',
}
model = Tournament
fields = ('name', 'date',)
template_name = 'django_tables2/bootstrap4.html'

View File

@ -0,0 +1,16 @@
{% extends "base.html" %}
{% load django_tables2 i18n %}
{% block contenttitle %}
<h1>{% trans "All tournaments" %}</h1>
{% endblock %}
{% block content %}
<div id="form-content">
{% render_table table %}
{% if user.registration.is_admin %}
<a class="btn btn-block btn-success" href="#">{% trans "Add tournament" %}</a>
{% endif %}
</div>
{% endblock %}

View File

@ -6,7 +6,7 @@ from django.views.generic import TemplateView
from .views import CreateTeamView, JoinTeamView, \
MyParticipationDetailView, MyTeamDetailView, ParticipationDetailView, TeamAuthorizationsView, \
TeamDetailView, TeamLeaveView, TeamListView, TeamUpdateView
TeamDetailView, TeamLeaveView, TeamListView, TeamUpdateView, TournamentListView
app_name = "participation"
@ -22,5 +22,6 @@ urlpatterns = [
path("team/leave/", TeamLeaveView.as_view(), name="team_leave"),
path("detail/", MyParticipationDetailView.as_view(), name="my_participation_detail"),
path("detail/<int:pk>/", ParticipationDetailView.as_view(), name="participation_detail"),
path("tournament/", TournamentListView.as_view(), name="tournament_list"),
path("chat/", TemplateView.as_view(template_name="participation/chat.html"), name="chat")
]

View File

@ -24,8 +24,8 @@ from tfjm.matrix import Matrix
from tfjm.views import AdminMixin
from .forms import JoinTeamForm, ParticipationForm, RequestValidationForm, TeamForm, ValidateParticipationForm
from .models import Participation, Team
from .tables import TeamTable
from .models import Participation, Team, Tournament
from .tables import TeamTable, TournamentTable
class CreateTeamView(LoginRequiredMixin, CreateView):
@ -401,3 +401,8 @@ class ParticipationDetailView(LoginRequiredMixin, DetailView):
context["title"] = lambda: _("Participation of team {trigram}").format(trigram=self.object.team.trigram)
return context
class TournamentListView(SingleTableView):
model = Tournament
table_class = TournamentTable

View File

@ -63,6 +63,11 @@
<li class="nav-item active">
<a href="{% url "index" %}" class="nav-link"><i class="fas fa-home"></i> {% trans "Home" %}</a>
</li>
<li class="nav-item active">
<a href="#" class="nav-link" data-toggle="modal" data-target="#tournamentListModal">
<i class="fas fa-calendar-day"></i> {% trans "Tournaments" %}
</a>
</li>
{% if user.is_authenticated and user.registration.is_admin %}
<li class="nav-item active">
<a href="{% url "registration:user_list" %}" class="nav-link"><i class="fas fa-user"></i> {% trans "Users" %}</a>
@ -218,6 +223,8 @@
</div>
</footer>
{% trans "All tournaments" as modal_title %}
{% include "base_modal.html" with modal_id="tournamentList" modal_additional_class="modal-lg" %}
{% if user.is_authenticated %}
{% trans "All teams" as modal_title %}
@ -247,6 +254,12 @@
$(".invalid-feedback").addClass("d-block");
$(document).ready(function () {
$('a[data-target="#tournamentListModal"]').click(function() {
let modalBody = $("#tournamentListModal div.modal-body");
if (!modalBody.html().trim())
modalBody.load("{% url "participation:tournament_list" %} #form-content")
});
{% if user.is_authenticated and user.registration.is_admin %}
$('a[data-target="#teamsModal"]').click(function() {
let modalBody = $("#teamsModal div.modal-body");