forked from deekay2310/calorieApp_server
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathforms.py
150 lines (123 loc) · 4.64 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
"""
Copyright (c) 2023 Rajat Chandak, Shubham Saboo, Vibhav Deo, Chinmay Nayak
This code is licensed under MIT license (see LICENSE for details)
@author: Burnout
This python file is used in and is part of the Burnout project.
For more information about the Burnout project, visit:
https://github.com/VibhavDeo/FitnessApp
"""
# from datetime import date
# from re import sub
# from flask import app
"""Importing modules to create forms"""
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):
"""Form to collect the registration data of the user"""
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)])
goal = StringField(
'Goal (Weight Loss/ Muscle Gain)', validators=[
DataRequired(), Length(
min=2, max=20)])
target_weight = StringField(
'Target Weight', validators=[
DataRequired(), Length(
min=2, max=20)])
submit = SubmitField('Sign Up')
def validate_email(self, email):
"""Function to validate the entered 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):
"""Login form to log in to the application"""
email = StringField('Email',
validators=[DataRequired(), Email()])
password = PasswordField('Password', validators=[DataRequired()])
remember = BooleanField('Remember Me')
submit = SubmitField('Login')
class CalorieForm(FlaskForm):
"""Form to rcord the calorie intake details of the user"""
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 UserProfileForm(FlaskForm):
"""Form to input user details to store their height, weight, goal and target weight"""
weight = StringField(
'Weight', validators=[
DataRequired(), Length(
min=2, max=20)])
height = StringField(
'Height', validators=[
DataRequired(), Length(
min=2, max=20)])
goal = StringField(
'Goal (Weight Loss/ Muscle Gain)', validators=[
DataRequired(), Length(
min=2, max=20)])
target_weight = StringField(
'Target Weight', validators=[
DataRequired(), Length(
min=2, max=20)])
submit = SubmitField('Update')
class HistoryForm(FlaskForm):
"""Form to input the date for which the history needs to be displayed"""
app = App()
mongo = app.mongo
date = DateField()
submit = SubmitField('Fetch')
class EnrollForm(FlaskForm):
"""Form to enroll into a particular exercise/event"""
app = App()
mongo = app.mongo
submit = SubmitField('Enroll')
class ResetPasswordForm(FlaskForm):
"""Form to reset the account password"""
password = PasswordField('Password', validators=[DataRequired()])
confirm_password = PasswordField(
'Confirm Password', validators=[
DataRequired(), EqualTo('password')])
submit = SubmitField('Reset')
class ReviewForm(FlaskForm):
"""Form to input the different reviews about the application"""
review = StringField(
'Review', validators=[
DataRequired(), Length(
min=2, max=200)])
name = StringField(
'Name', validators=[
DataRequired(), Length(
min=2, max=200)])
submit = SubmitField('Submit')