Update a team in a popup <3

This commit is contained in:
Yohann D'ANELLO 2020-09-24 11:15:54 +02:00
parent 8c70ef3835
commit 4975044046
11 changed files with 146 additions and 50 deletions

View File

@ -4,7 +4,7 @@ from django import forms
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _
from .models import Team
from .models import Team, Participation
class TeamForm(forms.ModelForm):
@ -36,3 +36,9 @@ class JoinTeamForm(forms.ModelForm):
class Meta:
model = Team
fields = ('access_code',)
class ParticipationForm(forms.ModelForm):
class Meta:
model = Participation
fields = ('problem',)

View File

@ -2,6 +2,8 @@ from django.core.validators import RegexValidator
from django.db import models
from django.db.models import Index
from django.utils.crypto import get_random_string
from django.utils.functional import lazy
from django.utils.text import format_lazy
from django.utils.translation import gettext_lazy as _
@ -56,7 +58,7 @@ class Participation(models.Model):
)
problem = models.IntegerField(
choices=[(i, _("Problem #{problem:d}").format(problem=i)) for i in range(1, 5)],
choices=[(i, format_lazy(_("Problem #{problem:d}"), problem=i)) for i in range(1, 5)],
null=True,
default=None,
verbose_name=_("problem number"),

View File

@ -1,4 +1,4 @@
{% load crispy_forms_filters i18n %}
{% load i18n %}
<div id="createTeamModal" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">

View File

@ -1,4 +1,4 @@
{% load crispy_forms_filters i18n %}
{% load i18n %}
<div id="joinTeamModal" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">

View File

@ -27,8 +27,25 @@
<dd class="col-sm-6">{{ team.students.all|join:", "|default:any }}</dd>
<dt class="col-sm-6 text-right">{% trans "Chosen problem:" %}</dt>
<dd class="col-sm-6">{{ team.participation.problem|default:any }}</dd>
<dd class="col-sm-6">{{ team.participation.get_problem_display|default:any }}</dd>
</dl>
</div>
<div class="card-footer text-center">
<button class="btn btn-primary" data-toggle="modal" data-target="#updateTeamModal">{% trans "Update" %}</button>
</div>
</div>
{% include "participation/update_team_modal.html" %}
{% endblock %}
{% block extrajavascript %}
<script>
$(document).ready(function() {
$('button[data-target="#updateTeamModal"]').click(function() {
let modalBody = $("#updateTeamModal div.modal-body");
if (!modalBody.html().trim())
modalBody.load("{% url "participation:update_team" pk=team.pk %} #form-content");
});
});
</script>
{% endblock %}

View File

@ -0,0 +1,15 @@
{% extends "base.html" %}
{% load crispy_forms_filters i18n %}
{% block content %}
<form method="post">
<div id="form-content">
{% csrf_token %}
{{ form|crispy }}
{{ participation_form|crispy }}
</div>
<button class="btn btn-success" type="submit">{% trans "Update" %}</button>
</form>
{% endblock content %}

View File

@ -0,0 +1,21 @@
{% load i18n %}
<div id="updateTeamModal" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<form method="post" action="{% url "participation:update_team" pk=team.pk %}">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">{% trans "Update team" %}</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body"></div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">{% trans "Update" %}</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">{% trans "Close" %}</button>
</div>
</div>
</form>
</div>
</div>

View File

@ -1,6 +1,6 @@
from django.urls import path
from .views import CreateTeamView, JoinTeamView, MyTeamDetailView, TeamDetailView
from .views import CreateTeamView, JoinTeamView, MyTeamDetailView, TeamDetailView, TeamUpdateView
app_name = "participation"
@ -10,4 +10,5 @@ urlpatterns = [
path("join_team/", JoinTeamView.as_view(), name="join_team"),
path("team/", MyTeamDetailView.as_view(), name="my_team_detail"),
path("team/<int:pk>/", TeamDetailView.as_view(), name="team_detail"),
path("team/<int:pk>/update/", TeamUpdateView.as_view(), name="update_team"),
]

View File

@ -3,9 +3,9 @@ from django.core.exceptions import PermissionDenied
from django.db import transaction
from django.urls import reverse_lazy
from django.utils.translation import gettext_lazy as _
from django.views.generic import CreateView, FormView, DetailView, RedirectView
from django.views.generic import CreateView, FormView, DetailView, RedirectView, UpdateView
from participation.forms import TeamForm, JoinTeamForm
from participation.forms import TeamForm, JoinTeamForm, ParticipationForm
from participation.models import Team
@ -74,3 +74,27 @@ class MyTeamDetailView(LoginRequiredMixin, RedirectView):
class TeamDetailView(LoginRequiredMixin, DetailView):
model = Team
class TeamUpdateView(LoginRequiredMixin, UpdateView):
model = Team
form_class = TeamForm
template_name = "participation/update_team.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["participation_form"] = ParticipationForm(data=self.request.POST or None,
instance=self.object.participation)
return context
@transaction.atomic
def form_valid(self, form):
participation_form = ParticipationForm(data=self.request.POST or None, instance=self.object.participation)
if not participation_form.is_valid():
return self.form_invalid(form)
participation_form.save()
return super().form_valid(form)
def get_success_url(self):
return reverse_lazy("participation:team_detail", args=(self.object.pk,))

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Corres2math\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-09-24 09:53+0200\n"
"POT-Creation-Date: 2020-09-24 11:08+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Yohann D'ANELLO <yohann.danello@animath.fr>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -32,6 +32,7 @@ msgstr "Cette tâche a échoué avec succès."
#: apps/eastereggs/templates/eastereggs/xp_modal.html:16
#: apps/participation/templates/participation/create_team_modal.html:16
#: apps/participation/templates/participation/join_team_modal.html:16
#: apps/participation/templates/participation/update_team_modal.html:16
#: apps/registration/templates/registration/login_modal.html:16
msgid "Close"
msgstr "Fermer"
@ -101,7 +102,7 @@ msgstr "changelogs"
msgid "Changelog of type \"{action}\" for model {model} at {timestamp}"
msgstr "Changelog de type \"{action}\" pour le modèle {model} le {timestamp}"
#: apps/participation/forms.py:14 apps/participation/models.py:18
#: apps/participation/forms.py:14 apps/participation/models.py:20
msgid "The trigram must be composed of three uppercase letters."
msgstr "Le trigramme doit être composé de trois lettres majuscules."
@ -109,27 +110,27 @@ msgstr "Le trigramme doit être composé de trois lettres majuscules."
msgid "No team was found with this access code."
msgstr "Aucune équipe n'a été trouvée avec ce code d'accès."
#: apps/participation/models.py:11
#: apps/participation/models.py:13
msgid "name"
msgstr "nom"
#: apps/participation/models.py:17
#: apps/participation/models.py:19
msgid "trigram"
msgstr "trigramme"
#: apps/participation/models.py:25
#: apps/participation/models.py:27
msgid "access code"
msgstr "code d'accès"
#: apps/participation/models.py:26
#: apps/participation/models.py:28
msgid "The access code let other people to join the team."
msgstr "Le code d'accès permet aux autres participants de rejoindre l'équipe."
#: apps/participation/models.py:30
#: apps/participation/models.py:32
msgid "Grant Animath to publish my video"
msgstr "Autoriser Animath à publier ma vidéo"
#: apps/participation/models.py:31
#: apps/participation/models.py:33
msgid ""
"Give the authorisation to publish the video on the main website to promote "
"the action."
@ -137,80 +138,80 @@ msgstr ""
"Donner l'autorisation de publier la vidéo sur le site principal pour "
"promouvoir les Correspondances."
#: apps/participation/models.py:41
#: apps/participation/models.py:43
#, python-brace-format
msgid "Team {name} ({trigram})"
msgstr "Équipe {name} ({trigram})"
#: apps/participation/models.py:44 apps/participation/models.py:55
#: apps/participation/models.py:46 apps/participation/models.py:57
#: apps/registration/models.py:73 apps/registration/models.py:106
msgid "team"
msgstr "équipe"
#: apps/participation/models.py:45
#: apps/participation/models.py:47
msgid "teams"
msgstr "équipes"
#: apps/participation/models.py:59
#: apps/participation/models.py:61
#, python-brace-format
msgid "Problem #{problem:d}"
msgstr "Problème n°{problem:d}"
#: apps/participation/models.py:62
#: apps/participation/models.py:64
msgid "problem number"
msgstr "numéro de problème"
#: apps/participation/models.py:71
#: apps/participation/models.py:73
msgid "solution video"
msgstr "vidéo de solution"
#: apps/participation/models.py:80
#: apps/participation/models.py:82
msgid "received participation"
msgstr "participation reçue"
#: apps/participation/models.py:89
#: apps/participation/models.py:91
msgid "synthesis video"
msgstr "vidéo de synthèse"
#: apps/participation/models.py:93
#: apps/participation/models.py:95
#, python-brace-format
msgid "Participation of the team {name} ({trigram})"
msgstr "Participation de l'équipe {name} ({trigram})"
#: apps/participation/models.py:96 apps/participation/models.py:104
#: apps/participation/models.py:98 apps/participation/models.py:106
msgid "participation"
msgstr "participation"
#: apps/participation/models.py:97
#: apps/participation/models.py:99
msgid "participations"
msgstr "participations"
#: apps/participation/models.py:108
#: apps/participation/models.py:110
msgid "link"
msgstr "lien"
#: apps/participation/models.py:109
#: apps/participation/models.py:111
msgid "The full video link."
msgstr "Le lien complet de la vidéo."
#: apps/participation/models.py:115
#: apps/participation/models.py:117
msgid "valid"
msgstr "valide"
#: apps/participation/models.py:116
#: apps/participation/models.py:118
msgid "The video got the validation of the administrators."
msgstr "La vidéo a été validée par les administrateurs."
#: apps/participation/models.py:120
#: apps/participation/models.py:122
#, python-brace-format
msgid "Video of team {name} ({trigram})"
msgstr "Vidéo de l'équipe {name} ({trigram})"
#: apps/participation/models.py:124
#: apps/participation/models.py:126
msgid "video"
msgstr "vidéo"
#: apps/participation/models.py:125
#: apps/participation/models.py:127
msgid "videos"
msgstr "vidéos"
@ -220,7 +221,7 @@ msgid "Create"
msgstr "Créer"
#: apps/participation/templates/participation/create_team_modal.html:8
#: apps/participation/views.py:15 templates/base.html:76
#: apps/participation/views.py:15 templates/base.html:70
msgid "Create team"
msgstr "Créer une équipe"
@ -230,7 +231,7 @@ msgid "Join"
msgstr "Rejoindre"
#: apps/participation/templates/participation/join_team_modal.html:8
#: apps/participation/views.py:41 templates/base.html:81
#: apps/participation/views.py:41 templates/base.html:75
msgid "Join team"
msgstr "Rejoindre une équipe"
@ -262,6 +263,16 @@ msgstr "Participants :"
msgid "Chosen problem:"
msgstr "Problème choisi :"
#: apps/participation/templates/participation/team_detail.html:34
#: apps/participation/templates/participation/update_team.html:12
#: apps/participation/templates/participation/update_team_modal.html:15
msgid "Update"
msgstr "Modifier"
#: apps/participation/templates/participation/update_team_modal.html:8
msgid "Update team"
msgstr "Modifier l'équipe"
#: apps/participation/views.py:23 apps/participation/views.py:49
msgid "You don't participate, so you can't create a team."
msgstr "Vous ne participez pas, vous ne pouvez pas créer d'équipe."
@ -410,7 +421,7 @@ msgstr "Se reconnecter"
#: apps/registration/templates/registration/login_modal.html:8
#: apps/registration/templates/registration/login_modal.html:15
#: apps/registration/templates/registration/password_reset_complete.html:10
#: templates/base.html:114 templates/registration/login.html:7
#: templates/base.html:108 templates/registration/login.html:7
#: templates/registration/login.html:8 templates/registration/login.html:25
msgid "Log in"
msgstr "Connexion"
@ -604,42 +615,38 @@ msgstr ""
"avec les détails de l'erreur. Vous pouvez désormais retourner voir des "
"vidéos."
#: templates/base.html:70
#: templates/base.html:64
msgid "Home"
msgstr "Accueil"
#: templates/base.html:87
#: templates/base.html:81
msgid "My team"
msgstr "Mon équipe"
#: templates/base.html:94
#: templates/base.html:88
msgid "Make a gift"
msgstr "Faire un don"
#: templates/base.html:98
#: templates/base.html:92
msgid "Administration"
msgstr "Administration"
#: templates/base.html:105
#: templates/base.html:99
msgid "Return to admin view"
msgstr "Retourner à l'interface administrateur"
#: templates/base.html:110
#: templates/base.html:104
msgid "Register"
msgstr "S'inscrire"
#: templates/base.html:119
#: templates/base.html:120
msgid "Log out"
msgstr "Déconnexion"
#: templates/base.html:145
#: templates/base.html:147
msgid "Contact us"
msgstr "Nous contacter"
#: templates/base.html:168
msgid "Back to top"
msgstr "Retour en haut"
#: templates/registration/login.html:13
#, python-format
msgid ""
@ -652,3 +659,6 @@ msgstr ""
#: templates/registration/login.html:23
msgid "Forgotten your password or username?"
msgstr "Mot de passe oublié ?"
#~ msgid "Back to top"
#~ msgstr "Retour en haut"