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.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from .models import Team from .models import Team, Participation
class TeamForm(forms.ModelForm): class TeamForm(forms.ModelForm):
@ -36,3 +36,9 @@ class JoinTeamForm(forms.ModelForm):
class Meta: class Meta:
model = Team model = Team
fields = ('access_code',) 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 import models
from django.db.models import Index from django.db.models import Index
from django.utils.crypto import get_random_string 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 _ from django.utils.translation import gettext_lazy as _
@ -56,7 +58,7 @@ class Participation(models.Model):
) )
problem = models.IntegerField( 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, null=True,
default=None, default=None,
verbose_name=_("problem number"), 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 id="createTeamModal" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document"> <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 id="joinTeamModal" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document"> <div class="modal-dialog" role="document">

View File

@ -27,8 +27,25 @@
<dd class="col-sm-6">{{ team.students.all|join:", "|default:any }}</dd> <dd class="col-sm-6">{{ team.students.all|join:", "|default:any }}</dd>
<dt class="col-sm-6 text-right">{% trans "Chosen problem:" %}</dt> <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> </dl>
</div> </div>
<div class="card-footer text-center">
<button class="btn btn-primary" data-toggle="modal" data-target="#updateTeamModal">{% trans "Update" %}</button>
</div> </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 %} {% 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 django.urls import path
from .views import CreateTeamView, JoinTeamView, MyTeamDetailView, TeamDetailView from .views import CreateTeamView, JoinTeamView, MyTeamDetailView, TeamDetailView, TeamUpdateView
app_name = "participation" app_name = "participation"
@ -10,4 +10,5 @@ urlpatterns = [
path("join_team/", JoinTeamView.as_view(), name="join_team"), path("join_team/", JoinTeamView.as_view(), name="join_team"),
path("team/", MyTeamDetailView.as_view(), name="my_team_detail"), path("team/", MyTeamDetailView.as_view(), name="my_team_detail"),
path("team/<int:pk>/", TeamDetailView.as_view(), name="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.db import transaction
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.utils.translation import gettext_lazy as _ 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 from participation.models import Team
@ -74,3 +74,27 @@ class MyTeamDetailView(LoginRequiredMixin, RedirectView):
class TeamDetailView(LoginRequiredMixin, DetailView): class TeamDetailView(LoginRequiredMixin, DetailView):
model = Team 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 "" msgstr ""
"Project-Id-Version: Corres2math\n" "Project-Id-Version: Corres2math\n"
"Report-Msgid-Bugs-To: \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" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Yohann D'ANELLO <yohann.danello@animath.fr>\n" "Last-Translator: Yohann D'ANELLO <yohann.danello@animath.fr>\n"
"Language-Team: LANGUAGE <LL@li.org>\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/eastereggs/templates/eastereggs/xp_modal.html:16
#: apps/participation/templates/participation/create_team_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/join_team_modal.html:16
#: apps/participation/templates/participation/update_team_modal.html:16
#: apps/registration/templates/registration/login_modal.html:16 #: apps/registration/templates/registration/login_modal.html:16
msgid "Close" msgid "Close"
msgstr "Fermer" msgstr "Fermer"
@ -101,7 +102,7 @@ msgstr "changelogs"
msgid "Changelog of type \"{action}\" for model {model} at {timestamp}" msgid "Changelog of type \"{action}\" for model {model} at {timestamp}"
msgstr "Changelog de type \"{action}\" pour le modèle {model} le {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." msgid "The trigram must be composed of three uppercase letters."
msgstr "Le trigramme doit être composé de trois lettres majuscules." 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." msgid "No team was found with this access code."
msgstr "Aucune équipe n'a été trouvée avec ce code d'accès." 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" msgid "name"
msgstr "nom" msgstr "nom"
#: apps/participation/models.py:17 #: apps/participation/models.py:19
msgid "trigram" msgid "trigram"
msgstr "trigramme" msgstr "trigramme"
#: apps/participation/models.py:25 #: apps/participation/models.py:27
msgid "access code" msgid "access code"
msgstr "code d'accès" 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." 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." 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" msgid "Grant Animath to publish my video"
msgstr "Autoriser Animath à publier ma vidéo" msgstr "Autoriser Animath à publier ma vidéo"
#: apps/participation/models.py:31 #: apps/participation/models.py:33
msgid "" msgid ""
"Give the authorisation to publish the video on the main website to promote " "Give the authorisation to publish the video on the main website to promote "
"the action." "the action."
@ -137,80 +138,80 @@ msgstr ""
"Donner l'autorisation de publier la vidéo sur le site principal pour " "Donner l'autorisation de publier la vidéo sur le site principal pour "
"promouvoir les Correspondances." "promouvoir les Correspondances."
#: apps/participation/models.py:41 #: apps/participation/models.py:43
#, python-brace-format #, python-brace-format
msgid "Team {name} ({trigram})" msgid "Team {name} ({trigram})"
msgstr "Équipe {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 #: apps/registration/models.py:73 apps/registration/models.py:106
msgid "team" msgid "team"
msgstr "équipe" msgstr "équipe"
#: apps/participation/models.py:45 #: apps/participation/models.py:47
msgid "teams" msgid "teams"
msgstr "équipes" msgstr "équipes"
#: apps/participation/models.py:59 #: apps/participation/models.py:61
#, python-brace-format #, python-brace-format
msgid "Problem #{problem:d}" msgid "Problem #{problem:d}"
msgstr "Problème n°{problem:d}" msgstr "Problème n°{problem:d}"
#: apps/participation/models.py:62 #: apps/participation/models.py:64
msgid "problem number" msgid "problem number"
msgstr "numéro de problème" msgstr "numéro de problème"
#: apps/participation/models.py:71 #: apps/participation/models.py:73
msgid "solution video" msgid "solution video"
msgstr "vidéo de solution" msgstr "vidéo de solution"
#: apps/participation/models.py:80 #: apps/participation/models.py:82
msgid "received participation" msgid "received participation"
msgstr "participation reçue" msgstr "participation reçue"
#: apps/participation/models.py:89 #: apps/participation/models.py:91
msgid "synthesis video" msgid "synthesis video"
msgstr "vidéo de synthèse" msgstr "vidéo de synthèse"
#: apps/participation/models.py:93 #: apps/participation/models.py:95
#, python-brace-format #, python-brace-format
msgid "Participation of the team {name} ({trigram})" msgid "Participation of the team {name} ({trigram})"
msgstr "Participation de l'équipe {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" msgid "participation"
msgstr "participation" msgstr "participation"
#: apps/participation/models.py:97 #: apps/participation/models.py:99
msgid "participations" msgid "participations"
msgstr "participations" msgstr "participations"
#: apps/participation/models.py:108 #: apps/participation/models.py:110
msgid "link" msgid "link"
msgstr "lien" msgstr "lien"
#: apps/participation/models.py:109 #: apps/participation/models.py:111
msgid "The full video link." msgid "The full video link."
msgstr "Le lien complet de la vidéo." msgstr "Le lien complet de la vidéo."
#: apps/participation/models.py:115 #: apps/participation/models.py:117
msgid "valid" msgid "valid"
msgstr "valide" msgstr "valide"
#: apps/participation/models.py:116 #: apps/participation/models.py:118
msgid "The video got the validation of the administrators." msgid "The video got the validation of the administrators."
msgstr "La vidéo a été validée par les administrateurs." msgstr "La vidéo a été validée par les administrateurs."
#: apps/participation/models.py:120 #: apps/participation/models.py:122
#, python-brace-format #, python-brace-format
msgid "Video of team {name} ({trigram})" msgid "Video of team {name} ({trigram})"
msgstr "Vidéo de l'équipe {name} ({trigram})" msgstr "Vidéo de l'équipe {name} ({trigram})"
#: apps/participation/models.py:124 #: apps/participation/models.py:126
msgid "video" msgid "video"
msgstr "vidéo" msgstr "vidéo"
#: apps/participation/models.py:125 #: apps/participation/models.py:127
msgid "videos" msgid "videos"
msgstr "vidéos" msgstr "vidéos"
@ -220,7 +221,7 @@ msgid "Create"
msgstr "Créer" msgstr "Créer"
#: apps/participation/templates/participation/create_team_modal.html:8 #: 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" msgid "Create team"
msgstr "Créer une équipe" msgstr "Créer une équipe"
@ -230,7 +231,7 @@ msgid "Join"
msgstr "Rejoindre" msgstr "Rejoindre"
#: apps/participation/templates/participation/join_team_modal.html:8 #: 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" msgid "Join team"
msgstr "Rejoindre une équipe" msgstr "Rejoindre une équipe"
@ -262,6 +263,16 @@ msgstr "Participants :"
msgid "Chosen problem:" msgid "Chosen problem:"
msgstr "Problème choisi :" 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 #: apps/participation/views.py:23 apps/participation/views.py:49
msgid "You don't participate, so you can't create a team." 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." 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:8
#: apps/registration/templates/registration/login_modal.html:15 #: apps/registration/templates/registration/login_modal.html:15
#: apps/registration/templates/registration/password_reset_complete.html:10 #: 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 #: templates/registration/login.html:8 templates/registration/login.html:25
msgid "Log in" msgid "Log in"
msgstr "Connexion" msgstr "Connexion"
@ -604,42 +615,38 @@ msgstr ""
"avec les détails de l'erreur. Vous pouvez désormais retourner voir des " "avec les détails de l'erreur. Vous pouvez désormais retourner voir des "
"vidéos." "vidéos."
#: templates/base.html:70 #: templates/base.html:64
msgid "Home" msgid "Home"
msgstr "Accueil" msgstr "Accueil"
#: templates/base.html:87 #: templates/base.html:81
msgid "My team" msgid "My team"
msgstr "Mon équipe" msgstr "Mon équipe"
#: templates/base.html:94 #: templates/base.html:88
msgid "Make a gift" msgid "Make a gift"
msgstr "Faire un don" msgstr "Faire un don"
#: templates/base.html:98 #: templates/base.html:92
msgid "Administration" msgid "Administration"
msgstr "Administration" msgstr "Administration"
#: templates/base.html:105 #: templates/base.html:99
msgid "Return to admin view" msgid "Return to admin view"
msgstr "Retourner à l'interface administrateur" msgstr "Retourner à l'interface administrateur"
#: templates/base.html:110 #: templates/base.html:104
msgid "Register" msgid "Register"
msgstr "S'inscrire" msgstr "S'inscrire"
#: templates/base.html:119 #: templates/base.html:120
msgid "Log out" msgid "Log out"
msgstr "Déconnexion" msgstr "Déconnexion"
#: templates/base.html:145 #: templates/base.html:147
msgid "Contact us" msgid "Contact us"
msgstr "Nous contacter" msgstr "Nous contacter"
#: templates/base.html:168
msgid "Back to top"
msgstr "Retour en haut"
#: templates/registration/login.html:13 #: templates/registration/login.html:13
#, python-format #, python-format
msgid "" msgid ""
@ -652,3 +659,6 @@ msgstr ""
#: templates/registration/login.html:23 #: templates/registration/login.html:23
msgid "Forgotten your password or username?" msgid "Forgotten your password or username?"
msgstr "Mot de passe oublié ?" msgstr "Mot de passe oublié ?"
#~ msgid "Back to top"
#~ msgstr "Retour en haut"