Default routine log reps from targets
This commit is contained in:
@@ -159,7 +159,7 @@ async def log_seeded_routine_workout(
|
||||
'performed_at': performed_at,
|
||||
'routine_name': routine_name.strip(),
|
||||
'notes': notes.strip() or None,
|
||||
'exercises': await _parse_structured_routine_form(request, exercise_count),
|
||||
'exercises': await _parse_structured_routine_form(request, routine, exercise_count),
|
||||
}
|
||||
request.app.state.store.add_workout(payload)
|
||||
return RedirectResponse(url='/', status_code=status.HTTP_303_SEE_OTHER)
|
||||
@@ -272,6 +272,7 @@ def _build_routine_log_sheet(routine: dict) -> list[dict]:
|
||||
'exercise_name': exercise['exercise_name'],
|
||||
'target_sets': target_sets,
|
||||
'target_reps': exercise.get('target_reps'),
|
||||
'default_reps': default_reps,
|
||||
'notes': exercise.get('notes'),
|
||||
'sets': [
|
||||
{
|
||||
@@ -328,8 +329,9 @@ def _routine_action_label(routine_name: str) -> str:
|
||||
return day_aliases.get(label, label)
|
||||
|
||||
|
||||
async def _parse_structured_routine_form(request: Request, exercise_count: int) -> list[dict]:
|
||||
async def _parse_structured_routine_form(request: Request, routine: dict, exercise_count: int) -> list[dict]:
|
||||
form = await request.form()
|
||||
routine_exercises = routine.get('exercises', [])
|
||||
exercises = []
|
||||
for exercise_index in range(exercise_count):
|
||||
exercise_name = str(form.get(f'exercise_{exercise_index}_name', '')).strip()
|
||||
@@ -339,12 +341,18 @@ async def _parse_structured_routine_form(request: Request, exercise_count: int)
|
||||
set_count = int(str(form.get(f'exercise_{exercise_index}_set_count', '0')).strip())
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=400, detail='Invalid set count in routine log form.') from exc
|
||||
target_reps = None
|
||||
if exercise_index < len(routine_exercises):
|
||||
target_reps = routine_exercises[exercise_index].get('target_reps')
|
||||
default_reps_raw = _default_reps_value(target_reps)
|
||||
sets = []
|
||||
for set_index in range(set_count):
|
||||
reps_raw = str(form.get(f'exercise_{exercise_index}_set_{set_index}_reps', '')).strip()
|
||||
weight_raw = str(form.get(f'exercise_{exercise_index}_set_{set_index}_weight_lbs', '')).strip()
|
||||
if not reps_raw and not weight_raw:
|
||||
continue
|
||||
if not reps_raw and weight_raw and default_reps_raw.isdigit():
|
||||
reps_raw = default_reps_raw
|
||||
if not reps_raw or not weight_raw:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
{% for exercise in routine_sheet %}
|
||||
<section class="evidence-slab">
|
||||
<input type="hidden" name="exercise_{{ exercise.exercise_index }}_set_count" value="{{ exercise.target_sets }}">
|
||||
<input type="hidden" name="exercise_{{ exercise.exercise_index }}_default_reps" value="{{ exercise.default_reps }}">
|
||||
<div class="case-legend">
|
||||
<span class="section-label">Exercise {{ loop.index }}</span>
|
||||
<span class="pill">{{ exercise.target_sets }} sets</span>
|
||||
|
||||
Reference in New Issue
Block a user