Reorganize workout view for desktop and compact session details
This commit is contained in:
+16
-3
@@ -199,6 +199,19 @@ def get_workout_distribution(person_id, workout_id):
|
||||
distribution=distribution,
|
||||
category_name=category)
|
||||
|
||||
@workout_bp.route("/person/<int:person_id>/workout/<int:workout_id>/summary", methods=['GET'])
|
||||
@login_required
|
||||
@validate_workout
|
||||
@require_ownership
|
||||
def get_workout_summary(person_id, workout_id):
|
||||
top_sets = db.execute(
|
||||
"SELECT exercise_id, repetitions FROM topset WHERE workout_id = %s",
|
||||
[workout_id],
|
||||
)
|
||||
return render_template('partials/workout_summary.html', person_id=person_id,
|
||||
workout_id=workout_id, top_sets=top_sets)
|
||||
|
||||
|
||||
@workout_bp.route("/person/<int:person_id>/workout/<int:workout_id>/topset/<int:topset_id>/achievements", methods=['GET'])
|
||||
@validate_topset
|
||||
def get_topset_achievements(person_id, workout_id, topset_id):
|
||||
@@ -209,7 +222,7 @@ def get_topset_achievements(person_id, workout_id, topset_id):
|
||||
@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'))
|
||||
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'), existing_row=True)
|
||||
|
||||
@workout_bp.route("/person/<int:person_id>/workout/<int:workout_id>/topset/<int:topset_id>/edit_form", methods=['GET'])
|
||||
@login_required
|
||||
@@ -273,7 +286,7 @@ def update_topset(person_id, workout_id, topset_id):
|
||||
db.update_topset(exercise_id, repetitions, weight, topset_id)
|
||||
exercise = db.get_exercise(exercise_id)
|
||||
db.activityRequest.log(current_user.id, 'UPDATE_SET', 'topset', topset_id, f"Updated set {topset_id}: {repetitions} x {weight}kg {exercise['name']}")
|
||||
return render_template('partials/topset.html', person_id=person_id, workout_id=workout_id, topset_id=topset_id, exercise_id=exercise_id, exercise_name=exercise.get('name'), repetitions=repetitions, weight=weight)
|
||||
return render_template('partials/topset.html', person_id=person_id, workout_id=workout_id, topset_id=topset_id, exercise_id=exercise_id, exercise_name=exercise.get('name'), repetitions=repetitions, weight=weight, existing_row=True), 200, {"HX-Trigger": "topsetChanged"}
|
||||
|
||||
@workout_bp.route("/person/<int:person_id>/workout/<int:workout_id>/topset/<int:topset_id>/delete", methods=['DELETE'])
|
||||
@login_required
|
||||
@@ -283,7 +296,7 @@ def delete_topset(person_id, workout_id, topset_id):
|
||||
topset = db.get_topset(topset_id)
|
||||
db.delete_topset(topset_id)
|
||||
db.activityRequest.log(current_user.id, 'DELETE_SET', 'topset', topset_id, f"Deleted set {topset_id}: {topset['exercise_name']} in workout {workout_id}")
|
||||
return ""
|
||||
return f'<tr id="extra-target-{topset_id}" hx-swap-oob="delete"></tr>', 200, {"HX-Trigger": "topsetChanged"}
|
||||
|
||||
@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):
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/* Workout workspace: keep logging readable on wide screens. */
|
||||
.workout-workspace{max-width:1360px;margin:0 auto;padding:8px 12px 40px;color:#253449}
|
||||
.workout-workspace nav{margin-bottom:28px}
|
||||
.workout-header{display:flex;align-items:center;justify-content:space-between;gap:20px;margin-bottom:24px}
|
||||
.workout-eyebrow{font-size:11px;font-weight:700;letter-spacing:.12em;text-transform:uppercase;color:#64748b;margin:0 0 8px}
|
||||
.workout-header h1{font-size:30px;line-height:1.25;font-weight:750;letter-spacing:-.035em;margin-bottom:8px}
|
||||
.workout-header h1 span{color:#64748b;font-weight:400}
|
||||
.workout-layout{display:grid;grid-template-columns:minmax(0,1fr) 300px;gap:24px;align-items:start}
|
||||
.workout-main,.workout-sidebar{min-width:0;display:grid;gap:20px}
|
||||
.workout-card{background:#fff;border:1px solid #e1e7ec;border-radius:14px;box-shadow:0 2px 4px #182c4203;min-width:0}
|
||||
.workout-logger{padding:24px;border-top:3px solid #0891a0}
|
||||
.workout-section-heading{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:22px}
|
||||
.workout-section-heading h2{font-size:18px;line-height:1.4;font-weight:700;letter-spacing:-.02em}
|
||||
.workout-subtle{font-size:12px;line-height:1.6;color:#64748b;font-weight:400}
|
||||
.workout-section-heading p.workout-subtle{margin-top:5px}
|
||||
.workout-set-fields{display:grid;grid-template-columns:minmax(140px,1fr) 84px 104px auto;align-items:end;gap:12px}
|
||||
.workout-set-field{min-width:0}
|
||||
.workout-set-field label{font-size:11px;letter-spacing:.03em;text-transform:none;color:#64748b;margin-bottom:7px}
|
||||
.workout-set-field input{height:44px;border-radius:8px;padding:10px 12px;font-size:14px;background:#f8fafc;border-color:#dbe3e9;color:#253449}
|
||||
.workout-set-field input:focus{outline:2px solid #0891a0;outline-offset:2px}
|
||||
.workout-add-button{display:flex;align-items:center;justify-content:center;gap:5px;min-height:44px;padding:10px 15px;background:#087f8c;color:white;border-radius:8px;font-size:13px;font-weight:650;white-space:nowrap}
|
||||
.workout-add-button:hover{background:#066975}
|
||||
.workout-workspace button:focus-visible,.workout-workspace summary:focus-visible{outline:2px solid #0891a0;outline-offset:3px}
|
||||
.workout-button{display:flex;align-items:center;gap:16px;padding:10px 14px;border:1px solid #dbe3e9;background:#fff;border-radius:8px;font-size:12px;cursor:pointer;list-style:none}
|
||||
.workout-menu{position:relative;flex-shrink:0}
|
||||
.workout-menu-content{position:absolute;right:0;top:calc(100% + 8px);z-index:20;padding:6px;background:#fff;border:1px solid #e1e7ec;border-radius:10px;min-width:180px;box-shadow:0 8px 24px #182c4214}
|
||||
.workout-delete{color:#b42335;padding:10px;width:100%;text-align:left;border-radius:6px;font-size:13px}
|
||||
.workout-delete:hover{background:#fff1f2}
|
||||
.workout-results>.workout-section-heading{padding:22px 24px 18px;margin:0}
|
||||
.workout-table{width:100%;border-collapse:collapse;table-layout:fixed;text-align:left}
|
||||
.workout-table>thead th{font-size:10px;letter-spacing:.08em;text-transform:uppercase;color:#64748b;background:#f8fafc;padding:12px 20px;border-block:1px solid #e8edf1;font-weight:650}
|
||||
.workout-table>thead th:first-child{width:53%}
|
||||
.workout-table>thead th:last-child{width:82px;padding-inline:0}
|
||||
.workout-table .workout-set-row>td{padding:18px 20px;vertical-align:middle;border-bottom:1px solid #edf0f3;font-size:13px}
|
||||
.workout-table .workout-set-row>td:last-child{display:table-cell;padding:10px 6px}
|
||||
.workout-table .workout-set-row>td:last-child>div{flex-direction:row}
|
||||
.workout-table .workout-set-row>td:last-child button{color:#718096;border-radius:7px}
|
||||
.workout-table .workout-set-row>td:last-child button:hover{color:#087f8c;background:#edf7f8}
|
||||
.workout-exercise-name{display:flex;align-items:flex-start;flex-direction:column;gap:8px;overflow-wrap:anywhere}
|
||||
.workout-exercise-tools{display:flex;gap:8px;flex-wrap:wrap}
|
||||
.workout-exercise-tools button{gap:4px;padding:3px 0;font-size:11px;font-weight:500;color:#64748b;min-height:26px}
|
||||
.workout-exercise-tools button:hover{color:#087f8c;background:transparent}
|
||||
.workout-exercise-tools svg{width:13px;height:13px}
|
||||
.workout-empty{display:none;padding:42px 24px;text-align:center;color:#64748b;font-size:13px;line-height:1.7}
|
||||
.workout-empty strong{display:block;color:#334155;font-size:16px;margin-bottom:6px}
|
||||
.workout-results:not(:has(.workout-set-row)) .workout-empty{display:block}
|
||||
.workout-results:not(:has(.workout-set-row)) .workout-table{display:none}
|
||||
.workout-summary{padding:22px}
|
||||
.workout-summary dl{display:grid;grid-template-columns:repeat(3,1fr);gap:12px;margin:18px 0 14px}
|
||||
.workout-summary dl>div{display:flex;flex-direction:column-reverse;gap:4px}
|
||||
.workout-summary dt{font-size:11px;color:#64748b}
|
||||
.workout-summary dd{font-size:27px;line-height:1.2;letter-spacing:-.04em;font-weight:700;font-variant-numeric:tabular-nums}
|
||||
.workout-disclosure>summary{position:relative;padding:20px 40px 20px 20px;font-weight:650;font-size:14px;cursor:pointer;list-style:none}
|
||||
.workout-disclosure>summary:after{content:'+';position:absolute;right:20px;top:20px;color:#64748b;font-size:18px;font-weight:400}
|
||||
.workout-disclosure[open]>summary:after{content:'−'}
|
||||
.workout-disclosure>summary .workout-subtle{display:block;margin-top:3px}
|
||||
.workout-disclosure-body{padding:0 20px 20px}
|
||||
.workout-disclosure-body [id^='workout-note-'] a{float:none;padding-left:0}
|
||||
.workout-disclosure-body [id^='tag-form-w-']>div{display:block}
|
||||
.workout-disclosure-body [id^='tag-form-w-']>div>div{width:100%;padding:8px 0;margin:0}
|
||||
.workout-breakdown h3{font-size:11px;font-weight:650;color:#64748b;margin:0 0 12px}
|
||||
.workout-distribution-bar{display:flex;gap:2px;height:7px;border-radius:4px;overflow:hidden;margin-bottom:14px}
|
||||
.workout-distribution-legend{display:grid;gap:11px;font-size:12px}
|
||||
.workout-distribution-legend li{display:flex;justify-content:space-between;gap:10px;font-variant-numeric:tabular-nums}
|
||||
.workout-distribution-legend li>span:last-child{color:#64748b}
|
||||
.workout-legend-label{display:flex;align-items:center;gap:8px}
|
||||
.workout-legend-label i{width:7px;height:7px;border-radius:50%;flex-shrink:0}
|
||||
.workout-secondary-details{margin-top:20px;padding-top:14px;border-top:1px solid #e8edf1}
|
||||
.workout-secondary-details>summary,.workout-previous-details>summary{font-size:12px;color:#64748b;cursor:pointer}
|
||||
.workout-secondary-details .workout-breakdown{margin-top:20px}
|
||||
.workout-previous-details{border-top:1px solid #e8edf1;margin-top:18px;padding-top:14px}
|
||||
.workout-previous-details>summary span{float:right;color:#334155;font-variant-numeric:tabular-nums}
|
||||
.workout-table .extra-content-container:not(:empty){background:#f8fafc;padding:18px 20px;border-bottom:1px solid #e1e7ec}
|
||||
.workout-table .extra-content-container .progress-heading{padding-right:22px}
|
||||
.workout-workspace .forecast-chart{height:220px}
|
||||
.workout-workspace .forecast-chart path{vector-effect:non-scaling-stroke;stroke-width:1.8px}
|
||||
.workout-workspace .forecast-chart circle{opacity:.6}
|
||||
.workout-workspace .exercise-progress{padding:8px 0;max-width:100%}
|
||||
.workout-workspace .progress-title h4{font-size:14px}
|
||||
.workout-workspace .exercise-progress>h2{color:#64748b}
|
||||
@media(min-width:1600px){.workout-workspace{padding-top:16px}.workout-layout{gap:28px;grid-template-columns:minmax(0,1fr) 320px}}
|
||||
@media(max-width:1100px){.workout-layout{grid-template-columns:minmax(0,1fr) 260px;gap:16px}.workout-logger{padding:20px}.workout-set-fields{grid-template-columns:minmax(0,1fr) 76px 90px;gap:10px}.workout-set-submit{grid-column:1/-1}.workout-add-button{width:100%}}
|
||||
@media(max-width:900px){.workout-layout{grid-template-columns:minmax(0,1fr)}.workout-sidebar{grid-template-columns:repeat(2,minmax(0,1fr));align-items:start}.workout-set-fields{grid-template-columns:minmax(140px,1fr) 84px 104px auto}.workout-set-submit{grid-column:auto}}
|
||||
@media(max-width:600px){.workout-workspace{padding:4px 0 24px}.workout-workspace nav{margin-bottom:20px}.workout-header{gap:8px;align-items:flex-start;margin-bottom:18px}.workout-header h1{font-size:24px}.workout-header h1 span{display:block;font-size:16px;letter-spacing:0;margin-top:4px}.workout-button{gap:8px;padding:8px 10px;font-size:11px}.workout-main,.workout-sidebar{gap:14px}.workout-sidebar{grid-template-columns:minmax(0,1fr)}.workout-logger{padding:18px 16px}.workout-section-heading{margin-bottom:18px}.workout-section-heading>.workout-subtle{display:none}.workout-set-fields{grid-template-columns:1fr 1fr;gap:14px 10px}.workout-set-field:first-child,.workout-set-submit{grid-column:1/-1}.workout-results>.workout-section-heading{padding:18px 14px}.workout-table>thead th{padding:10px 12px}.workout-table>thead th:first-child{width:49%}.workout-table>thead th:last-child{width:44px}.workout-table .workout-set-row>td{padding:16px 12px;font-size:12px}.workout-table .workout-set-row>td:last-child{padding:6px 0}.workout-table .workout-set-row>td:last-child>div{flex-direction:column}.workout-exercise-tools{gap:8px}.workout-exercise-tools button{font-size:10px;min-height:30px}.workout-exercise-tools svg{display:none}.workout-table .extra-content-container:not(:empty){padding:14px 10px}.workout-workspace .forecast-chart{height:190px}.workout-summary dl{margin:14px 0}.workout-summary{padding:18px 20px}}
|
||||
@@ -15,6 +15,7 @@
|
||||
<link href="/static/css/tailwind.css" rel="stylesheet">
|
||||
|
||||
<link href="/static/css/style.css" rel="stylesheet">
|
||||
<link href="/static/css/workout.css?v=1" rel="stylesheet">
|
||||
<script src="/static/js/htmx.min.js" defer></script>
|
||||
<script src="/static/js/hyperscript.min.js" defer></script>
|
||||
<link rel="stylesheet" href="/static/css/forecast.css?v=2">
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<form class="w-full" id="new-set-workout-{{ workout_id }}"
|
||||
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
|
||||
|
||||
if detail.xhr.status == 200
|
||||
set #validation-error-{{ workout_id }}.innerText to ''
|
||||
add .hidden to #validation-error-{{ workout_id }}
|
||||
@@ -19,16 +19,16 @@
|
||||
<div id="validation-error-{{ workout_id }}"
|
||||
class="hidden text-red-500 text-xs italic mb-4 p-2 bg-red-50 border border-red-200 rounded"></div>
|
||||
|
||||
<div class="flex flex-wrap -mx-3 mb-2">
|
||||
<div class="w-full md:w-[30%] px-2 md:px-3 mb-6 md:mb-0">
|
||||
<label class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" for="grid-state">
|
||||
<div class="workout-set-fields">
|
||||
<div class="workout-set-field">
|
||||
<label class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" for="exercise-search">
|
||||
Exercise
|
||||
</label>
|
||||
{{ render_partial('partials/exercise/exercise_select.html', person_id=person_id,
|
||||
exercise_id=exercise_id, exercise_name=exercise_name) }}
|
||||
</div>
|
||||
|
||||
<div class="w-full md:w-[30%] px-2 md:px-3 mb-6 md:mb-0">
|
||||
<div class="workout-set-field">
|
||||
<label class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" for="grid-city">
|
||||
Reps
|
||||
</label>
|
||||
@@ -38,9 +38,9 @@
|
||||
_="on clearNewSetInputs set my.placeholder to ''" {% endif %}>
|
||||
</div>
|
||||
|
||||
<div class="w-full md:w-[30%] px-2 md:px-3 mb-6 md:mb-0">
|
||||
<div class="workout-set-field">
|
||||
<label class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" for="grid-zip">
|
||||
Weight
|
||||
Weight (kg)
|
||||
</label>
|
||||
<input
|
||||
class="appearance-none block w-full bg-gray-200 text-gray-700 border border-gray-200 rounded py-3 px-4 leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
|
||||
@@ -48,14 +48,15 @@
|
||||
_="on clearNewSetInputs set my.placeholder to ''" {% endif %}>
|
||||
</div>
|
||||
|
||||
<div class="w-full md:w-[10%] px-2 md:px-3 mb-6 md:mb-0">
|
||||
<div class="workout-set-submit">
|
||||
<button
|
||||
class="flex items-center justify-center py-2 px-2 md:px-3 mb-3 text-sm font-medium text-center text-gray-900 bg-cyan-600 hover:bg-cyan-700 rounded-lg border border-gray-300 hover:scale-[1.02] transition-transform mb-6 md:mb-0 mt-0 md:mt-6 w-full"
|
||||
class="workout-add-button"
|
||||
type="submit">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24" class="w-7 h-7">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24" class="w-5 h-5">
|
||||
<path
|
||||
d="M12 4a1 1 0 011 1v6h6a1 1 0 110 2h-6v6a1 1 0 11-2 0v-6H5a1 1 0 110-2h6V5a1 1 0 011-1z" />
|
||||
</svg>
|
||||
<span>Add set</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -66,17 +67,18 @@
|
||||
|
||||
<div hx-trigger="exerciseSelected from:body"
|
||||
hx-get="{{ url_for('workout.get_most_recent_topset_for_exercise', person_id=person_id, workout_id=workout_id) }}"
|
||||
hx-target="#new-set-form-container-{{ workout_id }}" hx-include="[name='exercise_id']">
|
||||
hx-target="#new-set-form-container-{{ workout_id }}" hx-swap="outerHTML" hx-include="[name='exercise_id']">
|
||||
</div>
|
||||
|
||||
{% if exercise_id %}
|
||||
<div class="flex items-center justify-center">
|
||||
<details class="workout-previous-details">
|
||||
<summary>Previous performance{% if repetitions %}<span>{{ repetitions }} × {{ weight }} kg</span>{% endif %}</summary>
|
||||
<div class="w-full">
|
||||
<div class="hidden"
|
||||
hx-get="{{ url_for('get_exercise_progress_for_user', person_id=person_id, exercise_id=exercise_id) }}"
|
||||
hx-trigger="load" hx-target="this" hx-swap="outerHTML">
|
||||
hx-trigger="toggle once from:closest details" hx-target="this" hx-swap="outerHTML">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</details>
|
||||
{% endif %}
|
||||
</div>
|
||||
@@ -1,12 +1,12 @@
|
||||
<tr id="topset-{{ topset_id }}">
|
||||
<tr class="workout-set-row" id="topset-{{ topset_id }}">
|
||||
<td class="p-0 sm:p-4 text-sm font-semibold text-gray-900 break-normal">
|
||||
{% if is_edit|default(false, true) == false %}
|
||||
<div class="flex items-center space-x-2">
|
||||
<div class="workout-exercise-name">
|
||||
<span class="cursor-pointer" hx-get="{{ url_for('tags.goto_tag') }}"
|
||||
hx-vals='{"filter": "?exercise_id={{ exercise_id }}", "person_id" : "{{ person_id }}" }'
|
||||
hx-target="#container" hx-swap="innerHTML" hx-push-url="true"
|
||||
_='on click trigger closeModalWithoutRefresh'>{{ exercise_name }}</span>
|
||||
<div class="flex flex-col sm:flex-row space-y-1 sm:space-y-0 sm:space-x-1">
|
||||
<div class="workout-exercise-tools">
|
||||
<button
|
||||
class="inline-flex justify-center p-1 text-gray-500 rounded cursor-pointer hover:text-gray-900 hover:bg-gray-100 dark:text-gray-400 dark:hover:text-white dark:hover:bg-gray-600"
|
||||
title="Show Progress Graph"
|
||||
@@ -17,7 +17,7 @@
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||
d="M13 7h8m0 0v8m0-8l-8 8-4-4-6 6"></path>
|
||||
</svg>
|
||||
<span class="sr-only">Show Progress Graph</span>
|
||||
<span class="workout-tool-label">Progress</span>
|
||||
</button>
|
||||
<button
|
||||
class="inline-flex justify-center p-1 text-gray-500 rounded cursor-pointer hover:text-gray-900 hover:bg-gray-100 dark:text-gray-400 dark:hover:text-white dark:hover:bg-gray-600"
|
||||
@@ -29,7 +29,7 @@
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||
d="M4 6h16M4 10h16M4 14h16M4 18h16"></path>
|
||||
</svg>
|
||||
<span class="sr-only">Show History</span>
|
||||
<span class="workout-tool-label">History</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -57,11 +57,11 @@
|
||||
<div class="flex items-center flex-col sm:flex-row">
|
||||
<input type="number"
|
||||
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-4 sm:pl-10 p-2.5 "
|
||||
name="repetitions" value="{{ repetitions }}">
|
||||
aria-label="Repetitions" name="repetitions" value="{{ repetitions }}">
|
||||
<p class="px-2">x</p>
|
||||
<input type="number"
|
||||
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-4 sm:pl-10 p-2.5 "
|
||||
name="weight" value="{{ weight }}">
|
||||
aria-label="Weight in kilograms" step="any" name="weight" value="{{ weight }}">
|
||||
<p class="px-2">kg</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
@@ -118,7 +118,7 @@
|
||||
</td>
|
||||
</tr>
|
||||
{# Target row modified for dismissible extra content (graph or history) #}
|
||||
<tr id="extra-target-{{ topset_id }}">
|
||||
<tr id="extra-target-{{ topset_id }}" {% if existing_row|default(false) or is_edit|default(false) %}hx-swap-oob="outerHTML"{% endif %}>
|
||||
<td colspan="3" class="p-0 relative">
|
||||
<div id="extra-content-{{ topset_id }}" class="extra-content-container" _="
|
||||
on htmx:afterSwap
|
||||
|
||||
@@ -1,64 +1,18 @@
|
||||
{% set distribution = distribution or muscle_distribution %}
|
||||
{% set category_name = category_name or 'Muscle Group' %}
|
||||
{% set distribution = distribution|default([], true) %}
|
||||
{% set category_name = category_name|default('Muscle Group', true) %}
|
||||
{% set breakdown_id = category_name.lower().replace(' ', '-') %}
|
||||
|
||||
{% if distribution %}
|
||||
<div class="px-4 py-3 bg-white relative" id="{{ breakdown_id }}-breakdown"
|
||||
<div class="workout-breakdown" id="{{ breakdown_id }}-breakdown"
|
||||
hx-get="{{ url_for('workout.get_workout_distribution', person_id=person_id, workout_id=workout_id, category=category_name) }}"
|
||||
hx-trigger="topsetAdded from:body" hx-swap="outerHTML">
|
||||
|
||||
<!-- Shared Popover Container (managed by Hyperscript) -->
|
||||
<div id="popover-{{ breakdown_id }}"
|
||||
class="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 z-30 hidden bg-white border border-gray-200 shadow-2xl rounded-xl p-4 min-w-[200px] animate-in fade-in zoom-in duration-200"
|
||||
_="on click from elsewhere add .hidden to me">
|
||||
<div id="content-{{ breakdown_id }}"></div>
|
||||
<button class="absolute top-2 right-2 text-gray-400 hover:text-gray-600"
|
||||
_="on click add .hidden to #popover-{{ breakdown_id }}">
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
|
||||
</svg>
|
||||
</button>
|
||||
hx-trigger="topsetAdded from:body, topsetChanged from:body" hx-swap="outerHTML">
|
||||
<h3>{{ category_name }}</h3>
|
||||
{% if distribution %}
|
||||
<div class="workout-distribution-bar" aria-hidden="true">
|
||||
{% for item in distribution %}<span style="width: {{ item.percentage }}%; background-color: {{ item.color }};"></span>{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="flex items-center justify-between mb-2">
|
||||
<h4 class="text-[9px] font-black text-gray-400 uppercase tracking-[0.25em]">{{ category_name }} Distribution
|
||||
</h4>
|
||||
</div>
|
||||
|
||||
<!-- Sleek Performance Bar -->
|
||||
<div class="w-full h-8 flex overflow-hidden rounded-lg bg-gray-100 shadow-inner p-0.5 cursor-pointer">
|
||||
<ul class="workout-distribution-legend">
|
||||
{% for item in distribution %}
|
||||
<div class="h-full transition-all duration-700 ease-in-out flex items-center justify-center relative group first:rounded-l-md last:rounded-r-md"
|
||||
style="width: {{ item.percentage }}%; background-color: {{ item.color }};" _="on click
|
||||
halt the event
|
||||
put '<div class=\'flex flex-col gap-1\'>
|
||||
<div class=\'flex items-center gap-2\'>
|
||||
<div class=\'w-3 h-3 rounded-full\' style=\'background-color: {{ item.color }}\'></div>
|
||||
<span class=\'font-black text-sm uppercase\'>{{ item.attribute_name }}</span>
|
||||
</div>
|
||||
<div class=\'text-2xl font-black text-gray-900\'>{{ item.percentage }}%</div>
|
||||
<div class=\'text-[10px] font-bold text-gray-400 uppercase tracking-wider\'>{{ item.count }} Sets Targeted</div>
|
||||
</div>' into #content-{{ breakdown_id }}
|
||||
remove .hidden from #popover-{{ breakdown_id }}"
|
||||
title="{{ item.attribute_name }}: {{ item.percentage }}%">
|
||||
|
||||
<!-- Labels (Name & Percentage grouped and centered) -->
|
||||
<div
|
||||
class="flex items-center justify-center gap-1.5 leading-none text-white pointer-events-none px-1 overflow-hidden">
|
||||
{% if item.percentage > 18 %}
|
||||
<span class="text-[9px] font-black uppercase tracking-tighter truncate drop-shadow-sm">{{
|
||||
item.attribute_name }}</span>
|
||||
<span class="text-[9px] font-bold opacity-90 whitespace-nowrap drop-shadow-sm">{{ item.percentage
|
||||
}}%</span>
|
||||
{% elif item.percentage > 8 %}
|
||||
<span class="text-[9px] font-black drop-shadow-sm">{{ item.percentage }}%</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<!-- Enhanced Hover State -->
|
||||
<div class="absolute inset-0 bg-white/15 opacity-0 group-hover:opacity-100 transition-opacity"></div>
|
||||
</div>
|
||||
<li><span class="workout-legend-label"><i style="background-color: {{ item.color }};" aria-hidden="true"></i>{{ item.attribute_name }}</span><span title="{{ item.count }} sets targeted">{{ item.percentage }}%</span></li>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</ul>
|
||||
{% else %}<p class="workout-subtle">No categorized sets yet.</p>{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
@@ -0,0 +1,14 @@
|
||||
{% set totals = namespace(reps=0) %}
|
||||
{% for top_set in top_sets %}{% set totals.reps = totals.reps + (top_set.repetitions or 0)|int %}{% endfor %}
|
||||
<section class="workout-card workout-summary" id="workout-summary"
|
||||
aria-label="Session summary" aria-live="polite"
|
||||
hx-get="{{ url_for('workout.get_workout_summary', person_id=person_id, workout_id=workout_id) }}"
|
||||
hx-trigger="topsetAdded from:body, topsetChanged from:body" hx-swap="outerHTML">
|
||||
<p class="workout-eyebrow">This session</p>
|
||||
<dl>
|
||||
<div><dt>Exercises</dt><dd>{{ top_sets|map(attribute='exercise_id')|unique|list|length }}</dd></div>
|
||||
<div><dt>Top sets</dt><dd>{{ top_sets|length }}</dd></div>
|
||||
<div><dt>Reps</dt><dd>{{ totals.reps }}</dd></div>
|
||||
</dl>
|
||||
<p class="workout-subtle">Based on your logged top sets.</p>
|
||||
</section>
|
||||
+69
-100
@@ -1,9 +1,8 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
|
||||
<nav class="flex md:pb-0 pb-4" aria-label="Breadcrumb">
|
||||
<div class="workout-workspace">
|
||||
<nav class="flex md:pb-0 pb-4" aria-label="Breadcrumb">
|
||||
<ol class="inline-flex items-center space-x-1 md:space-x-2 rtl:space-x-reverse">
|
||||
<li class="inline-flex items-center">
|
||||
<a hx-get="{{ url_for('dashboard') }}" hx-push-url="true" hx-target="#container"
|
||||
@@ -23,8 +22,8 @@
|
||||
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||
d="m1 9 4-4-4-4" />
|
||||
</svg>
|
||||
{% set hx_current_url = request.headers.get('HX-Current-URL') %}
|
||||
<a hx-get="{{ hx_current_url if hx_current_url else url_for('calendar.get_calendar', person_id=person_id) }}"
|
||||
|
||||
<a hx-get="{{ url_for('calendar.get_calendar', person_id=person_id) }}"
|
||||
hx-push-url="true" hx-target="#container"
|
||||
class="ms-1 text-sm font-medium text-gray-700 hover:text-blue-600 md:ms-2 dark:text-gray-400 dark:hover:text-white cursor-pointer">{{person_name}}</a>
|
||||
</div>
|
||||
@@ -41,107 +40,77 @@
|
||||
</li>
|
||||
</ol>
|
||||
</nav>
|
||||
<header class="workout-header">
|
||||
<div>
|
||||
<p class="workout-eyebrow">Training log</p>
|
||||
<h1>{{ person_name }}<span> / Workout</span></h1>
|
||||
{{ render_partial('partials/start_date.html', person_id=person_id, workout_id=workout_id, start_date=start_date) }}
|
||||
</div>
|
||||
<details class="workout-menu">
|
||||
<summary class="workout-button">Session options <span aria-hidden="true">···</span></summary>
|
||||
<div class="workout-menu-content">
|
||||
<button type="button" class="workout-delete"
|
||||
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">Delete workout</button>
|
||||
</div>
|
||||
</details>
|
||||
</header>
|
||||
|
||||
<div class='p-0 md:p-4 m-0 md:m-2'>
|
||||
<div class="relative w-full h-full">
|
||||
<!-- Modal content -->
|
||||
<div class="relative bg-white rounded-lg shadow overflow-hidden">
|
||||
<!-- Modal header -->
|
||||
<div class="p-4 md:p-6 border-b relative">
|
||||
<div class="flex flex-col w-full pr-8">
|
||||
<h3 class="text-2xl font-black text-gray-900 leading-tight">{{ person_name }}</h3>
|
||||
{{ render_partial('partials/workout_tags.html', person_id=person_id, workout_id=workout_id,
|
||||
tags=tags) }}
|
||||
<div class="workout-layout">
|
||||
<div class="workout-main">
|
||||
<section class="workout-card workout-logger" aria-labelledby="log-heading">
|
||||
<div class="workout-section-heading">
|
||||
<div><p class="workout-eyebrow">Log your training</p><h2 id="log-heading">Add a top set</h2></div>
|
||||
<span class="workout-subtle">Reps × weight</span>
|
||||
</div>
|
||||
{{ render_partial('partials/new_set_form.html', person_id=person_id, workout_id=workout_id, exercises=exercises, has_value=False) }}
|
||||
</section>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mt-4">
|
||||
{{ render_partial('partials/start_date.html', person_id=person_id, workout_id=workout_id,
|
||||
start_date=start_date) }}
|
||||
{{ render_partial('partials/workout_note.html', person_id=person_id, workout_id=workout_id,
|
||||
note=note) }}
|
||||
</div>
|
||||
<section class="workout-card workout-results" aria-labelledby="sets-heading">
|
||||
<div class="workout-section-heading">
|
||||
<div><h2 id="sets-heading">Session exercises</h2><p class="workout-subtle">Your top sets, records and progress.</p></div>
|
||||
</div>
|
||||
<table class="workout-table">
|
||||
<thead><tr><th scope="col">Exercise</th><th scope="col">Top set</th><th scope="col"><span class="sr-only">Actions</span></th></tr></thead>
|
||||
<tbody id="new-workout" hx-target="closest tr" hx-swap="outerHTML swap:0.5s">
|
||||
{% for top_set in top_sets %}
|
||||
{{ render_partial('partials/topset.html', person_id=person_id, workout_id=workout_id, **top_set) }}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="workout-empty" id="no-workouts"><strong>Your session starts here</strong><p>Add your first top set above. Progress and records will appear here.</p></div>
|
||||
<div id="exercise-progress"></div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<button type="button"
|
||||
class="absolute top-4 right-4 text-gray-400 bg-transparent hover:bg-gray-100 hover:text-gray-900 rounded-lg text-sm p-2 transition-colors inline-flex items-center"
|
||||
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"
|
||||
xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd"
|
||||
d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z"
|
||||
clip-rule="evenodd"></path>
|
||||
</svg>
|
||||
<span class="sr-only">Delete workout</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Multi-Category Breakdown Stripes -->
|
||||
<div class="bg-gray-50/50 border-b divide-y divide-gray-100">
|
||||
{{ render_partial('partials/workout_breakdown.html', person_id=person_id, workout_id=workout_id,
|
||||
distribution=muscle_distribution, category_name='Muscle Group') }}
|
||||
|
||||
{{ render_partial('partials/workout_breakdown.html', person_id=person_id, workout_id=workout_id,
|
||||
distribution=equipment_distribution, category_name='Machine vs Free Weight') }}
|
||||
|
||||
{{ render_partial('partials/workout_breakdown.html', person_id=person_id, workout_id=workout_id,
|
||||
distribution=movement_distribution, category_name='Compound vs Isolation') }}
|
||||
</div>
|
||||
|
||||
<!-- Workout Content Card -->
|
||||
<div class="p-0">
|
||||
<div class="p-2 md:p-4 border-0 md:border-b">
|
||||
<!-- Modal footer / New Set Form -->
|
||||
<div class="flex items-center p-1 md:p-2 rounded-b">
|
||||
{{ render_partial('partials/new_set_form.html', person_id=person_id,
|
||||
workout_id=workout_id,
|
||||
exercises=exercises,
|
||||
has_value=False) }}
|
||||
</div>
|
||||
|
||||
<!-- Modal body / Top Sets Table -->
|
||||
<div class="p-3 md:p-6 space-y-6">
|
||||
<table class="items-center w-full bg-transparent border-collapse table-fixed">
|
||||
<thead>
|
||||
<tr>
|
||||
<th
|
||||
class="px-4 bg-gray-50 text-gray-700 align-middle py-3 text-xs font-semibold text-left uppercase border-l-0 border-r-0 whitespace-nowrap">
|
||||
Exercise</th>
|
||||
<th
|
||||
class="px-4 bg-gray-50 text-gray-700 align-middle py-3 text-xs font-semibold text-left uppercase border-l-0 border-r-0 whitespace-nowrap">
|
||||
Top Set</th>
|
||||
<th
|
||||
class="bg-gray-50 text-gray-700 align-middle py-3 text-xs font-semibold text-left uppercase border-l-0 border-r-0 whitespace-nowrap w-9 sm:w-20">
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-gray-100" id="new-workout" hx-target="closest tr"
|
||||
hx-swap="outerHTML swap:0.5s">
|
||||
{% for top_set in top_sets %}
|
||||
{{ render_partial('partials/topset.html', person_id=person_id,
|
||||
workout_id=workout_id, **top_set) }}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{% if top_sets|length == 0 %}
|
||||
<div class="bg-purple-100 rounded-lg py-5 px-6 mb-4 text-base text-purple-700 mb-3" role="alert"
|
||||
id="no-workouts">
|
||||
No sets recorded for this session.
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div id="exercise-progress" class="mx-0 md:mx-5">
|
||||
</div>
|
||||
<aside class="workout-sidebar" aria-label="Session information">
|
||||
{{ render_partial('partials/workout_summary.html', person_id=person_id, workout_id=workout_id, top_sets=top_sets) }}
|
||||
<details class="workout-card workout-disclosure" open>
|
||||
<summary>Training balance <span class="workout-subtle">Muscles & equipment</span></summary>
|
||||
<div class="workout-disclosure-body">
|
||||
{{ render_partial('partials/workout_breakdown.html', person_id=person_id, workout_id=workout_id, distribution=muscle_distribution, category_name='Muscle Group') }}
|
||||
<details class="workout-secondary-details">
|
||||
<summary>Equipment & movement</summary>
|
||||
{{ render_partial('partials/workout_breakdown.html', person_id=person_id, workout_id=workout_id, distribution=equipment_distribution, category_name='Machine vs Free Weight') }}
|
||||
{{ render_partial('partials/workout_breakdown.html', person_id=person_id, workout_id=workout_id, distribution=movement_distribution, category_name='Compound vs Isolation') }}
|
||||
</details>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</details>
|
||||
<details class="workout-card workout-disclosure" {% if note %}open{% endif %}>
|
||||
<summary>Session notes <span class="workout-subtle">Cues, energy, how it felt</span></summary>
|
||||
<div class="workout-disclosure-body">
|
||||
{{ render_partial('partials/workout_note.html', person_id=person_id, workout_id=workout_id, note=note or '') }}
|
||||
</div>
|
||||
</details>
|
||||
<details class="workout-card workout-disclosure">
|
||||
<summary>Tags <span class="workout-subtle">Organize this session</span></summary>
|
||||
<div class="workout-disclosure-body">
|
||||
{{ render_partial('partials/workout_tags.html', person_id=person_id, workout_id=workout_id, tags=tags) }}
|
||||
</div>
|
||||
</details>
|
||||
</aside>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hidden" hx-get="{{ url_for('get_stats') }}" hx-vals='{"person_id": "{{ person_id }}"}' hx-trigger="load"
|
||||
hx-target="#stats" hx-swap="innerHTML">
|
||||
</div>
|
||||
<div class="hidden" hx-get="{{ url_for('get_stats') }}" hx-vals='{"person_id": "{{ person_id }}"}' hx-trigger="load" hx-target="#stats" hx-swap="innerHTML"></div>
|
||||
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,125 @@
|
||||
"""Workout rendering and HTMX lifecycle checks, using an isolated database."""
|
||||
import unittest
|
||||
from datetime import date
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
|
||||
class WorkoutViewTests(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
# Import the application without opening a real database connection.
|
||||
with patch('psycopg_pool.ConnectionPool'):
|
||||
import app
|
||||
cls.module = app
|
||||
cls.app = app.app
|
||||
cls.app.config.update(TESTING=True)
|
||||
|
||||
def setUp(self):
|
||||
import routes.workout as workout
|
||||
self.workout = workout
|
||||
self.db = MagicMock()
|
||||
for module in (self.module, workout):
|
||||
patcher = patch.object(module, 'db', self.db)
|
||||
patcher.start()
|
||||
self.addCleanup(patcher.stop)
|
||||
self.user = SimpleNamespace(id=1, name='Peter', is_authenticated=True,
|
||||
is_active=True, is_anonymous=False,
|
||||
is_admin=False, get_id=lambda: '1')
|
||||
loader = patch.object(self.module.login_manager, '_user_callback', lambda _: self.user)
|
||||
loader.start()
|
||||
self.addCleanup(loader.stop)
|
||||
self.client = self.app.test_client()
|
||||
with self.client.session_transaction() as session:
|
||||
session['_user_id'] = '1'
|
||||
session['_fresh'] = True
|
||||
self.top_sets = [
|
||||
dict(topset_id=i, exercise_id=i, exercise_name=name, repetitions=reps, weight=weight)
|
||||
for i, (name, reps, weight) in enumerate([
|
||||
('30 degrees Smith Press', 7, 93.5),
|
||||
('Seated Smith machine BTN press', 5, 61.5),
|
||||
('Smith machine JM press', 12, 62.0),
|
||||
('DB Lateral Raises', 20, 10.5),
|
||||
('Smith machine Bulgarian split squat', 12, 96.0),
|
||||
], 1)
|
||||
]
|
||||
self.distribution = [
|
||||
dict(attribute_name=name, percentage=percent, color=color, count=1)
|
||||
for name, percent, color in [('Shoulders', 40, '#477db5'), ('Chest', 20, '#299e9a'),
|
||||
('Quads', 20, '#8b75bb'), ('Triceps', 20, '#c78565')]
|
||||
]
|
||||
self.view_model = dict(person_id=1, workout_id=1, person_name='Peter',
|
||||
start_date=date(2026, 9, 5), note='', tags=[], top_sets=self.top_sets,
|
||||
muscle_distribution=self.distribution, equipment_distribution=[], movement_distribution=[])
|
||||
model = patch.object(workout, '_get_workout_view_model', lambda *args: self.view_model)
|
||||
model.start()
|
||||
self.addCleanup(model.stop)
|
||||
self.db.execute.return_value = self.top_sets
|
||||
self.db.get_topset.return_value = self.top_sets[0]
|
||||
self.db.get_exercise.return_value = {'name': self.top_sets[0]['exercise_name']}
|
||||
self.db.get_all_exercises.return_value = [{'exercise_id': 1, 'name': 'Smith Press'}]
|
||||
self.db.create_topset.return_value = 6
|
||||
self.db.get_topset_achievements.return_value = dict(is_pr_reps=True, rep_increase=1, weight_increase=0, stalled_sessions=0)
|
||||
self.db.exercises.get_workout_attribute_distribution.return_value = self.distribution
|
||||
self.base = '/person/1/workout/1'
|
||||
|
||||
def test_full_page_and_fragment_render(self):
|
||||
for headers in ({}, {'HX-Request': 'true'}):
|
||||
response = self.client.get(self.base, headers=headers)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertIn(b'workout-layout', response.data)
|
||||
self.assertIn(b'Session exercises', response.data)
|
||||
self.assertEqual(response.data.count(b'id=extra-target-1'), 1)
|
||||
|
||||
def test_summary_counts_unique_exercises_and_refreshes(self):
|
||||
self.db.execute.return_value = self.top_sets + [self.top_sets[0]]
|
||||
response = self.client.get(self.base + '/summary')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertIn(b'<dt>Exercises<dd>5', response.data)
|
||||
self.assertIn(b'<dt>Top sets<dd>6', response.data)
|
||||
self.assertIn(b'<dt>Reps<dd>63', response.data)
|
||||
self.assertIn(b'topsetChanged from:body', response.data)
|
||||
|
||||
def test_empty_distribution_keeps_refresh_target(self):
|
||||
from flask import render_template
|
||||
with self.app.test_request_context():
|
||||
html = render_template('partials/workout_breakdown.html', person_id=1, workout_id=1,
|
||||
distribution=[], category_name='Muscle Group')
|
||||
self.assertIn('id="muscle-group-breakdown"', html)
|
||||
self.assertIn('No categorized sets yet.', html)
|
||||
self.assertIn('topsetAdded from:body', html)
|
||||
|
||||
def test_previous_performance_is_loaded_on_expansion(self):
|
||||
self.db.get_most_recent_topset_for_exercise.return_value = (7, 93.5, 'Smith Press')
|
||||
response = self.client.get(self.base + '/exercise/most_recent_topset_for_exercise?exercise_id=1')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertIn(b'toggle once from:closest details', response.data)
|
||||
self.assertNotIn(b'hx-trigger=load', response.data)
|
||||
self.assertIn(b'Previous performance', response.data)
|
||||
|
||||
def test_create_edit_cancel_update_and_delete_targets(self):
|
||||
data = dict(exercise_id=1, repetitions=8, weight=93.5)
|
||||
created = self.client.post(self.base + '/topset', data=data)
|
||||
self.assertEqual(created.headers['HX-Trigger'], 'topsetAdded')
|
||||
self.assertNotIn(b'hx-swap-oob', created.data)
|
||||
for suffix in ('/topset/1/edit_form', '/topset/1'):
|
||||
response = self.client.get(self.base + suffix)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertIn(b'hx-swap-oob=outerHTML', response.data)
|
||||
updated = self.client.put(self.base + '/topset/1', data=data)
|
||||
self.assertEqual(updated.headers['HX-Trigger'], 'topsetChanged')
|
||||
self.assertIn(b'hx-swap-oob=outerHTML', updated.data)
|
||||
deleted = self.client.delete(self.base + '/topset/1/delete')
|
||||
self.assertEqual(deleted.headers['HX-Trigger'], 'topsetChanged')
|
||||
self.assertIn(b'hx-swap-oob=delete', deleted.data)
|
||||
|
||||
def test_summary_requires_owner(self):
|
||||
with self.client.session_transaction() as session:
|
||||
session.clear()
|
||||
response = self.client.get(self.base + '/summary')
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.db.execute.assert_not_called()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user