1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-07-04 04:12:08 +02:00

Register new organizers

This commit is contained in:
Yohann D'ANELLO
2021-01-14 21:07:09 +01:00
parent 1a7a411e10
commit 3e7ff21746
7 changed files with 179 additions and 41 deletions

View File

@ -45,6 +45,38 @@ class SignupForm(UserCreationForm):
fields = ('first_name', 'last_name', 'email', 'password1', 'password2', 'role',)
class AddOrganizerForm(forms.ModelForm):
"""
Signup form to registers volunteers
"""
type = forms.ChoiceField(
label=lambda: _("role").capitalize(),
choices=lambda: [
("volunteer", _("volunteer").capitalize()),
("admin", _("admin").capitalize()),
],
)
def clean_email(self):
"""
Ensure that the email address is unique.
"""
email = self.data["email"]
if User.objects.filter(email=email).exists():
self.add_error("email", _("This email address is already used."))
return email
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["first_name"].required = True
self.fields["last_name"].required = True
self.fields["email"].required = True
class Meta:
model = User
fields = ('first_name', 'last_name', 'email', 'type',)
class UserForm(forms.ModelForm):
"""
Replace the default user form to require the first name, last name and the email.