mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-03-16 16:37:32 +00:00
Allow admins to create users outside registration period
This commit is contained in:
parent
905b96fbcf
commit
fb10df77e5
@ -38,19 +38,6 @@ class SignupForm(UserCreationForm):
|
|||||||
self.add_error("email", _("This email address is already used."))
|
self.add_error("email", _("This email address is already used."))
|
||||||
return email
|
return email
|
||||||
|
|
||||||
def clean(self):
|
|
||||||
# Check that registrations are opened
|
|
||||||
now = timezone.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 "
|
|
||||||
"{closing_date:%Y-%m-%d %H:%M}."),
|
|
||||||
closing_date=settings.REGISTRATION_DATES['close']))
|
|
||||||
return super().clean()
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.fields["first_name"].required = True
|
self.fields["first_name"].required = True
|
||||||
|
@ -10,13 +10,13 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% now "c" as now %}
|
{% now "c" as now %}
|
||||||
{% if now < TFJM.REGISTRATION_DATES.open.isoformat %}
|
{% if now < TFJM.REGISTRATION_DATES.open.isoformat and not user.registration.is_admin %}
|
||||||
<div class="alert alert-warning">
|
<div class="alert alert-warning">
|
||||||
{% trans "Thank you for your great interest, but registrations are not opened yet!" %}
|
{% trans "Thank you for your great interest, but registrations are not opened yet!" %}
|
||||||
{% trans "They will open on:" %} {{ TFJM.REGISTRATION_DATES.open|date:'DATETIME_FORMAT' }}.
|
{% trans "They will open on:" %} {{ TFJM.REGISTRATION_DATES.open|date:'DATETIME_FORMAT' }}.
|
||||||
{% trans "Please come back at this time to register!" %}
|
{% trans "Please come back at this time to register!" %}
|
||||||
</div>
|
</div>
|
||||||
{% elif now > TFJM.REGISTRATION_DATES.close.isoformat %}
|
{% elif now > TFJM.REGISTRATION_DATES.close.isoformat and not user.registration.is_admin %}
|
||||||
<div class="alert alert-danger">
|
<div class="alert alert-danger">
|
||||||
{% trans "Registrations are closed for this year. We hope to see you next year!" %}
|
{% trans "Registrations are closed for this year. We hope to see you next year!" %}
|
||||||
{% trans "If needed, you can contact us by mail." %}
|
{% trans "If needed, you can contact us by mail." %}
|
||||||
|
@ -62,6 +62,20 @@ class SignupView(CreateView):
|
|||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
|
if not self.request.user.registration.is_admin:
|
||||||
|
# Check that registrations are opened
|
||||||
|
now = timezone.now()
|
||||||
|
if now < settings.REGISTRATION_DATES['open']:
|
||||||
|
form.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']:
|
||||||
|
form.add_error(None, format_lazy(_("Registrations for this year are closed since "
|
||||||
|
"{closing_date:%Y-%m-%d %H:%M}."),
|
||||||
|
closing_date=settings.REGISTRATION_DATES['close']))
|
||||||
|
if not form.is_valid():
|
||||||
|
return self.form_invalid(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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user