1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-03-16 16:37:32 +00:00

Fix registration dates test

This commit is contained in:
Emmy D'Anello 2025-03-05 19:41:09 +01:00
parent fb10df77e5
commit 758a2c9a00
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
2 changed files with 12 additions and 12 deletions

View File

@ -7,8 +7,6 @@ from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.forms import FileInput from django.forms import FileInput
from django.utils import timezone
from django.utils.text import format_lazy
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from .models import CoachRegistration, ParticipantRegistration, Payment, \ from .models import CoachRegistration, ParticipantRegistration, Payment, \

View File

@ -18,7 +18,7 @@ from django.http import FileResponse, Http404
from django.shortcuts import redirect, resolve_url from django.shortcuts import redirect, resolve_url
from django.template.loader import render_to_string from django.template.loader import render_to_string
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.utils import translation from django.utils import timezone, translation
from django.utils.crypto import get_random_string from django.utils.crypto import get_random_string
from django.utils.http import urlsafe_base64_decode from django.utils.http import urlsafe_base64_decode
from django.utils.text import format_lazy from django.utils.text import format_lazy
@ -60,22 +60,24 @@ class SignupView(CreateView):
return context return context
@transaction.atomic def get_form(self, form_class=None):
def form_valid(self, form): form = super().get_form(form_class)
if not self.request.user.registration.is_admin: if self.request.method in ("POST", "PUT") \
and (not self.request.user.is_authenticated or not self.request.user.registration.is_admin):
# Check that registrations are opened # Check that registrations are opened
now = timezone.now() now = timezone.now()
if now < settings.REGISTRATION_DATES['open']: if now < settings.REGISTRATION_DATES['open']:
form.add_error(None, format_lazy(_("Registrations are not opened yet. " form.add_error(None, format_lazy(_("Registrations are not opened yet. "
"They will open on the {opening_date:%Y-%m-%d %H:%M}."), "They will open on the {opening_date:%Y-%m-%d %H:%M}."),
opening_date=settings.REGISTRATION_DATES['open'])) opening_date=settings.REGISTRATION_DATES['open']))
elif now > settings.REGISTRATION_DATES['close']: elif now > settings.REGISTRATION_DATES['close']:
form.add_error(None, format_lazy(_("Registrations for this year are closed since " form.add_error(None, format_lazy(_("Registrations for this year are closed since "
"{closing_date:%Y-%m-%d %H:%M}."), "{closing_date:%Y-%m-%d %H:%M}."),
closing_date=settings.REGISTRATION_DATES['close'])) closing_date=settings.REGISTRATION_DATES['close']))
if not form.is_valid(): return form
return self.form_invalid(form)
@transaction.atomic
def form_valid(self, form):
role = form.cleaned_data["role"] role = form.cleaned_data["role"]
if role == "participant": if role == "participant":
registration_form = StudentRegistrationForm(self.request.POST) registration_form = StudentRegistrationForm(self.request.POST)