-
Notifications
You must be signed in to change notification settings - Fork 10
/
forms.py
126 lines (100 loc) · 3.92 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
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
from datetime import date
from re import sub
from flask import app
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, SubmitField, BooleanField
from wtforms.fields.core import DateField, SelectField
from wtforms.validators import DataRequired, Length, Email, EqualTo, ValidationError
from apps import App
class RegistrationForm(FlaskForm):
username = StringField('Username',
validators=[DataRequired(),
Length(min=2, max=20)])
email = StringField('Email', validators=[DataRequired(), Email()])
password = PasswordField('Password', validators=[DataRequired()])
confirm_password = PasswordField(
'Confirm Password', validators=[DataRequired(),
EqualTo('password')])
weight = StringField('Weight',
validators=[
DataRequired(),
Length(min=2, max=20),
])
height = StringField('Height',
validators=[DataRequired(),
Length(min=2, max=20)])
target_weight = StringField(
'Target Weight', validators=[DataRequired(),
Length(min=2, max=20)])
target_date = DateField(DataRequired())
submit = SubmitField('Sign Up')
def validate_email(self, email):
app_object = App()
mongo = app_object.mongo
temp = mongo.db.user.find_one({'email': email.data}, {'email', 'pwd'})
if temp:
raise ValidationError('Email already exists!')
class LoginForm(FlaskForm):
email = StringField('Email', validators=[DataRequired(), Email()])
password = PasswordField('Password', validators=[DataRequired()])
remember = BooleanField('Remember Me')
submit = SubmitField('Login')
class WorkoutForm(FlaskForm):
app = App()
mongo = app.mongo
# cursor = mongo.db.food.find()
# get_docs = []
# for record in cursor:
# get_docs.append(record)
# result = []
# temp = ""
# for i in get_docs:
# temp = i['food'] + ' (' + i['calories'] + ')'
# result.append((temp, temp))
# food = SelectField(
# 'Select Food', choices=result)
burnout = StringField('Burn Out', validators=[DataRequired()])
submit = SubmitField('Save')
class CalorieForm(FlaskForm):
app = App()
mongo = app.mongo
cursor = mongo.db.food.find()
get_docs = []
for record in cursor:
get_docs.append(record)
result = []
temp = ""
for i in get_docs:
temp = i['food'] + ' (' + i['calories'] + ')'
result.append((temp, temp))
food = SelectField('Select Food', choices=result)
submit = SubmitField('Save')
class UserProfileForm(FlaskForm):
weight = StringField('Weight',
validators=[DataRequired(),
Length(min=2, max=20)])
height = StringField('Height',
validators=[DataRequired(),
Length(min=2, max=20)])
goal = StringField('Goal',
validators=[DataRequired(),
Length(min=2, max=20)])
target_weight = StringField(
'Target Weight', validators=[DataRequired(),
Length(min=2, max=20)])
submit = SubmitField('Save Profile')
class HistoryForm(FlaskForm):
app = App()
mongo = app.mongo
date = DateField()
submit = SubmitField('Fetch')
class EnrollForm(FlaskForm):
app = App()
mongo = app.mongo
submit = SubmitField('Enroll')
class ResetPasswordForm(FlaskForm):
password = PasswordField('Password', validators=[DataRequired()])
confirm_password = PasswordField(
'Confirm Password', validators=[DataRequired(),
EqualTo('password')])
submit = SubmitField('Reset')