diff options
| author | stilbruch <stilbruch@protonmail.com> | 2022-05-09 00:25:31 -0500 |
|---|---|---|
| committer | stilbruch <stilbruch@protonmail.com> | 2022-05-09 00:25:31 -0500 |
| commit | 0cce988f119b80fd69b9a415c9e9b983325a12af (patch) | |
| tree | a1ff33b817b28fc64065cc3396a42750f6ef9a45 /app/routes | |
| parent | 3fd02681d178298551b0f8f3bba93964be30d4ca (diff) | |
| download | Strengthy-0cce988f119b80fd69b9a415c9e9b983325a12af.tar.xz Strengthy-0cce988f119b80fd69b9a415c9e9b983325a12af.zip | |
Improve history page
Diffstat (limited to 'app/routes')
| -rw-r--r-- | app/routes/workout.py | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/app/routes/workout.py b/app/routes/workout.py index 8f58aa3..767603e 100644 --- a/app/routes/workout.py +++ b/app/routes/workout.py @@ -144,11 +144,35 @@ def workout_record(workout_id=None): @app.route("/workout/history/<record_id>") @login_required def workout_history(record_id=None): - record = WorkoutRecord.query.filter_by( - id=int(record_id), user_id=current_user.id - ).first() - - if not record: + query = ( + db.session.query(SetRecord) + .join(WorkoutRecord) + .filter( + WorkoutRecord.id == SetRecord.workout_record_id, + WorkoutRecord.user_id == current_user.id, + WorkoutRecord.id == record_id, + ) + .order_by(SetRecord.exercise_id) + .all() + ) + if not query: return redirect(url_for("home")) - return render_template("workout/history.html", record=record) + # Condense into format we want + # TODO: this should be handled by an ExerciseRecord class, but I don't have time for it + exercises = {} + for set in query: + if set.exercise_id in exercises: + exercises[set.exercise_id]["sets"].append(set) + else: + exercises[set.exercise_id] = { + "sets": [set], + "name": set.exercise.name, + "id": int(set.exercise.id), + } + + return render_template( + "workout/history.html", + exercises=exercises.values(), + workout_record=query[0].workout_record, + ) |
