-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforms.py
More file actions
144 lines (114 loc) · 3.69 KB
/
forms.py
File metadata and controls
144 lines (114 loc) · 3.69 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
from flask_wtf import FlaskForm
from flask_wtf.file import FileField, FileAllowed # , FileRequired
from wtforms import StringField, PasswordField, TextAreaField, SelectField, IntegerField, TelField, BooleanField # , SelectMultipleField, widgets
from wtforms.validators import InputRequired, Email, Length, Optional, NumberRange, Disabled, ValidationError, Regexp
class CSRFProtection(FlaskForm):
"""CSRFProtection form, intentionally has no fields."""
class UserAddForm(FlaskForm):
"""Form for adding users."""
username = StringField(
'Username',
validators=[InputRequired(), Length(max=16)],
)
password = PasswordField(
'Password',
validators=[InputRequired(), Length(min=6, max=50)],
)
email = StringField(
'E-mail',
validators=[InputRequired(), Email(), Length(max=50)],
)
first_name = StringField(
'First Name',
validators=[InputRequired(), Length(max=25)]
)
last_name = StringField(
'Last Name',
validators=[InputRequired(), Length(max=25)]
)
# TODO: Check geo-coding libraries to see what form is required
zipcode = StringField(
'Zip Code',
validators=[Optional(),
Length(max=10),
Regexp(regex='^[+-]?[0-9]',
message="Invalid zip-code")]
)
# TODO: check if there is a Phone Number WTF validator
phone_number = TelField(
'Phone Number',
validators=[
InputRequired(),
Length(max=10),
Regexp(regex='^[+-]?[0-9]',
message="Invalid phone number")
]
)
# TODO: FS-A add option for phone number and email login
class LoginForm(FlaskForm):
"""Login form."""
username = StringField(
'Username',
validators=[InputRequired(), Length(max=16)],
)
password = PasswordField(
'Password',
validators=[InputRequired(), Length(min=6, max=50)],
)
class DeleteForm(FlaskForm):
"""Delete form."""
username = StringField(
'Username',
validators=[InputRequired(), Length(max=16)],
)
password = PasswordField(
'Password',
validators=[InputRequired(), Length(min=6, max=50)],
)
confirm = BooleanField(
'Are you sure you want to delete your account?',
validators=[InputRequired()]
)
def validate_confirm(self, field):
if not field.data:
raise ValidationError(
'You must check the confirmation box to delete your account.')
#TODO: Currently only one hobby and interest can be selected
class UserEditForm(FlaskForm):
"""Form for editing users."""
username = StringField(
'Username',
validators=[Disabled(), Optional()]
)
profile_photo = FileField(
'Profile Image (Optional)',
validators=[
Optional(),
FileAllowed(["jpg", "png", "jpeg"], 'Images only (.png, .jpeg, .jpg)')]
)
bio = TextAreaField(
'Tell us about yourself (Optional)',
validators=[Optional(), Length(max=140)]
)
zipcode = StringField(
'Zip Code',
validators=[Optional(), Length(max=10)]
)
friend_radius = IntegerField(
'Friend Radius',
validators=[InputRequired(), NumberRange(min=1, max=100)]
)
interest = SelectField(
'Interest',
validators=[Optional()]
)
# widget = widgets.ListWidget(prefix_label=False),
# option_widget = widgets.CheckboxInput()
hobby = SelectField(
'Hobby',
validators=[Optional()]
)
password = PasswordField(
'Password',
validators=[InputRequired(), Length(min=6, max=50)],
)