-
Notifications
You must be signed in to change notification settings - Fork 139
/
Copy pathsignup_form.py
65 lines (51 loc) · 1.73 KB
/
signup_form.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from django import forms
from viewflow.forms import Layout, Row, FormSetField, Caption, FormSet
from . import Form
class EmailForm(Form):
email = forms.EmailField()
description = forms.CharField()
class BaseEmailFormset(forms.BaseFormSet):
def clean(self):
if any(self.errors):
return
emails = []
for form in self.forms:
email = form.cleaned_data.get("email")
if not email:
continue
if email in emails:
raise forms.ValidationError("Emails should be distinct.")
emails.append(email)
EmailFormSet = forms.formset_factory(
EmailForm, extra=3, can_delete=True, formset=BaseEmailFormset
)
class AddressForm(Form):
line_1 = forms.CharField(max_length=250)
line_2 = forms.CharField(max_length=250)
state = forms.CharField(max_length=100)
city = forms.CharField(max_length=100)
zipcode = forms.CharField(max_length=10)
layout = Layout(
Caption("Address"),
"line_1",
"line_2",
"state",
Row("city", "zipcode"),
)
AddressFormSet = forms.formset_factory(AddressForm, extra=3, can_delete=True)
class SignupForm(Form):
username = forms.CharField(
max_length=50,
widget=forms.TextInput(attrs={"leading-icon": "account_box"}),
)
first_name = forms.CharField(max_length=250)
last_name = forms.CharField(max_length=250)
date_of_birth = forms.DateField()
emails = FormSetField(formset_class=EmailFormSet)
addresses = FormSetField(formset_class=AddressFormSet)
layout = Layout(
"username",
Row("first_name", "last_name", "date_of_birth"),
"emails",
FormSet("addresses", card_desktop=4),
)