forked from celestekilgore/friender-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforms.py
74 lines (56 loc) · 1.85 KB
/
forms.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
66
67
68
69
70
71
72
73
74
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, IntegerField, TextAreaField, FileField, BooleanField
from wtforms.validators import InputRequired, Length, NumberRange, Optional, ValidationError, AnyOf
from flask_wtf.file import FileAllowed
from api import is_valid_zip_code
class LoginForm(FlaskForm):
"""Form for logging in a user."""
username = StringField(
"Username",
validators=[InputRequired()],
)
password = PasswordField(
"Password",
validators=[InputRequired()],
)
class RegisterForm(FlaskForm):
"""Form for registering new user."""
username = StringField(
"Username",
validators=[InputRequired(), Length(min=2, max=30)],
)
password = PasswordField(
"Password",
validators=[InputRequired(), Length(min=6, max=100)],
)
zip_code = StringField(
"Zip Code",
validators=[InputRequired(), Length(min=2, max=10)],
)
def validate_zip_code(self, field):
"""Takes zip code field and raises error if invalid."""
if field.data:
if not is_valid_zip_code(field.data):
raise ValidationError("Invalid")
friend_radius = IntegerField(
"Friend Radius",
validators=[InputRequired(), NumberRange(min=1, max=9999)],
)
hobbies = TextAreaField(
"Hobbies",
validators=[InputRequired(), Length(min=2, max=500)]
)
interests = TextAreaField(
"Interests",
validators=[InputRequired(), Length(min=2, max=500)]
)
image = FileField(
"Image",
validators=[Optional(), FileAllowed(['png', 'gif', 'jpg', 'jpeg'])]
)
class RelationshipForm(FlaskForm):
"""Form for establishing relationship."""
response = BooleanField(
"Response",
validators=[AnyOf([True, False])],
)