diff --git a/application.py b/application.py index beb0d5dc..19086bb9 100644 --- a/application.py +++ b/application.py @@ -11,7 +11,7 @@ from flask_mail import Mail from flask_pymongo import PyMongo from tabulate import tabulate -from forms import HistoryForm, RegistrationForm, LoginForm, CalorieForm, UserProfileForm, EnrollForm +from forms import HistoryForm, RegistrationForm, LoginForm, CalorieForm, UserProfileForm, EnrollForm,WorkoutForm app = Flask(__name__) app.secret_key = 'secret' @@ -155,7 +155,30 @@ def calories(): return redirect(url_for('home')) return render_template('calories.html', form=form, time=now) +@app.route("/workout", methods=['GET', 'POST']) +def workout(): + now = datetime.now() + now = now.strftime('%Y-%m-%d') + get_session = session.get('email') + + if get_session is not None: + form = WorkoutForm() + if form.validate_on_submit(): + if request.method == 'POST': + email = session.get('email') + burn = request.form.get('burnout') + + + mongo.db.calories.insert_one({'date': now, 'email': email, 'calories': -int(burn)}) + + flash(f'Successfully updated the data', 'success') + return redirect(url_for('workout')) + else: + return redirect(url_for('home')) + return render_template('workout.html', form=form, time=now) + +# print(intake) @app.route("/user_profile", methods=['GET', 'POST']) def user_profile(): """ @@ -208,7 +231,21 @@ def history(): email = get_session = session.get('email') if get_session is not None: form = HistoryForm() - return render_template('history.html', form=form) + + data=[ + ("01-01-2020",100), + ("02-01-2020",101), + ("03-01-2020",102) + ] + + # labels=[row[0] for row in data] + # values=[row[1] for row in data] + labels=[] + values=[] + for row in data: + labels.append(row[0]) + values.append(row[1]) + return render_template('history.html', form=form,labels=labels,values=values) @app.route("/ajaxhistory", methods=['POST']) diff --git a/forms.py b/forms.py index 4ad38077..94890852 100644 --- a/forms.py +++ b/forms.py @@ -34,6 +34,26 @@ class LoginForm(FlaskForm): 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() diff --git a/templates/calories.html b/templates/calories.html index 5412007b..eb8d8041 100644 --- a/templates/calories.html +++ b/templates/calories.html @@ -1,7 +1,7 @@ {% extends "layout.html" %} {% block content %}