feat: Refactor workout functionality into blueprint

- Moved workout-related routes (create/delete/edit workouts, topsets, tags, start dates, show workout) from `app.py` into a new blueprint at `routes/workout.py`.
- Integrated workout view model logic from `features/workout.py` directly into `routes/workout.py` helper function `_get_workout_view_model`.
- Removed `features/workout.py` and the corresponding class instantiation in `db.py`.
- Registered the new `workout_bp` blueprint in `app.py`.
- Removed the original workout route definitions from `app.py`.
- Updated `url_for` calls in relevant templates (`workout.html`, `person_overview.html`, `partials/workout_tags.html`, `partials/topset.html`, `partials/start_date.html`, `partials/new_set_form.html`, `notes.html`, `calendar.html`) to reference the new blueprint endpoints (e.g., `workout.create_workout`).
- Updated `templates/changelog/changelog.html` to document this refactoring.
This commit is contained in:
Peter Stockings
2025-03-31 22:38:48 +11:00
parent 78436b230b
commit eaeb4ab2c8
13 changed files with 276 additions and 242 deletions

135
app.py
View File

@@ -9,6 +9,7 @@ from routes.auth import auth, get_person_by_id
from routes.changelog import changelog_bp
from routes.calendar import calendar_bp # Import the new calendar blueprint
from routes.notes import notes_bp # Import the new notes blueprint
from routes.workout import workout_bp # Import the new workout blueprint
from extensions import db
from utils import convert_str_to_date, generate_plot
from flask_htmx import HTMX
@@ -38,6 +39,7 @@ app.register_blueprint(auth, url_prefix='/auth')
app.register_blueprint(changelog_bp, url_prefix='/changelog')
app.register_blueprint(calendar_bp) # Register the calendar blueprint
app.register_blueprint(notes_bp) # Register the notes blueprint
app.register_blueprint(workout_bp) # Register the workout blueprint
@app.after_request
def response_minify(response):
@@ -131,99 +133,6 @@ def person_overview(person_id):
return render_template('person_overview.html', **render_args), 200, {"HX-Push-Url": url_for('person_overview', person_id=person_id, min_date=min_date, max_date=max_date, exercise_id=selected_exercise_ids), "HX-Trigger": "refreshStats"}
# Route moved to routes/notes.py
@ app.route("/person/<int:person_id>/workout", methods=['POST'])
def create_workout(person_id):
new_workout_id = db.create_workout(person_id)
workout = db.get_workout(person_id, new_workout_id)
(person_tags, workout_tags, selected_workout_tag_ids) = db.get_workout_tags(
person_id, new_workout_id)
view_model = db.workout.get(person_id, new_workout_id)
return render_block(app.jinja_env, 'workout.html', 'content', **view_model)
@ app.route("/person/<int:person_id>/workout/<int:workout_id>/delete", methods=['GET'])
@ validate_workout
def delete_workout(person_id, workout_id):
db.delete_workout(workout_id)
return redirect(url_for('calendar.get_calendar', person_id=person_id))
#return "", 200, {"HX-Trigger": "updatedPeople", "HX-Push-Url": url_for('calendar.get_calendar', person_id=person_id)}
@ app.route("/person/<int:person_id>/workout/<int:workout_id>/start_date_edit_form", methods=['GET'])
@ validate_workout
def get_workout_start_date_edit_form(person_id, workout_id):
workout = db.get_workout(person_id, workout_id)
return render_template('partials/start_date.html', person_id=person_id, workout_id=workout_id, start_date=workout['start_date'], is_edit=True)
@ app.route("/person/<int:person_id>/workout/<int:workout_id>/start_date", methods=['PUT'])
@ validate_workout
def update_workout_start_date(person_id, workout_id):
new_start_date = request.form.get('start-date')
db.update_workout_start_date(workout_id, new_start_date)
return render_template('partials/start_date.html', person_id=person_id, workout_id=workout_id, start_date=convert_str_to_date(new_start_date, '%Y-%m-%d'))
@ app.route("/person/<int:person_id>/workout/<int:workout_id>/start_date", methods=['GET'])
@ validate_workout
def get_workout_start_date(person_id, workout_id):
workout = db.get_workout(person_id, workout_id)
return render_template('partials/start_date.html', person_id=person_id, workout_id=workout_id, start_date=workout['start_date'])
@ app.route("/person/<int:person_id>/workout/<int:workout_id>/topset/<int:topset_id>", methods=['GET'])
@ validate_topset
def get_topset(person_id, workout_id, topset_id):
topset = db.get_topset(topset_id)
return render_template('partials/topset.html', person_id=person_id, workout_id=workout_id, topset_id=topset_id, exercise_id=topset['exercise_id'], exercise_name=topset['exercise_name'], repetitions=topset['repetitions'], weight=topset['weight'])
@ app.route("/person/<int:person_id>/workout/<int:workout_id>/topset/<int:topset_id>/edit_form", methods=['GET'])
@ validate_topset
def get_topset_edit_form(person_id, workout_id, topset_id):
exercises = db.get_all_exercises()
topset = db.get_topset(topset_id)
return render_template('partials/topset.html', person_id=person_id, workout_id=workout_id, topset_id=topset_id, exercises=exercises, exercise_id=topset['exercise_id'], exercise_name=topset['exercise_name'], repetitions=topset['repetitions'], weight=topset['weight'], is_edit=True)
@ app.route("/person/<int:person_id>/workout/<int:workout_id>/topset", methods=['POST'])
@ validate_workout
def create_topset(person_id, workout_id):
exercise_id = request.form.get("exercise_id")
repetitions = request.form.get("repetitions")
weight = request.form.get("weight")
new_topset_id = db.create_topset(
workout_id, exercise_id, repetitions, weight)
exercise = db.get_exercise(exercise_id)
return render_template('partials/topset.html', person_id=person_id, workout_id=workout_id, topset_id=new_topset_id, exercise_id=exercise_id, exercise_name=exercise['name'], repetitions=repetitions, weight=weight), 200, {"HX-Trigger": "topsetAdded"}
@ app.route("/person/<int:person_id>/workout/<int:workout_id>/topset/<int:topset_id>", methods=['PUT'])
@ validate_workout
def update_topset(person_id, workout_id, topset_id):
exercise_id = request.form.get("exercise_id")
repetitions = request.form.get("repetitions")
weight = request.form.get("weight")
db.update_topset(exercise_id, repetitions, weight, topset_id)
exercise = db.get_exercise(exercise_id)
return render_template('partials/topset.html', person_id=person_id, workout_id=workout_id, topset_id=topset_id, exercise_name=exercise['name'], repetitions=repetitions, weight=weight)
@ app.route("/person/<int:person_id>/workout/<int:workout_id>/topset/<int:topset_id>/delete", methods=['DELETE'])
@ validate_topset
def delete_topset(person_id, workout_id, topset_id):
db.delete_topset(topset_id)
return ""
@ app.route("/person", methods=['POST'])
def create_person():
name = request.form.get("name")
@@ -328,38 +237,6 @@ def delete_tag(tag_id):
db.delete_tag_for_dashboard(tag_id)
return redirect(url_for('dashboard') + tag_filter)
# Routes moved to routes/notes.py
@ app.route("/person/<int:person_id>/workout/<int:workout_id>/tag/add", methods=['POST'])
def add_tag_to_workout(person_id, workout_id):
tags_id = [int(i) for i in request.form.getlist('tag_id')]
tags = db.add_tag_for_workout(workout_id, tags_id)
return render_template('partials/workout_tags_list.html', tags=tags)
@ app.route("/person/<int:person_id>/workout/<int:workout_id>/tag/new", methods=['POST'])
def create_new_tag_for_workout(person_id, workout_id):
tag_name = request.form.get('tag_name')
workout_tags = db.create_tag_for_workout(person_id, workout_id, tag_name)
return render_template('partials/workout_tags_list.html', workout_tags=workout_tags)
@ app.route("/person/<int:person_id>/workout/<int:workout_id>/exercise/most_recent_topset_for_exercise", methods=['GET'])
def get_most_recent_topset_for_exercise(person_id, workout_id):
exercise_id = request.args.get('exercise_id', type=int)
exercises = db.get_all_exercises()
if not exercise_id:
return render_template('partials/new_set_form.html', person_id=person_id, workout_id=workout_id, exercises=exercises)
topset = db.get_most_recent_topset_for_exercise(person_id, exercise_id)
if not topset:
return render_template('partials/new_set_form.html', person_id=person_id, workout_id=workout_id, exercises=exercises, exercise_id=exercise_id)
(repetitions, weight, exercise_name) = topset
return render_template('partials/new_set_form.html', person_id=person_id, workout_id=workout_id, exercise_id=exercise_id, exercise_name=exercise_name, repetitions=repetitions, weight=weight)
@ app.route("/person/<int:person_id>/exercise/<int:exercise_id>/sparkline", methods=['GET'])
def get_exercise_progress_for_user(person_id, exercise_id):
min_date = convert_str_to_date(request.args.get(
@@ -399,14 +276,6 @@ def get_people_graphs():
return render_template('partials/people_graphs.html', graphs=graphs, refresh_url=request.full_path)
@ app.route("/person/<int:person_id>/workout/<int:workout_id>", methods=['GET'])
def show_workout(person_id, workout_id):
view_model = db.workout.get(person_id, workout_id)
if htmx:
return render_block(app.jinja_env, 'workout.html', 'content', **view_model)
return render_template('workout.html', **view_model)
@app.route("/exercises/get")
def get_exercises():
query = request.args.get('query')

2
db.py
View File

@@ -10,7 +10,6 @@ from features.exercises import Exercises
from features.people_graphs import PeopleGraphs
from features.person_overview import PersonOverview
from features.stats import Stats
from features.workout import Workout
from features.sql_explorer import SQLExplorer
from features.dashboard import Dashboard
from utils import get_exercise_graph_model
@@ -19,7 +18,6 @@ from utils import get_exercise_graph_model
class DataBase():
def __init__(self, app=None):
self.stats = Stats(self.execute)
self.workout = Workout(self.execute)
self.exercises = Exercises(self.execute)
self.sql_explorer = SQLExplorer(self.execute)
self.person_overview = PersonOverview(self.execute)

View File

@@ -1,88 +0,0 @@
from flask import jsonify
class Workout:
def __init__(self, db_connection_method):
self.execute = db_connection_method
def get(self, person_id, workout_id):
query = """
SELECT
w.workout_id,
w.person_id,
p.name AS person_name,
w.start_date,
w.note,
t.topset_id,
e.exercise_id,
e.name AS exercise_name,
t.repetitions,
t.weight,
tag.tag_id,
tag.name AS tag_name,
tag.filter as tag_filter,
CASE WHEN wt.workout_id IS NOT NULL THEN TRUE ELSE FALSE END AS is_selected
FROM
workout w
LEFT JOIN
person p ON w.person_id = p.person_id
LEFT JOIN
topset t ON w.workout_id = t.workout_id
LEFT JOIN
exercise e ON t.exercise_id = e.exercise_id
LEFT JOIN
workout_tag wt ON w.workout_id = wt.workout_id
LEFT JOIN
tag ON TRUE -- Join to get all tags
WHERE
w.person_id = %s
AND w.workout_id = %s
ORDER BY t.topset_id ASC;
"""
data = self.execute(query, [person_id, workout_id])
if not data:
return {"error": "Workout not found"}, 404
# Initialize workout dictionary
workout_data = {
"workout_id": data[0]["workout_id"],
"person_id": data[0]["person_id"],
"person_name": data[0]["person_name"],
"start_date": data[0]["start_date"],
"note": data[0]["note"],
"tags": [],
"top_sets": [],
}
# Initialize helpers for tracking unique tags and topsets
tag_set = set()
topsets_seen = set()
# Process each row and add tags and topsets to workout_data
for row in data:
# Add all unique tags with is_selected property
tag_id = row["tag_id"]
if tag_id and tag_id not in tag_set:
workout_data["tags"].append({
"tag_id": tag_id,
"tag_name": row["tag_name"],
"tag_filter": row["tag_filter"],
"person_id": person_id,
"is_selected": row["is_selected"]
})
tag_set.add(tag_id)
# Add unique topsets based on topset_id
topset_id = row["topset_id"]
if topset_id and topset_id not in topsets_seen:
workout_data["top_sets"].append({
"topset_id": topset_id,
"exercise_id": row["exercise_id"],
"exercise_name": row["exercise_name"],
"repetitions": row["repetitions"],
"weight": row["weight"]
})
topsets_seen.add(topset_id)
return workout_data

244
routes/workout.py Normal file
View File

@@ -0,0 +1,244 @@
from flask import Blueprint, render_template, redirect, url_for, request, current_app
from jinja2_fragments import render_block
from flask_htmx import HTMX
from extensions import db
from decorators import validate_workout, validate_topset
from utils import convert_str_to_date
from collections import defaultdict # Import defaultdict
workout_bp = Blueprint('workout', __name__)
htmx = HTMX()
# --- Database Helper Function (Moved from features/workout.py) ---
def _get_workout_view_model(person_id, workout_id):
"""Fetches and formats workout data for display."""
query = """
SELECT
w.workout_id,
w.person_id,
p.name AS person_name,
w.start_date,
w.note,
t.topset_id,
e.exercise_id,
e.name AS exercise_name,
t.repetitions,
t.weight,
tag.tag_id,
tag.name AS tag_name,
tag.filter as tag_filter,
-- Check if the tag is associated with *this specific workout*
EXISTS (
SELECT 1 FROM workout_tag wt_check
WHERE wt_check.workout_id = w.workout_id AND wt_check.tag_id = tag.tag_id
) AS is_selected
FROM
workout w
LEFT JOIN
person p ON w.person_id = p.person_id
LEFT JOIN
topset t ON w.workout_id = t.workout_id
LEFT JOIN
exercise e ON t.exercise_id = e.exercise_id
-- Cross Join with tags relevant to the person to get all possible tags
CROSS JOIN
tag
WHERE
w.person_id = %s AND w.workout_id = %s
-- Ensure we only get tags associated with the person or general tags (person_id IS NULL)
AND (tag.person_id = w.person_id OR tag.person_id IS NULL)
ORDER BY t.topset_id ASC, tag.name ASC;
"""
# Note: The original query had a potential issue joining tags.
# The revised query uses a CROSS JOIN with person-specific tags
# and then checks association using EXISTS for the 'is_selected' flag.
# This ensures all relevant tags for the person are listed,
# and correctly marks those applied to this workout.
data = db.execute(query, [person_id, workout_id])
if not data:
# If workout exists but has no topsets/tags, fetch basic info
basic_info = db.execute(
"""SELECT w.workout_id, w.person_id, p.name as person_name, w.start_date, w.note
FROM workout w JOIN person p ON w.person_id = p.person_id
WHERE w.person_id = %s AND w.workout_id = %s""",
[person_id, workout_id], one=True
)
if not basic_info:
return {"error": "Workout not found"}, 404 # Truly not found
# Workout exists but is empty
return {
"workout_id": basic_info["workout_id"],
"person_id": basic_info["person_id"],
"person_name": basic_info["person_name"],
"start_date": basic_info["start_date"],
"note": basic_info["note"],
"tags": [], # Fetch all person tags separately if needed
"top_sets": [],
}
# Initialize workout dictionary using the first row for base details
workout_data = {
"workout_id": data[0]["workout_id"],
"person_id": data[0]["person_id"],
"person_name": data[0]["person_name"],
"start_date": data[0]["start_date"],
"note": data[0]["note"],
"tags": [],
"top_sets": [],
}
# Use sets to track unique IDs efficiently
tag_ids_seen = set()
topset_ids_seen = set()
for row in data:
# Process Tags
tag_id = row.get("tag_id")
if tag_id is not None and tag_id not in tag_ids_seen:
workout_data["tags"].append({
"tag_id": tag_id,
"tag_name": row.get("tag_name"),
"tag_filter": row.get("tag_filter"),
"person_id": person_id, # Assuming tags are person-specific or global
"is_selected": row.get("is_selected", False)
})
tag_ids_seen.add(tag_id)
# Process Topsets
topset_id = row.get("topset_id")
if topset_id is not None and topset_id not in topset_ids_seen:
workout_data["top_sets"].append({
"topset_id": topset_id,
"exercise_id": row.get("exercise_id"),
"exercise_name": row.get("exercise_name"),
"repetitions": row.get("repetitions"),
"weight": row.get("weight")
})
topset_ids_seen.add(topset_id)
# Sort tags alphabetically by name for consistent display
workout_data["tags"].sort(key=lambda x: x.get('tag_name', ''))
return workout_data
# --- Routes ---
@workout_bp.route("/person/<int:person_id>/workout", methods=['POST'])
def create_workout(person_id):
new_workout_id = db.create_workout(person_id)
# Use the local helper function to get the view model
view_model = _get_workout_view_model(person_id, new_workout_id)
if "error" in view_model: # Handle case where workout creation might fail or is empty
# Decide on appropriate error handling, maybe redirect or show error message
return redirect(url_for('calendar.get_calendar', person_id=person_id))
return render_block(current_app.jinja_env, 'workout.html', 'content', **view_model)
@workout_bp.route("/person/<int:person_id>/workout/<int:workout_id>/delete", methods=['GET'])
@validate_workout
def delete_workout(person_id, workout_id):
db.delete_workout(workout_id)
return redirect(url_for('calendar.get_calendar', person_id=person_id))
@workout_bp.route("/person/<int:person_id>/workout/<int:workout_id>/start_date_edit_form", methods=['GET'])
@validate_workout
def get_workout_start_date_edit_form(person_id, workout_id):
# Fetch only the necessary data (start_date)
workout = db.execute("SELECT start_date FROM workout WHERE workout_id = %s", [workout_id], one=True)
start_date = workout.get('start_date') if workout else None
return render_template('partials/start_date.html', person_id=person_id, workout_id=workout_id, start_date=start_date, is_edit=True)
@workout_bp.route("/person/<int:person_id>/workout/<int:workout_id>/start_date", methods=['PUT'])
@validate_workout
def update_workout_start_date(person_id, workout_id):
new_start_date_str = request.form.get('start-date')
db.update_workout_start_date(workout_id, new_start_date_str)
# Convert string back to date for rendering the partial
new_start_date = convert_str_to_date(new_start_date_str, '%Y-%m-%d')
return render_template('partials/start_date.html', person_id=person_id, workout_id=workout_id, start_date=new_start_date)
@workout_bp.route("/person/<int:person_id>/workout/<int:workout_id>/start_date", methods=['GET'])
@validate_workout
def get_workout_start_date(person_id, workout_id):
# Fetch only the necessary data (start_date)
workout = db.execute("SELECT start_date FROM workout WHERE workout_id = %s", [workout_id], one=True)
start_date = workout.get('start_date') if workout else None
return render_template('partials/start_date.html', person_id=person_id, workout_id=workout_id, start_date=start_date)
@workout_bp.route("/person/<int:person_id>/workout/<int:workout_id>/topset/<int:topset_id>", methods=['GET'])
@validate_topset
def get_topset(person_id, workout_id, topset_id):
topset = db.get_topset(topset_id) # Keep using db.py for simple gets for now
return render_template('partials/topset.html', person_id=person_id, workout_id=workout_id, topset_id=topset_id, exercise_id=topset.get('exercise_id'), exercise_name=topset.get('exercise_name'), repetitions=topset.get('repetitions'), weight=topset.get('weight'))
@workout_bp.route("/person/<int:person_id>/workout/<int:workout_id>/topset/<int:topset_id>/edit_form", methods=['GET'])
@validate_topset
def get_topset_edit_form(person_id, workout_id, topset_id):
exercises = db.get_all_exercises()
topset = db.get_topset(topset_id)
return render_template('partials/topset.html', person_id=person_id, workout_id=workout_id, topset_id=topset_id, exercises=exercises, exercise_id=topset.get('exercise_id'), exercise_name=topset.get('exercise_name'), repetitions=topset.get('repetitions'), weight=topset.get('weight'), is_edit=True)
@workout_bp.route("/person/<int:person_id>/workout/<int:workout_id>/topset", methods=['POST'])
@validate_workout
def create_topset(person_id, workout_id):
exercise_id = request.form.get("exercise_id")
repetitions = request.form.get("repetitions")
weight = request.form.get("weight")
new_topset_id = db.create_topset(workout_id, exercise_id, repetitions, weight)
exercise = db.get_exercise(exercise_id)
return render_template('partials/topset.html', person_id=person_id, workout_id=workout_id, topset_id=new_topset_id, exercise_id=exercise_id, exercise_name=exercise.get('name'), repetitions=repetitions, weight=weight), 200, {"HX-Trigger": "topsetAdded"}
@workout_bp.route("/person/<int:person_id>/workout/<int:workout_id>/topset/<int:topset_id>", methods=['PUT'])
@validate_workout
def update_topset(person_id, workout_id, topset_id):
exercise_id = request.form.get("exercise_id")
repetitions = request.form.get("repetitions")
weight = request.form.get("weight")
db.update_topset(exercise_id, repetitions, weight, topset_id)
exercise = db.get_exercise(exercise_id)
return render_template('partials/topset.html', person_id=person_id, workout_id=workout_id, topset_id=topset_id, exercise_name=exercise.get('name'), repetitions=repetitions, weight=weight)
@workout_bp.route("/person/<int:person_id>/workout/<int:workout_id>/topset/<int:topset_id>/delete", methods=['DELETE'])
@validate_topset
def delete_topset(person_id, workout_id, topset_id):
db.delete_topset(topset_id)
return ""
@workout_bp.route("/person/<int:person_id>/workout/<int:workout_id>/tag/add", methods=['POST'])
def add_tag_to_workout(person_id, workout_id):
tags_id = [int(i) for i in request.form.getlist('tag_id')]
tags = db.add_tag_for_workout(workout_id, tags_id) # Keep using db.py for complex tag logic for now
return render_template('partials/workout_tags_list.html', tags=tags)
@workout_bp.route("/person/<int:person_id>/workout/<int:workout_id>/tag/new", methods=['POST'])
def create_new_tag_for_workout(person_id, workout_id):
tag_name = request.form.get('tag_name')
workout_tags = db.create_tag_for_workout(person_id, workout_id, tag_name) # Keep using db.py for complex tag logic for now
return render_template('partials/workout_tags_list.html', workout_tags=workout_tags)
@workout_bp.route("/person/<int:person_id>/workout/<int:workout_id>/exercise/most_recent_topset_for_exercise", methods=['GET'])
def get_most_recent_topset_for_exercise(person_id, workout_id):
exercise_id = request.args.get('exercise_id', type=int)
exercises = db.get_all_exercises()
if not exercise_id:
return render_template('partials/new_set_form.html', person_id=person_id, workout_id=workout_id, exercises=exercises)
topset = db.get_most_recent_topset_for_exercise(person_id, exercise_id) # Keep using db.py for now
if not topset:
return render_template('partials/new_set_form.html', person_id=person_id, workout_id=workout_id, exercises=exercises, exercise_id=exercise_id)
(repetitions, weight, exercise_name) = topset
return render_template('partials/new_set_form.html', person_id=person_id, workout_id=workout_id, exercise_id=exercise_id, exercise_name=exercise_name, repetitions=repetitions, weight=weight)
@workout_bp.route("/person/<int:person_id>/workout/<int:workout_id>", methods=['GET'])
def show_workout(person_id, workout_id):
# Use the local helper function to get the view model
view_model = _get_workout_view_model(person_id, workout_id)
if "error" in view_model:
# Decide on appropriate error handling
return redirect(url_for('calendar.get_calendar', person_id=person_id)) # Redirect to calendar on error
if htmx:
return render_block(current_app.jinja_env, 'workout.html', 'content', **view_model)
return render_template('workout.html', **view_model)

View File

@@ -95,7 +95,7 @@
</div>
{% for workout in day.workouts %}
<div class="bottom flex-grow py-1 w-full"
hx-get="{{ url_for('show_workout', person_id=person_id, workout_id=workout.workout_id) }}"
hx-get="{{ url_for('workout.show_workout', person_id=person_id, workout_id=workout.workout_id) }}"
hx-push-url="true" hx-target="#container">
{% for set in workout.sets %}
<button
@@ -141,7 +141,7 @@
{% for day in month.days %}
<div class="{% if day.is_today and day.is_in_current_month %}rounded-md border-4 border-green-50 border{% endif %} py-3 px-4 hover:bg-blue hover:text-white text-center cursor-pointer rounded-md {% if day.has_workouts and day.is_in_current_month %}bg-green-100{% endif %}"
{% if day.has_workouts %}
hx-get="{{ url_for('show_workout', person_id=person_id, workout_id=day.first_workout_id) }}"
hx-get="{{ url_for('workout.show_workout', person_id=person_id, workout_id=day.first_workout_id) }}"
hx-push-url="true" hx-target="#container" {% endif %}>
{% if day.is_in_current_month %}
{{ day.day }}
@@ -170,7 +170,7 @@
{% block add_workout_button %}
<button
class="fixed z-90 bottom-10 right-8 bg-blue-600 w-20 h-20 rounded-full drop-shadow-lg flex justify-center items-center text-white text-4xl hover:bg-blue-700 hover:drop-shadow-2xl hover:animate-bounce duration-300"
hx-post="{{ url_for('create_workout', person_id=person_id) }}" hx-push-url="true" hx-target="#container">
hx-post="{{ url_for('workout.create_workout', person_id=person_id) }}" hx-push-url="true" hx-target="#container">
<svg viewBox="0 0 20 20" enable-background="new 0 0 20 20" class="w-6 h-6 inline-block">
<path fill="#FFFFFF" d="M16,10c0,0.553-0.048,1-0.601,1H11v4.399C11,15.951,10.553,16,10,16c-0.553,0-1-0.049-1-0.601V11H4.601
C4.049,11,4,10.553,4,10c0-0.553,0.049-1,0.601-1H9V4.601C9,4.048,9.447,4,10,4c0.553,0,1,0.048,1,0.601V9h4.399

View File

@@ -10,6 +10,17 @@
<div class="prose max-w-none">
<p>Updates and changes to the site will be documented here, with the most recent changes listed first.</p>
<!-- New Entry for Workout Refactoring -->
<hr class="my-6">
<h2 class="text-xl font-semibold mb-2">March 31, 2025</h2>
<ul class="list-disc pl-5 space-y-1">
<li>Refactored workout functionality (create/delete/edit workouts, topsets, tags) into its own blueprint
(`routes/workout.py`).</li>
<li>Moved workout view model logic from `features/workout.py` into the `routes/workout.py` blueprint.
</li>
<li>Updated relevant `url_for` calls in templates to use the new `workout.` prefix.</li>
</ul>
<!-- New Entry for Calendar Year View Fix -->
<hr class="my-6">
<h2 class="text-xl font-semibold mb-2">March 31, 2025</h2>

View File

@@ -50,7 +50,7 @@
{% for workout_note in workout_notes %}
<tr class="border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted">
<td class="p-4 align-middle [&amp;:has([role=checkbox])]:pr-0 cursor-pointer"
hx-get="{{ url_for('show_workout', person_id=person_id, workout_id=workout_note.workout_id) }}"
hx-get="{{ url_for('workout.show_workout', person_id=person_id, workout_id=workout_note.workout_id) }}"
hx-push-url="true" hx-target="#container">
<div class="flex flex-row items-center justify-center">
<button
@@ -96,7 +96,7 @@
{% block add_workout_button %}
<button
class="fixed z-90 bottom-10 right-8 bg-blue-600 w-20 h-20 rounded-full drop-shadow-lg flex justify-center items-center text-white text-4xl hover:bg-blue-700 hover:drop-shadow-2xl hover:animate-bounce duration-300"
hx-post="{{ url_for('create_workout', person_id=person_id) }}" hx-push-url="true" hx-target="#container">
hx-post="{{ url_for('workout.create_workout', person_id=person_id) }}" hx-push-url="true" hx-target="#container">
<svg viewBox="0 0 20 20" enable-background="new 0 0 20 20" class="w-6 h-6 inline-block">
<path fill="#FFFFFF" d="M16,10c0,0.553-0.048,1-0.601,1H11v4.399C11,15.951,10.553,16,10,16c-0.553,0-1-0.049-1-0.601V11H4.601
C4.049,11,4,10.553,4,10c0-0.553,0.049-1,0.601-1H9V4.601C9,4.048,9.447,4,10,4c0.553,0,1,0.048,1,0.601V9h4.399

View File

@@ -1,5 +1,5 @@
<form class="w-full" id="new-set-workout-{{ workout_id }}"
hx-post="{{ url_for('create_topset', person_id=person_id, workout_id=workout_id) }}" hx-swap="beforeend"
hx-post="{{ url_for('workout.create_topset', person_id=person_id, workout_id=workout_id) }}" hx-swap="beforeend"
hx-target="#new-workout" _="on htmx:afterOnLoad if #no-workouts add .hidden to #no-workouts end
on topsetAdded
render #notification-template with (message: 'Topset added') then append it to #notifications-container
@@ -52,7 +52,7 @@
</form>
<div hx-trigger="exerciseSelected from:body"
hx-get="{{ url_for('get_most_recent_topset_for_exercise', person_id=person_id, workout_id=workout_id) }}"
hx-get="{{ url_for('workout.get_most_recent_topset_for_exercise', person_id=person_id, workout_id=workout_id) }}"
hx-target="#new-set-workout-{{ workout_id }}" hx-include="[name='exercise_id']">
</div>

View File

@@ -2,7 +2,7 @@
{% if is_edit|default(false, true) == false %}
<span class="text-base font-normal text-gray-500">{{ strftime(start_date, "%b %d %Y") }}</span>
<a class="text-sm font-medium text-cyan-600 hover:bg-gray-100 rounded-lg inline-flex items-center p-2 cursor-pointer"
hx-get="{{ url_for('get_workout_start_date_edit_form', person_id=person_id, workout_id=workout_id) }}"
hx-get="{{ url_for('workout.get_workout_start_date_edit_form', person_id=person_id, workout_id=workout_id) }}"
hx-target="#edit-start-date">
Edit
</a>
@@ -20,10 +20,10 @@
<input type="date"
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full pl-10 p-2.5 w-full"
name="start-date" value="{{ start_date }}"
hx-put="{{ url_for('update_workout_start_date', person_id=person_id, workout_id=workout_id) }}">
hx-put="{{ url_for('workout.update_workout_start_date', person_id=person_id, workout_id=workout_id) }}">
</div>
<a hx-get="{{ url_for('get_workout_start_date', person_id=person_id, workout_id=workout_id) }}"
<a hx-get="{{ url_for('workout.get_workout_start_date', person_id=person_id, workout_id=workout_id) }}"
hx-target="#edit-start-date"
class="text-sm font-medium text-cyan-600 hover:bg-gray-100 rounded-lg inline-flex items-center p-2 cursor-pointer">
Cancel

View File

@@ -45,7 +45,7 @@
{% if is_edit|default(false, true) == false %}
<button
class="inline-flex justify-center p-2 text-blue-600 rounded-full cursor-pointer hover:bg-blue-100 dark:text-blue-500 dark:hover:bg-gray-600"
hx-get="{{ url_for('get_topset_edit_form', person_id=person_id, workout_id=workout_id, topset_id=topset_id) }}">
hx-get="{{ url_for('workout.get_topset_edit_form', person_id=person_id, workout_id=workout_id, topset_id=topset_id) }}">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
stroke="currentColor" class="w-5 h-5">
<path stroke-linecap="round" stroke-linejoin="round"
@@ -55,7 +55,7 @@
</button>
<button
class="inline-flex justify-center p-2 text-blue-600 rounded-full cursor-pointer hover:bg-blue-100 dark:text-blue-500 dark:hover:bg-gray-600"
hx-delete="{{ url_for('delete_topset', person_id=person_id, workout_id=workout_id, topset_id=topset_id) }}"
hx-delete="{{ url_for('workout.delete_topset', person_id=person_id, workout_id=workout_id, topset_id=topset_id) }}"
hx-confirm="Are you sure you wish to delete this topset?">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
stroke="currentColor" class="w-5 h-5">
@@ -68,7 +68,7 @@
{% else %}
<button
class="inline-flex justify-center p-2 text-blue-600 rounded-full cursor-pointer hover:bg-blue-100 dark:text-blue-500 dark:hover:bg-gray-600"
hx-put="{{ url_for('update_topset', person_id=person_id, workout_id=workout_id, topset_id=topset_id) }}"
hx-put="{{ url_for('workout.update_topset', person_id=person_id, workout_id=workout_id, topset_id=topset_id) }}"
hx-include="#topset-{{ topset_id }} * [name='exercise_id'],#topset-{{ topset_id }} * [name='repetitions'],#topset-{{ topset_id }} * [name='weight']">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
@@ -80,7 +80,7 @@
<button
class="inline-flex justify-center p-2 text-blue-600 rounded-full cursor-pointer hover:bg-blue-100 dark:text-blue-500 dark:hover:bg-gray-600"
hx-get="{{ url_for('get_topset', person_id=person_id, workout_id=workout_id, topset_id=topset_id) }}">
hx-get="{{ url_for('workout.get_topset', person_id=person_id, workout_id=workout_id, topset_id=topset_id) }}">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
stroke="currentColor" class="w-5 h-5">
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />

View File

@@ -35,7 +35,7 @@
<div class="relative">
<div class="w-full">
<select multiple name="tag_id"
hx-post="{{ url_for('add_tag_to_workout', person_id=person_id, workout_id=workout_id) }}"
hx-post="{{ url_for('workout.add_tag_to_workout', person_id=person_id, workout_id=workout_id) }}"
hx-target="#tag-wrapper-w-{{ workout_id }}"
class="block appearance-none w-full bg-gray-200 border border-gray-200 text-gray-700 py-3 px-4 pr-8 rounded leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
_="init js(me)
@@ -66,7 +66,7 @@
type="text" name="tag_name">
<button type="submit"
hx-post="{{ url_for('create_new_tag_for_workout', person_id=person_id, workout_id=workout_id) }}"
hx-post="{{ url_for('workout.create_new_tag_for_workout', person_id=person_id, workout_id=workout_id) }}"
hx-include="[name='tag_name']" hx-target="#tag-wrapper-w-{{ workout_id }}"
class="p-2.5 ml-2 text-sm font-medium text-white bg-blue-700 rounded-lg border border-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"

View File

@@ -129,7 +129,7 @@
<tbody class="bg-white">
{% for workout in workouts %}
<tr hx-get="{{ url_for('show_workout', person_id=person_id, workout_id=workout.id) }}"
<tr hx-get="{{ url_for('workout.show_workout', person_id=person_id, workout_id=workout.id) }}"
hx-push-url="true" hx-target="#container" class="cursor-pointer">
<td class="p-4 whitespace-nowrap text-sm font-normal text-gray-500">
{{ workout.start_date | strftime("%b %d %Y") }}
@@ -175,7 +175,7 @@
{% block add_workout_button %}
<button
class="fixed z-90 bottom-10 right-8 bg-blue-600 w-20 h-20 rounded-full drop-shadow-lg flex justify-center items-center text-white text-4xl hover:bg-blue-700 hover:drop-shadow-2xl hover:animate-bounce duration-300"
hx-post="{{ url_for('create_workout', person_id=person_id) }}" hx-push-url="true" hx-target="#container">
hx-post="{{ url_for('workout.create_workout', person_id=person_id) }}" hx-push-url="true" hx-target="#container">
<svg viewBox="0 0 20 20" enable-background="new 0 0 20 20" class="w-6 h-6 inline-block">
<path fill="#FFFFFF" d="M16,10c0,0.553-0.048,1-0.601,1H11v4.399C11,15.951,10.553,16,10,16c-0.553,0-1-0.049-1-0.601V11H4.601
C4.049,11,4,10.553,4,10c0-0.553,0.049-1,0.601-1H9V4.601C9,4.048,9.447,4,10,4c0.553,0,1,0.048,1,0.601V9h4.399

View File

@@ -75,7 +75,7 @@
<button type="button"
class="absolute right-0 text-gray-400 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm p-1.5 ml-auto inline-flex items-center dark:hover:bg-gray-600 dark:hover:text-white mr-2"
hx-get="{{ url_for('delete_workout', person_id=person_id, workout_id=workout_id) }}"
hx-get="{{ url_for('workout.delete_workout', person_id=person_id, workout_id=workout_id) }}"
hx-confirm="Are you sure you wish to delete this workout?" hx-push-url="true"
hx-target="#container">
<svg aria-hidden="true" class="w-5 h-5" fill="currentColor" viewBox="0 0 20 20"