Register pools
This commit is contained in:
parent
4faec03efb
commit
4d83664c0d
|
@ -9,7 +9,7 @@ from django.core.exceptions import ValidationError
|
|||
from django.utils import formats
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from .models import Participation, Team, Tournament, Solution
|
||||
from .models import Participation, Team, Tournament, Solution, Pool
|
||||
|
||||
|
||||
class TeamForm(forms.ModelForm):
|
||||
|
@ -123,3 +123,9 @@ class SolutionForm(forms.ModelForm):
|
|||
class Meta:
|
||||
model = Solution
|
||||
fields = ('problem', 'file',)
|
||||
|
||||
|
||||
class PoolForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Pool
|
||||
fields = ('tournament', 'round', 'juries',)
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.0.11 on 2021-01-13 16:00
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('participation', '0007_auto_20210112_1801'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='pool',
|
||||
name='round',
|
||||
field=models.PositiveSmallIntegerField(choices=[(1, 'Round 1'), (2, 'Round 2')], verbose_name='round'),
|
||||
),
|
||||
]
|
|
@ -288,6 +288,10 @@ class Pool(models.Model):
|
|||
|
||||
round = models.PositiveSmallIntegerField(
|
||||
verbose_name=_("round"),
|
||||
choices=[
|
||||
(1, format_lazy(_("Round {round}"), round=1)),
|
||||
(2, format_lazy(_("Round {round}"), round=2)),
|
||||
]
|
||||
)
|
||||
|
||||
participations = models.ManyToManyField(
|
||||
|
@ -306,6 +310,9 @@ class Pool(models.Model):
|
|||
def solutions(self):
|
||||
return Solution.objects.filter(participation__in=self.participations, final_solution=self.tournament.final)
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse_lazy("participation:pool_detail", args=(self.pk,))
|
||||
|
||||
def __str__(self):
|
||||
return _("Pool {round} for tournament {tournament} with teams {teams}")\
|
||||
.format(round=self.round,
|
||||
|
|
|
@ -81,12 +81,13 @@ class PoolTable(tables.Table):
|
|||
teams = tables.LinkColumn(
|
||||
'participation:pool_detail',
|
||||
args=[tables.A('id')],
|
||||
verbose_name=_("teams"),
|
||||
accessor=None,
|
||||
verbose_name=_("teams").capitalize,
|
||||
empty_values=(),
|
||||
)
|
||||
|
||||
def render_teams(self, record):
|
||||
return ", ".join(participation.team.trigram for participation in record.participations.all())
|
||||
return ", ".join(participation.team.trigram for participation in record.participations.all()) \
|
||||
or _("No defined team")
|
||||
|
||||
class Meta:
|
||||
attrs = {
|
||||
|
|
|
@ -50,7 +50,6 @@
|
|||
<script>
|
||||
$(document).ready(function () {
|
||||
$('button[data-target="#uploadSolutionModal"]').click(function() {
|
||||
console.log(42)
|
||||
let modalBody = $("#uploadSolutionModal div.modal-body");
|
||||
if (!modalBody.html().trim())
|
||||
modalBody.load("{% url "participation:upload_solution" pk=participation.pk %} #form-content")
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{% extends "base.html" %}
|
|
@ -0,0 +1,13 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% load crispy_forms_filters i18n %}
|
||||
|
||||
{% block content %}
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
<div id="form-content">
|
||||
{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
</div>
|
||||
<button class="btn btn-primary" type="submit">{% trans "Update pool" %}</button>
|
||||
</form>
|
||||
{% endblock content %}
|
|
@ -69,6 +69,23 @@
|
|||
</div>
|
||||
|
||||
{% if user.registration.is_admin %}
|
||||
<a class="btn btn-block btn-success" href="#">{% trans "Add new pool" %}</a>
|
||||
<button class="btn btn-block btn-success" data-toggle="modal" data-target="#addPoolModal">{% trans "Add new pool" %}</button>
|
||||
{% endif %}
|
||||
|
||||
{% trans "Add pool" as modal_title %}
|
||||
{% trans "Add" as modal_button %}
|
||||
{% url "participation:pool_create" as modal_action %}
|
||||
{% include "base_modal.html" with modal_id="addPool" %}
|
||||
{% endblock %}
|
||||
|
||||
{% block extrajavascript %}
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$('button[data-target="#addPoolModal"]').click(function() {
|
||||
let modalBody = $("#addPoolModal div.modal-body");
|
||||
if (!modalBody.html().trim())
|
||||
modalBody.load("{% url "participation:pool_create" %} #form-content")
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
|
@ -5,9 +5,9 @@ from django.urls import path
|
|||
from django.views.generic import TemplateView
|
||||
|
||||
from .views import CreateTeamView, JoinTeamView, \
|
||||
MyParticipationDetailView, MyTeamDetailView, ParticipationDetailView, TeamAuthorizationsView, \
|
||||
TeamDetailView, TeamLeaveView, TeamListView, TeamUpdateView, TournamentCreateView, TournamentDetailView, \
|
||||
TournamentListView, TournamentUpdateView, SolutionUploadView
|
||||
MyParticipationDetailView, MyTeamDetailView, ParticipationDetailView, PoolCreateView, PoolDetailView, \
|
||||
PoolUpdateView, TeamAuthorizationsView, TeamDetailView, TeamLeaveView, TeamListView, TeamUpdateView, \
|
||||
TournamentCreateView, TournamentDetailView, TournamentListView, TournamentUpdateView, SolutionUploadView
|
||||
|
||||
|
||||
app_name = "participation"
|
||||
|
@ -28,5 +28,8 @@ urlpatterns = [
|
|||
path("tournament/create/", TournamentCreateView.as_view(), name="tournament_create"),
|
||||
path("tournament/<int:pk>/", TournamentDetailView.as_view(), name="tournament_detail"),
|
||||
path("tournament/<int:pk>/update/", TournamentUpdateView.as_view(), name="tournament_update"),
|
||||
path("pools/create/", PoolCreateView.as_view(), name="pool_create"),
|
||||
path("pools/<int:pk>/", PoolDetailView.as_view(), name="pool_detail"),
|
||||
path("pools/<int:pk>/update/", PoolUpdateView.as_view(), name="pool_update"),
|
||||
path("chat/", TemplateView.as_view(template_name="participation/chat.html"), name="chat")
|
||||
]
|
||||
|
|
|
@ -23,9 +23,9 @@ from tfjm.lists import get_sympa_client
|
|||
from tfjm.matrix import Matrix
|
||||
from tfjm.views import AdminMixin
|
||||
|
||||
from .forms import JoinTeamForm, ParticipationForm, RequestValidationForm, SolutionForm, TeamForm, TournamentForm, \
|
||||
ValidateParticipationForm
|
||||
from .models import Participation, Team, Tournament, Solution
|
||||
from .forms import JoinTeamForm, ParticipationForm, PoolForm, RequestValidationForm, SolutionForm, TeamForm,\
|
||||
TournamentForm, ValidateParticipationForm
|
||||
from .models import Participation, Team, Tournament, Solution, Pool
|
||||
from .tables import TeamTable, TournamentTable, ParticipationTable, PoolTable
|
||||
|
||||
|
||||
|
@ -468,3 +468,17 @@ class SolutionUploadView(LoginRequiredMixin, FormView):
|
|||
|
||||
def get_success_url(self):
|
||||
return reverse_lazy("participation:participation_detail", args=(self.participation.pk,))
|
||||
|
||||
|
||||
class PoolCreateView(AdminMixin, CreateView):
|
||||
model = Pool
|
||||
form_class = PoolForm
|
||||
|
||||
|
||||
class PoolDetailView(AdminMixin, DetailView):
|
||||
model = Pool
|
||||
|
||||
|
||||
class PoolUpdateView(AdminMixin, UpdateView):
|
||||
model = Pool
|
||||
form_class = PoolForm
|
||||
|
|
Loading…
Reference in New Issue