ernestophone.ens.fr/gestion/forms.py

72 lines
1.9 KiB
Python
Raw Normal View History

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
from django.utils.translation import gettext_lazy as _
2021-04-29 00:27:33 +02:00
from gestion.models import ErnestoUser
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",
)
class ChangeFormUser(UserChangeForm):
password = None
2021-04-29 00:27:33 +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
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")
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")
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")
)
return cleaned_data
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",
)
class InscriptionMembreForm(ChangeMembreForm):
validation = forms.CharField(max_length=100, widget=forms.PasswordInput)
class Meta:
model = ErnestoUser
2021-04-29 00:27:33 +02:00
fields = (
"phone",
"instru",
"instru_autre",
"multi_instrumentiste",
"instru_bonus",
)