2015-03-17 19:03:51 +01:00
|
|
|
from django import forms
|
2021-04-29 00:27:33 +02:00
|
|
|
from django.contrib.auth.forms import UserChangeForm, UserCreationForm
|
2015-03-17 19:03:51 +01:00
|
|
|
from django.contrib.auth.models import User
|
2020-09-10 15:06:53 +02:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
|
2021-04-29 00:27:33 +02:00
|
|
|
from gestion.models import ErnestoUser
|
2016-07-14 01:58:52 +02:00
|
|
|
|
2015-03-17 19:03:51 +01:00
|
|
|
|
|
|
|
class RegistrationFormUser(UserCreationForm):
|
|
|
|
class Meta:
|
|
|
|
model = User
|
2021-04-29 00:27:33 +02:00
|
|
|
fields = (
|
|
|
|
"username",
|
|
|
|
"first_name",
|
|
|
|
"last_name",
|
|
|
|
"password1",
|
|
|
|
"password2",
|
|
|
|
"email",
|
|
|
|
)
|
|
|
|
|
2016-07-14 01:58:52 +02:00
|
|
|
|
2020-09-10 15:06:53 +02:00
|
|
|
class ChangeFormUser(UserChangeForm):
|
|
|
|
password = None
|
2021-04-29 00:27:33 +02:00
|
|
|
|
2020-09-10 15:06:53 +02:00
|
|
|
class Meta:
|
|
|
|
model = User
|
2021-04-29 00:27:33 +02:00
|
|
|
fields = (
|
|
|
|
"first_name",
|
|
|
|
"last_name",
|
|
|
|
"email",
|
|
|
|
)
|
2015-03-17 19:03:51 +01:00
|
|
|
|
2020-09-10 15:06:53 +02:00
|
|
|
|
|
|
|
class ChangeMembreForm(forms.ModelForm):
|
|
|
|
def clean(self):
|
|
|
|
cleaned_data = super(ChangeMembreForm, self).clean()
|
2021-04-29 00:27:33 +02:00
|
|
|
instru = cleaned_data.get("instru")
|
2020-09-10 15:06:53 +02:00
|
|
|
instru_autre = cleaned_data.get("instru_autre")
|
|
|
|
if (instru == "Autre") and not (instru_autre):
|
|
|
|
raise forms.ValidationError(_("Préçisez quel autre instrument"))
|
2021-04-29 00:27:33 +02:00
|
|
|
multi_instru = cleaned_data.get("multi_instrumentiste")
|
2020-09-10 15:06:53 +02:00
|
|
|
instru_bonus = cleaned_data.get("instru_bonus")
|
|
|
|
if (multi_instru == "Oui") and not (instru_bonus):
|
2021-04-29 00:27:33 +02:00
|
|
|
raise forms.ValidationError(
|
|
|
|
_("Préçisez quel·s instrument·s supplémentaire·s vous pouvez jouer")
|
|
|
|
)
|
2020-09-10 15:06:53 +02:00
|
|
|
return cleaned_data
|
2016-07-14 01:58:52 +02:00
|
|
|
|
2015-03-17 19:03:51 +01:00
|
|
|
class Meta:
|
|
|
|
model = ErnestoUser
|
2021-04-29 00:27:33 +02:00
|
|
|
fields = (
|
|
|
|
"phone",
|
|
|
|
"instru",
|
|
|
|
"instru_autre",
|
|
|
|
"multi_instrumentiste",
|
|
|
|
"instru_bonus",
|
|
|
|
)
|
|
|
|
|
2016-07-14 01:58:52 +02:00
|
|
|
|
2020-09-10 15:06:53 +02:00
|
|
|
class InscriptionMembreForm(ChangeMembreForm):
|
|
|
|
validation = forms.CharField(max_length=100, widget=forms.PasswordInput)
|
2016-06-21 00:33:32 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ErnestoUser
|
2021-04-29 00:27:33 +02:00
|
|
|
fields = (
|
|
|
|
"phone",
|
|
|
|
"instru",
|
|
|
|
"instru_autre",
|
|
|
|
"multi_instrumentiste",
|
|
|
|
"instru_bonus",
|
|
|
|
)
|