-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathforms.py
79 lines (67 loc) · 2.66 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
75
76
77
78
79
from flask_wtf import FlaskForm as Form
from wtforms import StringField, PasswordField, SubmitField, BooleanField, TextField, TextAreaField, FileField, IntegerField, HiddenField, SelectField
from wtforms.validators import DataRequired, Length, Email, EqualTo, Regexp, ValidationError, NumberRange
from models import User, Recipe, Review
#images = UploadSet('images', IMAGES)
class UserForm(Form):
id = IntegerField()
full_name = TextField("Your Full Name")
avatar = StringField()
city = TextField()
submit = SubmitField('Delete Profile')
submit = SubmitField('Edit Profile')
class RecipeForm(Form):
id = HiddenField()
name = TextField("Recipe Name")
# image = FileField('image', validators=[
# FileRequired(),
# FileAllowed(images, 'Images only!')
# ])
image = StringField("url for image")
description = TextAreaField("Recipe Description")
ingredients = TextAreaField("Recipe Ingredients")
instructions = TextAreaField("Recipe Instructions")
submit = SubmitField('Create Recipe')
class ReviewForm(Form):
id = HiddenField()
rating = SelectField(u"Recipe Rating ", choices=[('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5')])
comment = TextAreaField("Review of Recipe")
submit = SubmitField('Create Review')
def name_exists(form, field):
if User.select().where(User.username == field.data).exists():
raise ValidationError('User with that name already exists.')
def email_exists(form, field):
if User.select().where(User.email == field.data).exists():
raise ValidationError('User with that email already exists.')
class RegistrationForm(Form):
full_name = StringField("Your full name", validators=[DataRequired()])
avatar = StringField("Your avatar")
city = StringField("Your city", validators=[DataRequired()])
username = StringField(
'Username',
validators=[
DataRequired(),
#name_exists calls the above method to make sure user doesn't already exist
name_exists
])
email = StringField(
'Email',
validators=[
DataRequired(),
Email(),
email_exists
])
password = PasswordField(
'Password',
validators=[
DataRequired(),
Length(min=3),
EqualTo('confirm_password', message='Passwords must match')
])
confirm_password = PasswordField(
'Confirm password',
validators=[DataRequired()]
)
class LoginForm(Form):
email = StringField('Email', validators=[DataRequired(), Email()])
password = PasswordField('Password', validators=[DataRequired()])