summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstilbruch <stilbruch@protonmail.com>2022-04-30 12:56:15 -0500
committerstilbruch <stilbruch@protonmail.com>2022-04-30 12:56:15 -0500
commit11ca7472f0736ed7f7cc4447f8fa59cd8765eb2f (patch)
tree0d8a360753d97077171d087fac131b5e50c6906b
parent509a7bd8955138b2ff864dd75059d397b3fbb31e (diff)
downloadStrengthy-11ca7472f0736ed7f7cc4447f8fa59cd8765eb2f.tar.xz
Strengthy-11ca7472f0736ed7f7cc4447f8fa59cd8765eb2f.zip
Start workout history page
-rw-r--r--TODO1
-rw-r--r--app/routes/workout.py16
-rw-r--r--app/tables/user.py1
-rw-r--r--app/tables/workout.py3
-rw-r--r--app/templates/home.html12
-rw-r--r--app/templates/workout/history.html32
6 files changed, 58 insertions, 7 deletions
diff --git a/TODO b/TODO
deleted file mode 100644
index f81209d..0000000
--- a/TODO
+++ /dev/null
@@ -1 +0,0 @@
-Add fa icons to base
diff --git a/app/routes/workout.py b/app/routes/workout.py
index 996105c..9b46694 100644
--- a/app/routes/workout.py
+++ b/app/routes/workout.py
@@ -145,3 +145,19 @@ def workout_record():
@login_required
def workout_select():
return render_template("workout/select.html")
+
+
+@app.route("/workout/history", methods=["GET"])
+@login_required
+def workout_history():
+ if "id" not in request.args:
+ return redirect(url_for("home"))
+
+ # Matching workout record required
+ record = WorkoutRecord.query.filter_by(
+ id=int(request.args["id"]), user_id=current_user.id
+ ).first()
+ if not record:
+ return redirect(url_for("home"))
+
+ return render_template("workout/history.html", record=record)
diff --git a/app/tables/user.py b/app/tables/user.py
index 483e56f..00457e6 100644
--- a/app/tables/user.py
+++ b/app/tables/user.py
@@ -19,6 +19,7 @@ class User(db.Model, UserMixin):
# relationships
workouts = db.relationship("Workout", backref="user", lazy="dynamic")
+ records = db.relationship("WorkoutRecord", backref="user", lazy="dynamic")
def __init__(self, username, password, email):
self.username = username
diff --git a/app/tables/workout.py b/app/tables/workout.py
index cc8478e..bdb200e 100644
--- a/app/tables/workout.py
+++ b/app/tables/workout.py
@@ -1,4 +1,5 @@
from app import db, login_manager
+from flask_login import current_user
import enum
@@ -84,6 +85,7 @@ class WorkoutRecord(db.Model):
finished = db.Column(db.DateTime)
# foreign keys
+ user_id = db.Column(db.Integer, db.ForeignKey("users.id"))
workout_id = db.Column(db.Integer, db.ForeignKey("workouts.id"))
# relationships
@@ -92,3 +94,4 @@ class WorkoutRecord(db.Model):
def __init__(self, workout, finished):
self.workout = workout
self.finished = finished
+ self.user = current_user
diff --git a/app/templates/home.html b/app/templates/home.html
index 796b44b..235e6e7 100644
--- a/app/templates/home.html
+++ b/app/templates/home.html
@@ -19,20 +19,20 @@
<div class="tile is-ancestor has-text-centered">
<div class="tile is-parent">
<article class="tile is-child box">
- <p class="title has-text-black">0</p>
- <p class="subtitle has-text-black">Sets Completed</p>
+ <p class="title has-text-black">{{ current_user.workouts.count() }}</p>
+ <p class="subtitle has-text-black">Workouts</p>
</article>
</div>
<div class="tile is-parent">
<article class="tile is-child box">
- <p class="title has-text-black">0</p>
+ <p class="title has-text-black">{{ records.count() }}</p>
<p class="subtitle has-text-black">Workouts Completed</p>
</article>
</div>
<div class="tile is-parent">
<article class="tile is-child box">
- <p class="title has-text-black">{{ current_user.workouts.count() }}</p>
- <p class="subtitle has-text-black">Workouts</p>
+ <p class="title has-text-black">0</p>
+ <p class="subtitle has-text-black">Sets Completed</p>
</article>
</div>
<!-- Something else?
@@ -109,7 +109,7 @@
<tr>
<td>{{ record.workout.name }}</td>
<td>{{ record.finished.strftime("%m/%d/%y %-I:%M %p") }}</td>
- <td class="level-right"><a class="button is-small is-primary" href="#">View</a></td>
+ <td class="level-right"><a class="button is-small is-primary" href="/workout/history?id={{ record.id }}">View</a></td>
</tr>
{% endfor %}
</tbody>
diff --git a/app/templates/workout/history.html b/app/templates/workout/history.html
new file mode 100644
index 0000000..009deb0
--- /dev/null
+++ b/app/templates/workout/history.html
@@ -0,0 +1,32 @@
+{% extends 'base/layout.html' %}
+
+{% block title %}Workout{% endblock %}
+
+{% block content %}
+<div class="container">
+ <div class="columns is-centered">
+ <div class="column">
+ <h1 class="title is-2">Workout</h1>
+ <div class="box">
+ <table class="table is-fullwidth is-hoverable">
+ <thead>
+ <th>Set</th>
+ <th>lbs</th>
+ <th>Reps</th>
+ <th>Done</th>
+ </thead>
+ <tbody>
+ {% for set in record.sets %}
+ <tr>
+ <th></th>
+ <th>{{ set.lbs }}</th>
+ <th>{{ set.reps }}</th>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ </div>
+ </div>
+ </div>
+</div>
+{% endblock %}