From e0f3c0a165041478f50c67d71281ec144c3dcaf1 Mon Sep 17 00:00:00 2001 From: RISHI SINGHAL Date: Fri, 24 Nov 2023 20:59:12 -0500 Subject: [PATCH 1/2] Added curr_profile of user to the HTML code - needs further UI improvement --- application.py | 56 ++++++-------- service/history.py | 1 - templates/user_profile.html | 142 ++++++++++++++++++++---------------- 3 files changed, 104 insertions(+), 95 deletions(-) diff --git a/application.py b/application.py index 24666016..0f1ebd92 100644 --- a/application.py +++ b/application.py @@ -182,34 +182,25 @@ def user_profile(): Output: Value update in database and redirected to home login page """ if session.get('email'): + curr_profile = list(mongo.db.user.find({'email':session.get('email')})) + print(curr_profile) form = UserProfileForm() if form.validate_on_submit(): if request.method == 'POST': email = session.get('email') - weight = request.form.get('weight') - height = request.form.get('height') - goal = request.form.get('goal') - target_weight = request.form.get('target_weight') - temp = mongo.db.profile.find_one( - {'email': email}, - {'height', 'weight', 'goal', 'target_weight'}) - if temp is not None: - mongo.db.profile.update_one({'email': email}, { - '$set': { - 'weight': temp['weight'], - 'height': temp['height'], - 'goal': temp['goal'], - 'target_weight': temp['target_weight'] - } - }) - else: - mongo.db.profile.insert_one({ - 'email': email, - 'height': height, - 'weight': weight, - 'goal': goal, - 'target_weight': target_weight - }) + new_weight = request.form.get('weight') + new_height = request.form.get('height') + new_goal = request.form.get('goal') + new_target_weight = request.form.get('target_weight') + mongo.db.user.update_one({'email': email}, { + '$set': { + 'weight': new_weight, + 'height': new_height, + 'goal': new_goal, + 'target_weight': new_target_weight + } + }) + flash(f'User Profile Updated', 'success') return render_template('display_profile.html', @@ -217,7 +208,7 @@ def user_profile(): form=form) else: return redirect(url_for('login')) - return render_template('user_profile.html', status=True, form=form) + return render_template('user_profile.html', status=True, form=form, curr_profile=curr_profile) @app.route("/calories", methods=['GET', 'POST']) @@ -230,7 +221,7 @@ def calories(): Output: Value update in database and redirected to the home page """ get_session = session.get('email') - print(get_session) + # print(get_session) if get_session is not None: form = CalorieForm() if form.validate_on_submit(): @@ -265,7 +256,7 @@ def workout(): if form.validate_on_submit(): email = session.get('email') burnout = form.burnout.data - print(burnout) + # print(burnout) mongo.db.workout.insert_one({ 'date': form.date.data.strftime('%Y-%m-%d'), # Get the selected date from the form 'email': email, @@ -328,12 +319,12 @@ def history(): user_target_date = mongo.db.user.find({'email': email})[0]['target_date'] target_weight = mongo.db.user.find({'email': email})[0]['target_weight'] current_weight = mongo.db.user.find({'email': email})[0]['weight'] - print(current_weight, target_weight, type(user_start_date), datetime.today().strftime('%Y-%m-%d')) + # print(current_weight, target_weight, type(user_start_date), datetime.today().strftime('%Y-%m-%d')) # Find out the actual calories which user needed to burn/gain to achieve goal from the start day target_calories_to_burn = u.total_calories_to_burn( target_weight=int(target_weight), current_weight=int(current_weight)) - print(f'########## {target_calories_to_burn}') + # print(f'########## {target_calories_to_burn}') # Find out how many calories user has gained or burnt uptill now query = { @@ -381,7 +372,7 @@ def ajaxhistory(): # Output: date, email, calories, burnout # ########################## email = get_session = session.get('email') - print(email) + # print(email) if get_session is not None: if request.method == "POST": date = request.form.get('date') @@ -431,7 +422,7 @@ def friends(): for f in myFriends: myFriendsList.append(f['receiver']) - print(myFriends) + # print(myFriends) allUsers = list(mongo.db.user.find({}, {'name', 'email'})) pendingRequests = list( @@ -452,7 +443,7 @@ def friends(): for p in pendingApprovals: pendingApproves.append(p['sender']) - print(pendingApproves) + # print(pendingApproves) # print(pendingRequests) return render_template('friends.html', @@ -510,7 +501,6 @@ def send_email(): data = list( mongo.db.calories.find({'email': email}, {'date', 'email', 'calories'})) - print(data) table = [['Date', 'Email ID', 'Calories']] for a in data: tmp = [a['date'], a['email'], a['calories']] diff --git a/service/history.py b/service/history.py index 1cf9b8aa..5653c2fe 100644 --- a/service/history.py +++ b/service/history.py @@ -6,7 +6,6 @@ def get_calories_per_day_pipeline(days: int): end_date = datetime.today() bucket_boundaries = [(start_date + timedelta(days=i)).strftime('%Y-%m-%d') for i in range(days + 1)] - print(bucket_boundaries) date_range_filter = { '$match': { 'date': { diff --git a/templates/user_profile.html b/templates/user_profile.html index f8d1ea3a..52851662 100644 --- a/templates/user_profile.html +++ b/templates/user_profile.html @@ -1,68 +1,88 @@ {% extends "layout.html" %} {% block content %} - - +
+ +
-
- {{ form.hidden_tag() }} -
- User Profile +
+ + {{ form.hidden_tag() }} +
+ User Profile +
+ {{ form.height.label(class="form-control-label") }} (cms) + {% if form.height.errors %} + {{ form.height(class="form-control form-control-lg is-invalid") }} +
+ {% for error in form.height.errors %} + {{ error }} + {% endfor %} +
+ {% else %} + {{ form.height(class="form-control form-control-lg") }} + {% endif %} + + {{ form.weight.label(class="form-control-label") }} (kgs) + {% if form.weight.errors %} + {{ form.weight(class="form-control form-control-lg is-invalid") }} +
+ {% for error in form.weight.errors %} + {{ error }} + {% endfor %} +
+ {% else %} + {{ form.weight(class="form-control form-control-lg") }} + {% endif %} + + {{ form.goal.label(class="form-control-label") }} + {% if form.goal.errors %} + {{ form.goal(class="form-control form-control-lg is-invalid") }} +
+ {% for error in form.goal.errors %} + {{ error }} + {% endfor %} +
+ {% else %} + {{ form.goal(class="form-control form-control-lg") }} + {% endif %} + + {{ form.target_weight.label(class="form-control-label") }} (kgs) + {% if form.target_weight.errors %} + {{ form.target_weight(class="form-control form-control-lg is-invalid") }} +
+ {% for error in form.target_weight.errors %} + {{ error }} + {% endfor %} +
+ {% else %} + {{ form.target_weight(class="form-control form-control-lg") }} + {% endif %} + + + +
+
- - {{ form.height.label(class="form-control-label") }} (cms) - {% if form.height.errors %} - {{ form.height(class="form-control form-control-lg is-invalid") }} -
- {% for error in form.height.errors %} - {{ error }} - {% endfor %} -
- {% else %} - {{ form.height(class="form-control form-control-lg") }} - {% endif %} - {{ form.weight.label(class="form-control-label") }} (kgs) - {% if form.weight.errors %} - {{ form.weight(class="form-control form-control-lg is-invalid") }} -
- {% for error in form.weight.errors %} - {{ error }} - {% endfor %} -
- {% else %} - {{ form.weight(class="form-control form-control-lg") }} - {% endif %} - {{ form.goal.label(class="form-control-label") }} - {% if form.goal.errors %} - {{ form.goal(class="form-control form-control-lg is-invalid") }} -
- {% for error in form.goal.errors %} - {{ error }} - {% endfor %} -
- {% else %} - {{ form.goal(class="form-control form-control-lg") }} - {% endif %} - {{ form.target_weight.label(class="form-control-label") }} (kgs) - {% if form.target_weight.errors %} - {{ form.goal(class="form-control form-control-lg is-invalid") }} -
- {% for error in form.target_weight.errors %} - {{ error }} - {% endfor %} -
- {% else %} - {{ form.target_weight(class="form-control form-control-lg") }} - {% endif %} -
-
-
- {{ form.submit(class="btn btn-outline-info") }} -
- - + {{ form.submit(class="btn btn-outline-info") }} +
+ +
+
+ + + +
+
+ {% if curr_profile %} +
+

Your Current Profile

+

Height: {{ curr_profile[0]['height'] }} cms

+

Weight: {{ curr_profile[0]['weight'] }} kgs

+

Goal: {{ curr_profile[0]['goal'] }}

+

Target Weight: {{ curr_profile[0]['target_weight'] }} kgs

+
+ {% endif %}
-
- -{% endblock content %} \ No newline at end of file +{% endblock content %} From f9142a427b0912935a378f9aae1489c560964f70 Mon Sep 17 00:00:00 2001 From: RISHI SINGHAL Date: Fri, 24 Nov 2023 22:09:38 -0500 Subject: [PATCH 2/2] Added enrolled plans feature --- application.py | 53 ++++++++++++++++++++++++------------ templates/layout.html | 2 +- templates/new_dashboard.html | 16 ++++++++--- templates/plans.html | 22 +++++++++++++++ 4 files changed, 70 insertions(+), 23 deletions(-) create mode 100644 templates/plans.html diff --git a/application.py b/application.py index 0f1ebd92..7b082485 100644 --- a/application.py +++ b/application.py @@ -469,6 +469,14 @@ def bmi_calci(): return render_template("bmi_cal.html", bmi=bmi, bmi_category=bmi_category) +@app.route('/plans', methods=['GET', 'POST']) +def plans(): + + if(session.get('email')): + email = get_session = session.get('email') + enrolled_plans = list(mongo.db.plans.find({'Email': email})) + return render_template("plans.html",enrolled_plans=enrolled_plans) + @app.route('/chatbot', methods=['GET', 'POST']) def chatbot(): @@ -677,10 +685,11 @@ def yoga(): if form.validate_on_submit(): if request.method == 'POST': enroll = "yoga" - mongo.db.user.insert_one({'Email': email, 'Status': enroll}) + mongo.db.plans.insert_one({'Email': email, 'Status': enroll}) + enrolled_plans = list(mongo.db.plans.find({'Email':email})) flash(f' You have succesfully enrolled in our {enroll} plan!', 'success') - return render_template('new_dashboard.html', form=form) + return render_template('new_dashboard.html', form=form, enrolled_plans=enrolled_plans) # return redirect(url_for('dashboard')) else: return redirect(url_for('dashboard')) @@ -702,10 +711,11 @@ def swim(): if form.validate_on_submit(): if request.method == 'POST': enroll = "swimming" - mongo.db.user.insert_one({'Email': email, 'Status': enroll}) + mongo.db.plans.insert_one({'Email': email, 'Status': enroll}) + enrolled_plans = list(mongo.db.plans.find({'Email':email})) flash(f' You have succesfully enrolled in our {enroll} plan!', 'success') - return render_template('new_dashboard.html', form=form) + return render_template('new_dashboard.html', form=form, enrolled_plans=enrolled_plans) # return redirect(url_for('dashboard')) else: return redirect(url_for('dashboard')) @@ -727,10 +737,11 @@ def abbs(): if form.validate_on_submit(): if request.method == 'POST': enroll = "abbs" - mongo.db.user.insert_one({'Email': email, 'Status': enroll}) + mongo.db.plans.insert_one({'Email': email, 'Status': enroll}) + enrolled_plans = list(mongo.db.plans.find({'Email':email})) flash(f' You have succesfully enrolled in our {enroll} plan!', 'success') - return render_template('new_dashboard.html', form=form) + return render_template('new_dashboard.html', form=form, enrolled_plans=enrolled_plans) else: return redirect(url_for('dashboard')) return render_template('abbs.html', title='Abbs Smash!', form=form) @@ -751,10 +762,11 @@ def belly(): if form.validate_on_submit(): if request.method == 'POST': enroll = "belly" - mongo.db.user.insertOne({'Email': email, 'Status': enroll}) + mongo.db.plans.insert_one({'Email': email, 'Status': enroll}) + enrolled_plans = list(mongo.db.plans.find({'Email':email})) flash(f' You have succesfully enrolled in our {enroll} plan!', 'success') - return render_template('new_dashboard.html', form=form) + return render_template('new_dashboard.html', form=form, enrolled_plans=enrolled_plans) # return redirect(url_for('dashboard')) else: return redirect(url_for('dashboard')) @@ -776,10 +788,11 @@ def core(): if form.validate_on_submit(): if request.method == 'POST': enroll = "core" - mongo.db.user.insert_one({'Email': email, 'Status': enroll}) + mongo.db.plans.insert_one({'Email': email, 'Status': enroll}) + enrolled_plans = list(mongo.db.plans.find({'Email':email})) flash(f' You have succesfully enrolled in our {enroll} plan!', 'success') - return render_template('new_dashboard.html', form=form) + return render_template('new_dashboard.html', form=form, enrolled_plans=enrolled_plans) else: return redirect(url_for('dashboard')) return render_template('core.html', title='Core Conditioning', form=form) @@ -800,10 +813,11 @@ def gym(): if form.validate_on_submit(): if request.method == 'POST': enroll = "gym" - mongo.db.user.insert_one({'Email': email, 'Status': enroll}) + mongo.db.plans.insert_one({'Email': email, 'Status': enroll}) + enrolled_plans = list(mongo.db.plans.find({'Email':email})) flash(f' You have succesfully enrolled in our {enroll} plan!', 'success') - return render_template('new_dashboard.html', form=form) + return render_template('new_dashboard.html', form=form, enrolled_plans=enrolled_plans) # return redirect(url_for('dashboard')) else: return redirect(url_for('dashboard')) @@ -825,10 +839,11 @@ def walk(): if form.validate_on_submit(): if request.method == 'POST': enroll = "walk" - mongo.db.user.insert_one({'Email': email, 'Status': enroll}) + mongo.db.plans.insert_one({'Email': email, 'Status': enroll}) + enrolled_plans = list(mongo.db.plans.find({'Email':email})) flash(f' You have succesfully enrolled in our {enroll} plan!', 'success') - return render_template('new_dashboard.html', form=form) + return render_template('new_dashboard.html', form=form, enrolled_plans=enrolled_plans) # return redirect(url_for('dashboard')) else: return redirect(url_for('dashboard')) @@ -850,10 +865,11 @@ def dance(): if form.validate_on_submit(): if request.method == 'POST': enroll = "dance" - mongo.db.user.insert_one({'Email': email, 'Status': enroll}) + mongo.db.plans.insert_one({'Email': email, 'Status': enroll}) + enrolled_plans = list(mongo.db.plans.find({'Email':email})) flash(f' You have succesfully enrolled in our {enroll} plan!', 'success') - return render_template('new_dashboard.html', form=form) + return render_template('new_dashboard.html', form=form, enrolled_plans=enrolled_plans) # return redirect(url_for('dashboard')) else: return redirect(url_for('dashboard')) @@ -875,10 +891,11 @@ def hrx(): if form.validate_on_submit(): if request.method == 'POST': enroll = "hrx" - mongo.db.user.insert_one({'Email': email, 'Status': enroll}) + mongo.db.plans.insert_one({'Email': email, 'Status': enroll}) + enrolled_plans = list(mongo.db.plans.find({'Email':email})) flash(f' You have succesfully enrolled in our {enroll} plan!', 'success') - return render_template('new_dashboard.html', form=form) + return render_template('new_dashboard.html', form=form, enrolled_plans=enrolled_plans) # return redirect(url_for('dashboard')) else: return redirect(url_for('dashboard')) diff --git a/templates/layout.html b/templates/layout.html index e40ee231..264e07e4 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -41,7 +41,7 @@ Burnout FitnessBot BMI Calculator - + Enrolled Plans Friends Profile diff --git a/templates/new_dashboard.html b/templates/new_dashboard.html index f4defa9a..510436f7 100644 --- a/templates/new_dashboard.html +++ b/templates/new_dashboard.html @@ -4,11 +4,19 @@
Your Activities
-

-


+

Enrolled Plans

+

+ {% set unique_plans = [] %} + {% for plan in enrolled_plans %} + {% if plan['Status'] not in unique_plans %} + {{ plan['Status'] }}
+ {% set _ = unique_plans.append(plan['Status']) %} + {% endif %} + {% endfor %} +

+

- -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/templates/plans.html b/templates/plans.html new file mode 100644 index 00000000..510436f7 --- /dev/null +++ b/templates/plans.html @@ -0,0 +1,22 @@ +{% extends "layout.html" %} +{% block content %} + +
+
Your Activities
+
+

Enrolled Plans

+

+ {% set unique_plans = [] %} + {% for plan in enrolled_plans %} + {% if plan['Status'] not in unique_plans %} + {{ plan['Status'] }}
+ {% set _ = unique_plans.append(plan['Status']) %} + {% endif %} + {% endfor %} +

+
+

+
+
+ +{% endblock %}