71 lines
1.9 KiB
Python
71 lines
1.9 KiB
Python
from django import forms
|
|
from django.contrib.auth.forms import UserChangeForm, UserCreationForm
|
|
from django.contrib.auth.models import User
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from gestion.models import ErnestoUser
|
|
|
|
|
|
class RegistrationFormUser(UserCreationForm):
|
|
class Meta:
|
|
model = User
|
|
fields = (
|
|
"username",
|
|
"first_name",
|
|
"last_name",
|
|
"password1",
|
|
"password2",
|
|
"email",
|
|
)
|
|
|
|
|
|
class ChangeFormUser(UserChangeForm):
|
|
password = None
|
|
|
|
class Meta:
|
|
model = User
|
|
fields = (
|
|
"first_name",
|
|
"last_name",
|
|
"email",
|
|
)
|
|
|
|
|
|
class ChangeMembreForm(forms.ModelForm):
|
|
def clean(self):
|
|
cleaned_data = super(ChangeMembreForm, self).clean()
|
|
instru = cleaned_data.get("instru")
|
|
instru_autre = cleaned_data.get("instru_autre")
|
|
if (instru == "Autre") and not (instru_autre):
|
|
raise forms.ValidationError(_("Préçisez quel autre instrument"))
|
|
multi_instru = cleaned_data.get("multi_instrumentiste")
|
|
instru_bonus = cleaned_data.get("instru_bonus")
|
|
if (multi_instru == "Oui") and not (instru_bonus):
|
|
raise forms.ValidationError(
|
|
_("Préçisez quel·s instrument·s supplémentaire·s vous pouvez jouer")
|
|
)
|
|
return cleaned_data
|
|
|
|
class Meta:
|
|
model = ErnestoUser
|
|
fields = (
|
|
"phone",
|
|
"instru",
|
|
"instru_autre",
|
|
"multi_instrumentiste",
|
|
"instru_bonus",
|
|
)
|
|
|
|
|
|
class InscriptionMembreForm(ChangeMembreForm):
|
|
validation = forms.CharField(max_length=100, widget=forms.PasswordInput)
|
|
|
|
class Meta:
|
|
model = ErnestoUser
|
|
fields = (
|
|
"phone",
|
|
"instru",
|
|
"instru_autre",
|
|
"multi_instrumentiste",
|
|
"instru_bonus",
|
|
)
|