diff --git a/apps/participation/models.py b/apps/participation/models.py index 380936d..647530d 100644 --- a/apps/participation/models.py +++ b/apps/participation/models.py @@ -129,7 +129,7 @@ class Tournament(models.Model): ) date_end = models.DateField( - verbose_name=_("start"), + verbose_name=_("end"), default=timezone.now, ) diff --git a/apps/participation/tables.py b/apps/participation/tables.py index 075b317..6e81c34 100644 --- a/apps/participation/tables.py +++ b/apps/participation/tables.py @@ -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' diff --git a/apps/participation/templates/participation/tournament_list.html b/apps/participation/templates/participation/tournament_list.html new file mode 100644 index 0000000..70a79d7 --- /dev/null +++ b/apps/participation/templates/participation/tournament_list.html @@ -0,0 +1,16 @@ +{% extends "base.html" %} + +{% load django_tables2 i18n %} + +{% block contenttitle %} +

{% trans "All tournaments" %}

+{% endblock %} + +{% block content %} +
+ {% render_table table %} + {% if user.registration.is_admin %} + {% trans "Add tournament" %} + {% endif %} +
+{% endblock %} diff --git a/apps/participation/urls.py b/apps/participation/urls.py index 4bb1766..e02cb6e 100644 --- a/apps/participation/urls.py +++ b/apps/participation/urls.py @@ -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//", 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") ] diff --git a/apps/participation/views.py b/apps/participation/views.py index 7cceda1..cc567e1 100644 --- a/apps/participation/views.py +++ b/apps/participation/views.py @@ -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 diff --git a/tfjm/templates/base.html b/tfjm/templates/base.html index 3407f74..b233191 100644 --- a/tfjm/templates/base.html +++ b/tfjm/templates/base.html @@ -63,6 +63,11 @@ + {% if user.is_authenticated and user.registration.is_admin %}