X-Git-Url: https://git.mdrn.pl/cas.git/blobdiff_plain/3a65fcbfa423d5627e41c2f9e17c464d4a594087..a98197a1a1dd5fb58e727cb334bfc2357501d366:/src/accounts/forms.py?ds=sidebyside diff --git a/src/accounts/forms.py b/src/accounts/forms.py index 0c8cb66..5a1b62e 100644 --- a/src/accounts/forms.py +++ b/src/accounts/forms.py @@ -1,5 +1,6 @@ from django import forms from django.contrib.auth.models import User +from django.utils.translation import gettext_lazy as _ class UserBasicForm(forms.ModelForm): @@ -8,3 +9,20 @@ class UserBasicForm(forms.ModelForm): model = User fields = ('first_name', 'last_name', 'email',) + +class OnboardingForm(forms.Form): + first_name = forms.CharField(label=_("First name"), max_length=150) + last_name = forms.CharField(label=_("Last name"), max_length=150) + email = forms.EmailField(label=_("External email")) + username = forms.CharField( + label=_("Username"), + max_length=150, + help_text=_("Auto-generated from first and last name") + ) + + def clean_username(self): + username = self.cleaned_data['username'] + if User.objects.filter(username=username).exists(): + raise forms.ValidationError(_("User with this username already exists.")) + return username +