1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-07-02 05:58:32 +02:00

Prevent registration when we are not between registration dates

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello
2024-10-28 20:21:02 +01:00
parent 9de8a2ed0e
commit fe399c869d
4 changed files with 145 additions and 70 deletions

View File

@ -1,5 +1,6 @@
# Copyright (C) 2020 by Animath
# SPDX-License-Identifier: GPL-3.0-or-later
from datetime import datetime
from django import forms
from django.conf import settings
@ -7,6 +8,7 @@ from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
from django.forms import FileInput
from django.utils.text import format_lazy
from django.utils.translation import gettext_lazy as _
from .models import CoachRegistration, ParticipantRegistration, Payment, \
@ -36,6 +38,19 @@ class SignupForm(UserCreationForm):
self.add_error("email", _("This email address is already used."))
return email
def clean(self):
# Check that registrations are opened
now = datetime.now()
if now < settings.REGISTRATION_DATES['open']:
self.add_error(None, format_lazy(_("Registrations are not opened yet. "
"They will open on the {opening_date:%Y-%m-%d %H:%M}."),
opening_date=settings.REGISTRATION_DATES['open']))
elif now > settings.REGISTRATION_DATES['close']:
self.add_error(None, format_lazy(_("Registrations for this year are closed since "
"{opening_date:%Y-%m-%d %H:%M}."),
opening_date=settings.REGISTRATION_DATES['close']))
return super().clean()
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["first_name"].required = True