2024-02-07 01:26:49 +00:00
|
|
|
# Copyright (C) 2018-2024 by BDE ENS Paris-Saclay
|
2020-04-05 03:17:28 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2020-04-05 07:09:21 +00:00
|
|
|
from django import forms
|
2020-04-05 03:17:28 +00:00
|
|
|
from django.contrib.auth.forms import UserCreationForm
|
|
|
|
from django.contrib.auth.models import User
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
2020-08-03 10:35:51 +00:00
|
|
|
from note.models import NoteSpecial, Alias
|
2020-04-05 07:09:21 +00:00
|
|
|
from note_kfet.inputs import AmountInput
|
2020-04-05 03:17:28 +00:00
|
|
|
|
2023-07-09 08:36:36 +00:00
|
|
|
|
2020-04-05 03:17:28 +00:00
|
|
|
class SignUpForm(UserCreationForm):
|
2020-04-06 06:58:39 +00:00
|
|
|
"""
|
|
|
|
Pre-register users with all information
|
|
|
|
"""
|
2020-04-05 03:17:28 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
self.fields['username'].widget.attrs.pop("autofocus", None)
|
|
|
|
self.fields['first_name'].widget.attrs.update({"autofocus": "autofocus"})
|
|
|
|
self.fields['first_name'].required = True
|
|
|
|
self.fields['last_name'].required = True
|
|
|
|
self.fields['email'].required = True
|
|
|
|
self.fields['email'].help_text = _("This address must be valid.")
|
|
|
|
|
2020-08-10 10:09:05 +00:00
|
|
|
# Give some example
|
|
|
|
self.fields['first_name'].widget.attrs.update({"placeholder": "Sacha"})
|
|
|
|
self.fields['last_name'].widget.attrs.update({"placeholder": "Ketchum"})
|
|
|
|
self.fields['email'].widget.attrs.update({"placeholder": "mail@example.com"})
|
|
|
|
|
2020-08-03 10:35:51 +00:00
|
|
|
def clean_username(self):
|
|
|
|
value = self.cleaned_data["username"]
|
|
|
|
if Alias.objects.filter(normalized_name=Alias.normalize(value)).exists():
|
|
|
|
self.add_error("username", _("An alias with a similar name already exists."))
|
|
|
|
return value
|
|
|
|
|
2020-08-09 14:38:37 +00:00
|
|
|
def clean_email(self):
|
|
|
|
email = self.cleaned_data["email"]
|
|
|
|
if User.objects.filter(email=email).exists():
|
|
|
|
self.add_error("email", _("This email address is already used."))
|
|
|
|
return email
|
|
|
|
|
2020-04-05 03:17:28 +00:00
|
|
|
class Meta:
|
|
|
|
model = User
|
|
|
|
fields = ('first_name', 'last_name', 'username', 'email', )
|
2020-04-05 07:09:21 +00:00
|
|
|
|
|
|
|
|
2023-07-09 08:36:36 +00:00
|
|
|
# class DeclareSogeAccountOpenedForm(forms.Form):
|
|
|
|
# soge_account = forms.BooleanField(
|
|
|
|
# label=_("I declare that I opened or I will open soon a bank account in the Société générale with the BDE "
|
|
|
|
# "partnership."),
|
|
|
|
# help_text=_("Warning: this engages you to open your bank account. If you finally decides to don't open your "
|
|
|
|
# "account, you will have to pay the BDE membership."),
|
|
|
|
# required=False,
|
|
|
|
# )
|
2020-10-07 08:33:57 +00:00
|
|
|
|
|
|
|
|
2020-04-16 21:31:36 +00:00
|
|
|
class WEISignupForm(forms.Form):
|
|
|
|
wei_registration = forms.BooleanField(
|
|
|
|
label=_("Register to the WEI"),
|
|
|
|
required=False,
|
|
|
|
help_text=_("Check this case if you want to register to the WEI. If you hesitate, you will be able to register"
|
|
|
|
" later, after validating your account in the Kfet."),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-04-05 07:09:21 +00:00
|
|
|
class ValidationForm(forms.Form):
|
2020-04-06 06:58:39 +00:00
|
|
|
"""
|
|
|
|
Validate the inscription of the new users and pay memberships.
|
|
|
|
"""
|
2023-07-07 19:44:18 +00:00
|
|
|
# soge = forms.BooleanField(
|
|
|
|
# label=_("Inscription paid by Société Générale"),
|
|
|
|
# required=False,
|
|
|
|
# help_text=_("Check this case if the Société Générale paid the inscription."),
|
|
|
|
# )
|
2020-04-05 13:31:39 +00:00
|
|
|
|
2020-04-05 07:09:21 +00:00
|
|
|
credit_type = forms.ModelChoiceField(
|
|
|
|
queryset=NoteSpecial.objects,
|
|
|
|
label=_("Credit type"),
|
|
|
|
empty_label=_("No credit"),
|
|
|
|
required=False,
|
|
|
|
)
|
|
|
|
|
|
|
|
credit_amount = forms.IntegerField(
|
|
|
|
label=_("Credit amount"),
|
|
|
|
required=False,
|
|
|
|
initial=0,
|
|
|
|
widget=AmountInput(),
|
|
|
|
)
|
|
|
|
|
|
|
|
last_name = forms.CharField(
|
|
|
|
label=_("Last name"),
|
|
|
|
required=False,
|
|
|
|
)
|
|
|
|
|
|
|
|
first_name = forms.CharField(
|
|
|
|
label=_("First name"),
|
|
|
|
required=False,
|
|
|
|
)
|
|
|
|
|
|
|
|
bank = forms.CharField(
|
|
|
|
label=_("Bank"),
|
|
|
|
required=False,
|
|
|
|
)
|
|
|
|
|
2021-05-05 17:46:53 +00:00
|
|
|
join_bde = forms.BooleanField(
|
2020-04-05 13:31:39 +00:00
|
|
|
label=_("Join BDE Club"),
|
2020-04-06 08:45:32 +00:00
|
|
|
required=False,
|
2020-04-05 07:09:21 +00:00
|
|
|
initial=True,
|
|
|
|
)
|
|
|
|
|
2020-04-06 06:58:39 +00:00
|
|
|
# The user can join the Kfet club at the inscription
|
2021-05-05 17:46:53 +00:00
|
|
|
join_kfet = forms.BooleanField(
|
2020-04-05 13:31:39 +00:00
|
|
|
label=_("Join Kfet Club"),
|
2020-04-05 07:09:21 +00:00
|
|
|
required=False,
|
|
|
|
initial=True,
|
|
|
|
)
|