From 427786769f73f412b4331d97f9c944ab9de3e058 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sun, 11 Oct 2020 16:30:02 +0200 Subject: [PATCH] Teams can request a validation --- .../migrations/0005_participation_valid.py | 18 +++++ .../templates/participation/team_detail.html | 35 ++++++++- apps/participation/views.py | 20 +++-- locale/fr/LC_MESSAGES/django.po | 77 +++++++++++++------ 4 files changed, 116 insertions(+), 34 deletions(-) create mode 100644 apps/participation/migrations/0005_participation_valid.py diff --git a/apps/participation/migrations/0005_participation_valid.py b/apps/participation/migrations/0005_participation_valid.py new file mode 100644 index 0000000..f22fc7d --- /dev/null +++ b/apps/participation/migrations/0005_participation_valid.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.1 on 2020-10-11 13:58 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('participation', '0004_auto_20200927_1322'), + ] + + operations = [ + migrations.AddField( + model_name='participation', + name='valid', + field=models.BooleanField(default=None, help_text='The video got the validation of the administrators.', null=True, verbose_name='valid'), + ), + ] diff --git a/apps/participation/templates/participation/team_detail.html b/apps/participation/templates/participation/team_detail.html index 018fcb2..a4570e4 100644 --- a/apps/participation/templates/participation/team_detail.html +++ b/apps/participation/templates/participation/team_detail.html @@ -1,6 +1,7 @@ {% extends "base.html" %} {% load i18n %} +{% load crispy_forms_filters %} {% block content %} @@ -61,16 +62,42 @@ - {% if team.participation.valid %} -
+
+ {% if team.participation.valid %}
{% trans "Access to team participation" %}
- {% else %} - {# TODO Validate team #} + {% elif team.participation.valid is None %} {# Team did not ask for validation #} + {% if user.registration.participates %} + {% if can_validate %} +
+ {% trans "Your team has at least 3 members and all photo authorizations were given: the team can be validated." %} +
+ +
+
+ {% else %} +
+ {% trans "Your team must be composed of 3 members and each member must upload its photo authorization." %} +
+ {% endif %} + {% else %} +
+ {% trans "This team didn't ask for validation yet." %} +
+ {% endif %} + {% else %} {# Team is waiting for validation #} + {% if user.registration.participates %} +
+ {% trans "Your validation is pending." %} +
+ {% else %} + Team asked for validation. + {# TODO Add validation form: validate or invalidate, with a message #} + {% endif %} {% endif %} {% trans "Update team" as modal_title %} diff --git a/apps/participation/views.py b/apps/participation/views.py index 22d72c4..6e8b9d0 100644 --- a/apps/participation/views.py +++ b/apps/participation/views.py @@ -90,12 +90,22 @@ class MyTeamDetailView(LoginRequiredMixin, RedirectView): class TeamDetailView(LoginRequiredMixin, DetailView): model = Team - def dispatch(self, request, *args, **kwargs): + def get(self, request, *args, **kwargs): user = request.user if user.registration.is_admin or user.registration.participates and user.registration.team.pk == kwargs["pk"]: - return super().dispatch(request, *args, **kwargs) + return super().get(request, *args, **kwargs) raise PermissionDenied + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + + team = self.object + context["can_validate"] = team.students.count() >= 3 and \ + all(r.photo_authorization for r in team.students.all()) and \ + team.participation.problem + + return context + class TeamUpdateView(LoginRequiredMixin, UpdateView): model = Team @@ -148,7 +158,7 @@ class TeamAuthorizationsView(LoginRequiredMixin, DetailView): _("Photo authorization of {student}.{ext}").format(student=str(student), ext=ext)) zf.close() response = HttpResponse(content_type="application/zip") - response["Content-Disposition"] = "attachment; filename=\"{filename}\""\ + response["Content-Disposition"] = "attachment; filename=\"{filename}\"" \ .format(filename=_("Photo authorizations of team {trigram}.zip").format(trigram=team.trigram)) response.write(output.getvalue()) return response @@ -172,7 +182,7 @@ class ParticipationDetailView(LoginRequiredMixin, DetailView): user = request.user if not self.get_object().valid: raise PermissionDenied(_("The team is not validated yet.")) - if user.registration.is_admin or user.registration.participates\ + if user.registration.is_admin or user.registration.participates \ and user.registration.team.participation.pk == kwargs["pk"]: return super().dispatch(request, *args, **kwargs) raise PermissionDenied @@ -185,7 +195,7 @@ class UploadVideoView(LoginRequiredMixin, UpdateView): def dispatch(self, request, *args, **kwargs): user = request.user - if user.registration.is_admin or user.registration.participates\ + if user.registration.is_admin or user.registration.participates \ and user.registration.team.participation.pk == self.get_object().participation.pk: return super().dispatch(request, *args, **kwargs) raise PermissionDenied diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po index 44e0ee3..6876998 100644 --- a/locale/fr/LC_MESSAGES/django.po +++ b/locale/fr/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Corres2math\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-10-11 15:58+0200\n" +"POT-Creation-Date: 2020-10-11 16:27+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: Yohann D'ANELLO \n" "Language-Team: LANGUAGE \n" @@ -223,9 +223,9 @@ msgid "Join" msgstr "Rejoindre" #: apps/participation/templates/participation/participation_detail.html:6 -#: apps/participation/templates/participation/team_detail.html:27 -#: apps/participation/templates/participation/team_detail.html:36 -#: apps/participation/templates/participation/team_detail.html:41 +#: apps/participation/templates/participation/team_detail.html:28 +#: apps/participation/templates/participation/team_detail.html:37 +#: apps/participation/templates/participation/team_detail.html:42 #: apps/registration/templates/registration/user_detail.html:6 #: apps/registration/templates/registration/user_detail.html:26 msgid "any" @@ -241,7 +241,7 @@ msgid "Team:" msgstr "Équipe :" #: apps/participation/templates/participation/participation_detail.html:16 -#: apps/participation/templates/participation/team_detail.html:40 +#: apps/participation/templates/participation/team_detail.html:41 msgid "Chosen problem:" msgstr "Problème choisi :" @@ -269,40 +269,40 @@ msgstr "La plateforme de cette vidéo n'est pas encore supportée." msgid "Upload video" msgstr "Envoyer la vidéo" -#: apps/participation/templates/participation/team_detail.html:13 +#: apps/participation/templates/participation/team_detail.html:14 msgid "Name:" msgstr "Nom :" -#: apps/participation/templates/participation/team_detail.html:16 +#: apps/participation/templates/participation/team_detail.html:17 msgid "Trigram:" msgstr "Trigramme :" -#: apps/participation/templates/participation/team_detail.html:19 +#: apps/participation/templates/participation/team_detail.html:20 msgid "Access code:" msgstr "Code d'accès :" -#: apps/participation/templates/participation/team_detail.html:22 +#: apps/participation/templates/participation/team_detail.html:23 msgid "Coachs:" msgstr "Encadrants :" -#: apps/participation/templates/participation/team_detail.html:31 +#: apps/participation/templates/participation/team_detail.html:32 msgid "Participants:" msgstr "Participants :" -#: apps/participation/templates/participation/team_detail.html:44 +#: apps/participation/templates/participation/team_detail.html:45 msgid "Grant Animath to publish our video:" msgstr "Autoriser Animath à publier notre vidéo :" -#: apps/participation/templates/participation/team_detail.html:47 +#: apps/participation/templates/participation/team_detail.html:48 msgid "Authorizations:" msgstr "Autorisations :" -#: apps/participation/templates/participation/team_detail.html:53 +#: apps/participation/templates/participation/team_detail.html:54 msgid "Not uploaded yet" msgstr "Pas encore envoyée" -#: apps/participation/templates/participation/team_detail.html:60 -#: apps/participation/templates/participation/team_detail.html:73 +#: apps/participation/templates/participation/team_detail.html:61 +#: apps/participation/templates/participation/team_detail.html:104 #: apps/participation/templates/participation/update_team.html:12 #: apps/registration/templates/registration/update_user.html:12 #: apps/registration/templates/registration/user_detail.html:64 @@ -310,11 +310,39 @@ msgstr "Pas encore envoyée" msgid "Update" msgstr "Modifier" -#: apps/participation/templates/participation/team_detail.html:68 +#: apps/participation/templates/participation/team_detail.html:70 msgid "Access to team participation" msgstr "Accéder à la participation de l'équipe" -#: apps/participation/templates/participation/team_detail.html:72 +#: apps/participation/templates/participation/team_detail.html:77 +msgid "" +"Your team has at least 3 members and all photo authorizations were given: " +"the team can be validated." +msgstr "" +"Votre équipe contient au moins 3 personnes et toutes les autorisations de " +"droit à l'image ont été données : l'équipe peut être validée." + +#: apps/participation/templates/participation/team_detail.html:79 +msgid "Submit my team to validation" +msgstr "Soumettre mon équipe à validation" + +#: apps/participation/templates/participation/team_detail.html:84 +msgid "" +"Your team must be composed of 3 members and each member must upload its " +"photo authorization." +msgstr "" +"Votre équipe doit être composée de 3 membres et chaque membre doit envoyer " +"son autorisation de droit à l'image." + +#: apps/participation/templates/participation/team_detail.html:89 +msgid "This team didn't ask for validation yet." +msgstr "L'équipe n'a pas encore demandé à être validée." + +#: apps/participation/templates/participation/team_detail.html:95 +msgid "Your validation is pending." +msgstr "" + +#: apps/participation/templates/participation/team_detail.html:103 msgid "Update team" msgstr "Modifier l'équipe" @@ -336,26 +364,25 @@ msgstr "Vous êtes déjà dans une équipe." msgid "Join team" msgstr "Rejoindre une équipe" -#: apps/participation/views.py:86 apps/participation/views.py:164 +#: apps/participation/views.py:86 apps/participation/views.py:172 msgid "You are not in a team." msgstr "Vous n'êtes pas dans une équipe." -#: apps/participation/views.py:87 apps/participation/views.py:165 +#: apps/participation/views.py:87 apps/participation/views.py:173 msgid "You don't participate, so you don't have any team." msgstr "Vous ne participez pas, vous n'avez donc pas d'équipe." -#: apps/participation/views.py:148 apps/registration/views.py:213 +#: apps/participation/views.py:156 apps/registration/views.py:213 #, python-brace-format msgid "Photo authorization of {student}.{ext}" msgstr "Autorisation de droit à l'image de {student}.{ext}" -#: apps/participation/views.py:152 -#, fuzzy, python-brace-format -#| msgid "Photo authorization of {student}.{ext}" +#: apps/participation/views.py:160 +#, python-brace-format msgid "Photo authorizations of team {trigram}.zip" -msgstr "Autorisation de droit à l'image de {student}.{ext}" +msgstr "Autorisations de droit à l'image de l'équipe {trigram}.zip" -#: apps/participation/views.py:174 +#: apps/participation/views.py:182 msgid "The team is not validated yet." msgstr "L'équipe n'est pas encore validée."