1
0
mirror of https://gitlab.com/animath/si/plateforme-corres2math.git synced 2024-12-05 01:26:54 +00:00

We can only register during the first phase

This commit is contained in:
Yohann D'ANELLO 2020-11-15 01:50:12 +01:00
parent d3e18a8fbb
commit 731f8711ff
7 changed files with 112 additions and 100 deletions

View File

@ -0,0 +1,12 @@
from django import template
from ..models import Phase
def current_phase(nb):
phase = Phase.current_phase()
return phase is not None and phase.phase_number == nb
register = template.Library()
register.filter("current_phase", current_phase)

View File

@ -4,7 +4,6 @@ from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
from django.forms import FileInput
from django.utils.translation import gettext_lazy as _
from participation.models import Phase
from .models import AdminRegistration, CoachRegistration, StudentRegistration
@ -29,11 +28,6 @@ class SignupForm(UserCreationForm):
self.fields["last_name"].required = True
self.fields["email"].required = True
def clean(self):
if Phase.current_phase() is None or Phase.current_phase().phase_number >= 2:
self.add_error(None, _("You can't register now."))
return super().clean()
class Meta:
model = User
fields = ('first_name', 'last_name', 'email', 'password1', 'password2', 'role',)

View File

@ -84,26 +84,16 @@ class TestRegistration(TestCase):
"""
Ensure that the signup form is working successfully.
"""
response = self.client.get(reverse("registration:signup"))
self.assertEqual(response.status_code, 200)
# After first phase
response = self.client.post(reverse("registration:signup"), data=dict(
last_name="Toto",
first_name="Toto",
email="toto@example.com",
password1="azertyuiopazertyuiop",
password2="azertyuiopazertyuiop",
role="participant",
student_class=12,
school="God",
give_contact_to_animath=False,
))
self.assertEqual(response.status_code, 200)
response = self.client.get(reverse("registration:signup"))
self.assertEqual(response.status_code, 403)
Phase.objects.filter(phase_number__gte=2).update(start=timezone.now() + timedelta(days=1),
end=timezone.now() + timedelta(days=2))
response = self.client.get(reverse("registration:signup"))
self.assertEqual(response.status_code, 200)
# Incomplete form
response = self.client.post(reverse("registration:signup"), data=dict(
last_name="Toto",

View File

@ -13,6 +13,7 @@ from django.utils.http import urlsafe_base64_decode
from django.utils.translation import gettext_lazy as _
from django.views.generic import CreateView, DetailView, RedirectView, TemplateView, UpdateView, View
from magic import Magic
from participation.models import Phase
from .forms import CoachRegistrationForm, PhotoAuthorizationForm, SignupForm, StudentRegistrationForm, UserForm
from .models import StudentRegistration
@ -27,6 +28,15 @@ class SignupView(CreateView):
template_name = "registration/signup.html"
extra_context = dict(title=_("Sign up"))
def dispatch(self, request, *args, **kwargs):
"""
The signup view is available only during the first phase.
"""
current_phase = Phase.current_phase()
if not current_phase or current_phase.phase_number >= 2:
raise PermissionDenied(_("You can't register now."))
return super().dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs):
context = super().get_context_data()

View File

@ -1,4 +1,4 @@
{% load static i18n static %}
{% load static i18n static calendar %}
<!DOCTYPE html>
{% get_current_language as LANGUAGE_CODE %}{% get_current_language_bidi as LANGUAGE_BIDI %}
@ -122,9 +122,11 @@
</li>
{% endif %}
{% if not user.is_authenticated %}
{% if 1|current_phase %}
<li class="nav-item active">
<a class="nav-link" href="{% url "registration:signup" %}"><i class="fas fa-user-plus"></i> {% trans "Register" %}</a>
</li>
{% endif %}
<li class="nav-item active">
<a class="nav-link" href="#" data-toggle="modal" data-target="#loginModal">
<i class="fas fa-sign-in-alt"></i> {% trans "Log in" %}

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Corres2math\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-11-03 17:32+0100\n"
"POT-Creation-Date: 2020-11-15 01:49+0100\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"
@ -99,17 +99,17 @@ 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/admin.py:16 apps/participation/models.py:122
#: apps/participation/admin.py:16 apps/participation/models.py:132
#: apps/participation/tables.py:35 apps/participation/tables.py:62
msgid "problem number"
msgstr "numéro de problème"
#: apps/participation/admin.py:21 apps/participation/models.py:128
#: apps/participation/models.py:182
#: apps/participation/admin.py:21 apps/participation/models.py:138
#: apps/participation/models.py:192
msgid "valid"
msgstr "valide"
#: apps/participation/forms.py:20 apps/participation/models.py:33
#: apps/participation/forms.py:20 apps/participation/models.py:32
msgid "The trigram must be composed of three uppercase letters."
msgstr "Le trigramme doit être composé de trois lettres majuscules."
@ -155,28 +155,28 @@ msgstr "Cette phase doit commencer après les phases précédentes."
msgid "This phase must end after the next phases."
msgstr "Cette phase doit finir avant les phases suivantes."
#: apps/participation/models.py:26 apps/participation/tables.py:30
#: apps/participation/models.py:25 apps/participation/tables.py:30
#: apps/participation/tables.py:52 apps/participation/tables.py:78
msgid "name"
msgstr "nom"
#: apps/participation/models.py:32 apps/participation/tables.py:57
#: apps/participation/models.py:31 apps/participation/tables.py:57
msgid "trigram"
msgstr "trigramme"
#: apps/participation/models.py:40
#: apps/participation/models.py:39
msgid "access code"
msgstr "code d'accès"
#: apps/participation/models.py:41
#: apps/participation/models.py:40
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:45
#: apps/participation/models.py:44
msgid "Grant Animath to publish my video"
msgstr "Autoriser Animath à publier ma vidéo"
#: apps/participation/models.py:46
#: apps/participation/models.py:45
msgid ""
"Give the authorisation to publish the video on the main website to promote "
"the action."
@ -184,96 +184,96 @@ msgstr ""
"Donner l'autorisation de publier la vidéo sur le site principal pour "
"promouvoir les Correspondances."
#: apps/participation/models.py:97
#: apps/participation/models.py:107
#, python-brace-format
msgid "Team {name} ({trigram})"
msgstr "Équipe {name} ({trigram})"
#: apps/participation/models.py:100 apps/participation/models.py:115
#: apps/participation/models.py:110 apps/participation/models.py:125
#: apps/registration/models.py:106 apps/registration/models.py:155
msgid "team"
msgstr "équipe"
#: apps/participation/models.py:101
#: apps/participation/models.py:111
msgid "teams"
msgstr "équipes"
#: apps/participation/models.py:119
#: apps/participation/models.py:129
#, python-brace-format
msgid "Problem #{problem:d}"
msgstr "Problème n°{problem:d}"
#: apps/participation/models.py:129 apps/participation/models.py:183
#: apps/participation/models.py:139 apps/participation/models.py:193
msgid "The video got the validation of the administrators."
msgstr "La vidéo a été validée par les administrateurs."
#: apps/participation/models.py:138
#: apps/participation/models.py:148
msgid "solution video"
msgstr "vidéo de solution"
#: apps/participation/models.py:147
#: apps/participation/models.py:157
msgid "received participation"
msgstr "participation reçue"
#: apps/participation/models.py:156
#: apps/participation/models.py:166
msgid "synthesis video"
msgstr "vidéo de synthèse"
#: apps/participation/models.py:163
#: apps/participation/models.py:173
#, python-brace-format
msgid "Participation of the team {name} ({trigram})"
msgstr "Participation de l'équipe {name} ({trigram})"
#: apps/participation/models.py:166 apps/participation/models.py:240
#: apps/participation/models.py:176 apps/participation/models.py:250
msgid "participation"
msgstr "participation"
#: apps/participation/models.py:167
#: apps/participation/models.py:177
msgid "participations"
msgstr "participations"
#: apps/participation/models.py:175
#: apps/participation/models.py:185
msgid "link"
msgstr "lien"
#: apps/participation/models.py:176
#: apps/participation/models.py:186
msgid "The full video link."
msgstr "Le lien complet de la vidéo."
#: apps/participation/models.py:225
#: apps/participation/models.py:235
#, python-brace-format
msgid "Video of team {name} ({trigram})"
msgstr "Vidéo de l'équipe {name} ({trigram})"
#: apps/participation/models.py:229
#: apps/participation/models.py:239
msgid "video"
msgstr "vidéo"
#: apps/participation/models.py:230
#: apps/participation/models.py:240
msgid "videos"
msgstr "vidéos"
#: apps/participation/models.py:245
#: apps/participation/models.py:255
msgid "question"
msgstr "question"
#: apps/participation/models.py:259
#: apps/participation/models.py:269
msgid "phase number"
msgstr "phase"
#: apps/participation/models.py:264
#: apps/participation/models.py:274
msgid "phase description"
msgstr "description"
#: apps/participation/models.py:268
#: apps/participation/models.py:278
msgid "start date of the given phase"
msgstr "début de la phase"
#: apps/participation/models.py:273
#: apps/participation/models.py:283
msgid "end date of the given phase"
msgstr "fin de la phase"
#: apps/participation/models.py:291
#: apps/participation/models.py:299
msgid ""
"Phase {phase_number:d} starts on {start:%Y-%m-%d %H:%M} and ends on {end:%Y-"
"%m-%d %H:%M}"
@ -281,21 +281,21 @@ msgstr ""
"Phase {phase_number:d} démarrant le {start:%d/%m/%Y %H:%M} et finissant le "
"{end:%d/%m/%Y %H:%M}"
#: apps/participation/models.py:295
#: apps/participation/models.py:303
msgid "phase"
msgstr "phase"
#: apps/participation/models.py:296
#: apps/participation/models.py:304
msgid "phases"
msgstr "phases"
#: apps/participation/templates/participation/create_team.html:11
#: corres2math/templates/base.html:231
#: corres2math/templates/base.html:233
msgid "Create"
msgstr "Créer"
#: apps/participation/templates/participation/join_team.html:11
#: corres2math/templates/base.html:227
#: corres2math/templates/base.html:229
msgid "Join"
msgstr "Rejoindre"
@ -469,7 +469,7 @@ msgstr "Définir l'équipe qui recevra votre vidéo"
#: apps/participation/templates/participation/participation_detail.html:181
#: apps/participation/templates/participation/participation_detail.html:233
#: apps/participation/views.py:482
#: apps/participation/views.py:490
msgid "Upload video"
msgstr "Envoyer la vidéo"
@ -504,7 +504,7 @@ msgid "Update question"
msgstr "Modifier la question"
#: apps/participation/templates/participation/participation_detail.html:217
#: apps/participation/views.py:459
#: apps/participation/views.py:466
msgid "Delete question"
msgstr "Supprimer la question"
@ -514,8 +514,8 @@ msgid "Display synthesis"
msgstr "Afficher la synthèse"
#: apps/participation/templates/participation/phase_list.html:10
#: apps/participation/views.py:501 corres2math/templates/base.html:68
#: corres2math/templates/base.html:70 corres2math/templates/base.html:217
#: apps/participation/views.py:509 corres2math/templates/base.html:68
#: corres2math/templates/base.html:70 corres2math/templates/base.html:219
msgid "Calendar"
msgstr "Calendrier"
@ -627,7 +627,7 @@ msgid "Update team"
msgstr "Modifier l'équipe"
#: apps/participation/templates/participation/team_detail.html:127
#: apps/participation/views.py:314
#: apps/participation/views.py:319
msgid "Leave team"
msgstr "Quitter l'équipe"
@ -636,7 +636,7 @@ msgid "Are you sure that you want to leave this team?"
msgstr "Êtes-vous sûr·e de vouloir quitter cette équipe ?"
#: apps/participation/views.py:36 corres2math/templates/base.html:77
#: corres2math/templates/base.html:230
#: corres2math/templates/base.html:232
msgid "Create team"
msgstr "Créer une équipe"
@ -649,16 +649,16 @@ msgid "You are already in a team."
msgstr "Vous êtes déjà dans une équipe."
#: apps/participation/views.py:82 corres2math/templates/base.html:82
#: corres2math/templates/base.html:226
#: corres2math/templates/base.html:228
msgid "Join team"
msgstr "Rejoindre une équipe"
#: apps/participation/views.py:133 apps/participation/views.py:320
#: apps/participation/views.py:353
#: apps/participation/views.py:133 apps/participation/views.py:325
#: apps/participation/views.py:358
msgid "You are not in a team."
msgstr "Vous n'êtes pas dans une équipe."
#: apps/participation/views.py:134 apps/participation/views.py:354
#: apps/participation/views.py:134 apps/participation/views.py:359
msgid "You don't participate, so you don't have any team."
msgstr "Vous ne participez pas, vous n'avez donc pas d'équipe."
@ -694,43 +694,43 @@ msgstr "Vous n'êtes pas administrateur."
msgid "This team has no pending validation."
msgstr "L'équipe n'a pas de validation en attente."
#: apps/participation/views.py:235
#: apps/participation/views.py:240
msgid "You must specify if you validate the registration or not."
msgstr "Vous devez spécifier si vous validez l'inscription ou non."
#: apps/participation/views.py:263
#: apps/participation/views.py:268
#, python-brace-format
msgid "Update team {trigram}"
msgstr "Mise à jour de l'équipe {trigram}"
#: apps/participation/views.py:300 apps/registration/views.py:243
#: apps/participation/views.py:305 apps/registration/views.py:253
#, python-brace-format
msgid "Photo authorization of {student}.{ext}"
msgstr "Autorisation de droit à l'image de {student}.{ext}"
#: apps/participation/views.py:304
#: apps/participation/views.py:309
#, python-brace-format
msgid "Photo authorizations of team {trigram}.zip"
msgstr "Autorisations de droit à l'image de l'équipe {trigram}.zip"
#: apps/participation/views.py:322
#: apps/participation/views.py:327
msgid "The team is already validated or the validation is pending."
msgstr "La validation de l'équipe est déjà faite ou en cours."
#: apps/participation/views.py:366
#: apps/participation/views.py:371
msgid "The team is not validated yet."
msgstr "L'équipe n'est pas encore validée."
#: apps/participation/views.py:376
#: apps/participation/views.py:381
#, python-brace-format
msgid "Participation of team {trigram}"
msgstr "Participation de l'équipe {trigram}"
#: apps/participation/views.py:413
#: apps/participation/views.py:418
msgid "Create question"
msgstr "Créer une question"
#: apps/participation/views.py:510
#: apps/participation/views.py:518
msgid "Calendar update"
msgstr "Mise à jour du calendrier"
@ -923,8 +923,8 @@ msgid "Your password has been set. You may go ahead and log in now."
msgstr "Votre mot de passe a été changé. Vous pouvez désormais vous connecter."
#: apps/registration/templates/registration/password_reset_complete.html:10
#: corres2math/templates/base.html:130 corres2math/templates/base.html:221
#: corres2math/templates/base.html:222
#: corres2math/templates/base.html:132 corres2math/templates/base.html:223
#: corres2math/templates/base.html:224
#: corres2math/templates/registration/login.html:7
#: corres2math/templates/registration/login.html:8
#: corres2math/templates/registration/login.html:25
@ -981,7 +981,7 @@ msgstr "Réinitialiser mon mot de passe"
#: apps/registration/templates/registration/signup.html:5
#: apps/registration/templates/registration/signup.html:8
#: apps/registration/templates/registration/signup.html:20
#: apps/registration/views.py:28
#: apps/registration/views.py:29
msgid "Sign up"
msgstr "Inscription"
@ -1058,45 +1058,49 @@ msgid "Update user"
msgstr "Modifier l'utilisateur"
#: apps/registration/templates/registration/user_detail.html:77
#: apps/registration/views.py:206
#: apps/registration/views.py:216
msgid "Upload photo authorization"
msgstr "Téléverser l'autorisation de droit à l'image"
#: apps/registration/views.py:64
#: apps/registration/views.py:37
msgid "You can't register now."
msgstr "Vous ne pouvez pas vous inscrire maintenant."
#: apps/registration/views.py:74
msgid "Email validation"
msgstr "Validation de l'adresse mail"
#: apps/registration/views.py:66
#: apps/registration/views.py:76
msgid "Validate email"
msgstr "Valider l'adresse mail"
#: apps/registration/views.py:105
#: apps/registration/views.py:115
msgid "Email validation unsuccessful"
msgstr "Échec de la validation de l'adresse mail"
#: apps/registration/views.py:116
#: apps/registration/views.py:126
msgid "Email validation email sent"
msgstr "Mail de confirmation de l'adresse mail envoyé"
#: apps/registration/views.py:124
#: apps/registration/views.py:134
msgid "Resend email validation link"
msgstr "Renvoyé le lien de validation de l'adresse mail"
#: apps/registration/views.py:158
#: apps/registration/views.py:168
#, python-brace-format
msgid "Detail of user {user}"
msgstr "Détails de l'utilisateur {user}"
#: apps/registration/views.py:179
#: apps/registration/views.py:189
#, python-brace-format
msgid "Update user {user}"
msgstr "Mise à jour de l'utilisateur {user}"
#: corres2math/settings.py:154
#: corres2math/settings.py:157
msgid "English"
msgstr "Anglais"
#: corres2math/settings.py:155
#: corres2math/settings.py:158
msgid "French"
msgstr "Français"
@ -1181,19 +1185,19 @@ msgstr "Chercher ..."
msgid "Return to admin view"
msgstr "Retourner à l'interface administrateur"
#: corres2math/templates/base.html:126
#: corres2math/templates/base.html:127
msgid "Register"
msgstr "S'inscrire"
#: corres2math/templates/base.html:142
#: corres2math/templates/base.html:144
msgid "My account"
msgstr "Mon compte"
#: corres2math/templates/base.html:145
#: corres2math/templates/base.html:147
msgid "Log out"
msgstr "Déconnexion"
#: corres2math/templates/base.html:162
#: corres2math/templates/base.html:164
#, python-format
msgid ""
"Your email address is not validated. Please click on the link you received "
@ -1204,11 +1208,11 @@ msgstr ""
"avez reçu par mail. Vous pouvez renvoyer un mail en cliquant sur <a href="
"\"%(send_email_url)s\">ce lien</a>."
#: corres2math/templates/base.html:186
#: corres2math/templates/base.html:188
msgid "Contact us"
msgstr "Nous contacter"
#: corres2math/templates/base.html:219
#: corres2math/templates/base.html:221
msgid "Search results"
msgstr "Résultats de la recherche"