Refactor route validations to decorators

This commit is contained in:
Peter Stockings
2022-07-20 14:15:11 +10:00
parent 6e1f164ba9
commit ee8245bb4c
18 changed files with 464 additions and 407 deletions

View File

@@ -86,7 +86,7 @@
{% for p in get_list_of_people_and_workout_count() %}
<li>
<a href="{{ url_for('display_workouts_for_person' ,person_id=p['PersonId']) }}"
<a href="{{ url_for('get_person' ,person_id=p['PersonId']) }}"
class="text-base text-gray-900 font-normal rounded-lg hover:bg-gray-100 flex items-center p-2 group {% if p['IsActive']==1 %} bg-gray-200 {% endif %}">
<svg class="w-6 h-6 text-gray-500 flex-shrink-0 group-hover:text-gray-900 transition duration-75"
fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">

View File

@@ -11,7 +11,7 @@
<span class="text-base font-normal text-gray-500">Current rep maxes</span>
</div>
<div class="flex-shrink-0">
<a href="{{ url_for('display_workouts_for_person' ,person_id=1) }}"
<a href="{{ url_for('get_workout' ,person_id=1) }}"
class="text-sm font-medium text-cyan-600 hover:bg-gray-100 rounded-lg p-2">View workouts</a>
</div>
</div>
@@ -173,7 +173,7 @@
<span class="text-base font-normal text-gray-500">Current rep maxes</span>
</div>
<div class="flex-shrink-0">
<a href="{{ url_for('display_workouts_for_person' ,person_id=2) }}"
<a href="{{ url_for('get_workout' ,person_id=2) }}"
class="text-sm font-medium text-cyan-600 hover:bg-gray-100 rounded-lg p-2">View workouts</a>
</div>
</div>

View File

@@ -6,10 +6,10 @@
<div class="mb-4 flex items-center justify-between">
<div>
<h3 class="text-xl font-bold text-gray-900 mb-2">{{ topset['Name'] }}</h3>
<h3 class="text-xl font-bold text-gray-900 mb-2">{{ topset['PersonName'] }}</h3>
<span class="text-base font-normal text-gray-500">{{ topset['StartDate'] }}</span>
</div>
<a href="{{ url_for('delete_topset_from_workout_for_person', person_id=person_id, workout_id=workout_id, topset_id=topset_id)}}"
<a href="{{ url_for('delete_topset', person_id=topset['PersonId'], workout_id=topset['WorkoutId'], topset_id=topset['TopSetId'])}}"
class="text-sm font-medium text-cyan-600 hover:bg-gray-100 rounded-lg inline-flex items-center p-2">
Delete topset
</a>
@@ -30,7 +30,7 @@
<select
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"
id="grid-state" name="exercise_id">
{% for e in exercises %}
{% for e in topset['Exercises'] %}
<option value="{{ e['ExcerciseId'] }}" {% if topset['ExcerciseId']==e['ExcerciseId'] %}
selected {% endif %}>{{
e['Name']}}</option>

View File

@@ -6,10 +6,10 @@
<div class="mb-4 flex items-center justify-between">
<div>
<h3 class="text-xl font-bold text-gray-900 mb-2">{{ workout_info['Name'] }}</h3>
<span class="text-base font-normal text-gray-500">{{ workout_info['StartDate'] }}</span>
<h3 class="text-xl font-bold text-gray-900 mb-2">{{ workout['PersonName'] }}</h3>
<span class="text-base font-normal text-gray-500">{{ workout['StartDate'] }}</span>
</div>
<form action="{{ url_for('delete_workout_from_person', person_id=person_id, workout_id=workout_id) }}"
<form action="{{ url_for('delete_workout', person_id=workout['PersonId'], workout_id=workout['WorkoutId']) }}"
method="delete">
<button
class="sm:inline-flex text-white bg-cyan-600 hover:bg-cyan-700 focus:ring-4 focus:ring-cyan-200 font-medium rounded-lg text-sm px-5 py-2.5 text-center items-center mt-6"
@@ -41,19 +41,19 @@
</tr>
</thead>
<tbody class="divide-y divide-gray-100">
{% for t in top_sets %}
{% for t in workout['TopSets'] %}
<tr class="text-gray-500">
<th class="border-t-0 px-4 align-middle text-l font-normal whitespace-nowrap p-4 text-left">
{{ t['Name'] }}
{{ t['ExerciseName'] }}</th>
</th>
<td class="border-t-0 px-4 align-middle text-l font-medium text-gray-900 whitespace-nowrap p-4">
{{ t['TopSet'] }}</td>
{{ t['Repetitions'] }} x {{ t['Weight'] }}kg</td>
<td class="border-t-0 px-4 align-middle text-xs whitespace-nowrap p-4">
<a href="{{ url_for('show_topset_from_workout_for_person', person_id=person_id, workout_id=workout_id, topset_id=t['TopSetId']) }}"
<a href="{{ url_for('get_topset', person_id=workout['PersonId'], workout_id=workout['WorkoutId'], topset_id=t['TopSetId']) }}"
class="text-sm font-medium text-cyan-600 hover:bg-gray-100 rounded-lg inline-flex items-center p-2">
Edit
</a>
<a href="{{ url_for('delete_topset_from_workout_for_person', person_id=person_id, workout_id=workout_id, topset_id=t['TopSetId'])}}"
<a href="{{ url_for('delete_topset', person_id=workout['PersonId'], workout_id=workout['WorkoutId'], topset_id=t['TopSetId'])}}"
class="text-sm font-medium text-cyan-600 hover:bg-gray-100 rounded-lg inline-flex items-center p-2">
Delete
</a>
@@ -68,7 +68,7 @@
<div class="bg-white shadow rounded-lg p-4 sm:p-6 xl:p-8 2xl:col-span-2 mt-4">
<div class=" ">
<form class="w-full max-w-lg"
action="{{ url_for('add_topset_to_workout_for_person', person_id=person_id, workout_id=workout_id) }}"
action="{{ url_for('create_topset', person_id=workout['PersonId'], workout_id=workout['WorkoutId']) }}"
method="post">
<div class="flex flex-wrap -mx-3 mb-2">
@@ -80,7 +80,7 @@
<select
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"
id="grid-state" name="exercise_id">
{% for e in exercises %}
{% for e in workout['Exercises'] %}
<option value="{{ e['ExcerciseId'] }}">{{
e['Name']}}</option>
{% endfor %}

View File

@@ -6,7 +6,7 @@
<div class="mb-4 flex items-center justify-between">
<div>
<h3 class="text-xl font-bold text-gray-900 mb-2">{{ person['Name'] }}</h3>
<h3 class="text-xl font-bold text-gray-900 mb-2">{{ person['PersonName'] }}</h3>
<span class="text-base font-normal text-gray-500">List of workouts</span>
</div>
</div>
@@ -22,10 +22,10 @@
class="p-4 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Date
</th>
{% for e in exercises %}
{% for e in person['Exercises'] %}
<th scope="col"
class="p-4 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
{{ e['Name'] }}
{{ e['ExerciseName'] }}
</th>
{% endfor %}
<th scope="col"
@@ -35,28 +35,31 @@
</thead>
<tbody class="bg-white">
{% for w in workouts %}
{% for w in person['Workouts'] %}
<tr>
<td class="p-4 whitespace-nowrap text-sm font-normal text-gray-500">
{{ w['start_date'] }}
{{ w['StartDate'] }}
</td>
{% for e in exercises %}
{% for e in person['Exercises'] %}
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
{% if e['ExcerciseId'] in w['topset_exercises'] %}
{{ w['topset_exercises'][e['ExcerciseId']] }}
{% set topset_exercise =
get_first_element_from_list_with_matching_attribute(w['TopSets'], 'ExcerciseId',
e['ExcerciseId']) %}
{% if topset_exercise %}
{{ topset_exercise['Repetitions'] }} x {{ topset_exercise['Weight'] }}kg
{% endif %}
</td>
{% endfor %}
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
<a href="{{ url_for('show_workout_for_person' ,person_id=person_id, workout_id=w['workout_id']) }}"
<a href="{{ url_for('get_workout' ,person_id=person['PersonId'], workout_id=w['WorkoutId']) }}"
class="text-sm font-medium text-cyan-600 hover:bg-gray-100 rounded-lg inline-flex items-center p-2">
Edit
</a>
<form
action="{{ url_for('delete_workout_from_person', person_id=person_id, workout_id=w['workout_id']) }}"
action="{{ url_for('delete_workout', person_id=person['PersonId'], workout_id=w['WorkoutId']) }}"
method="delete" class="inline">
<button
class="text-sm font-medium text-cyan-600 hover:bg-gray-100 rounded-lg inline-flex items-center p-2"
@@ -69,7 +72,7 @@
</tbody>
</table>
<form action="{{ url_for('new_workout_for_person', person_id=person_id) }}" method="post">
<form action="{{ url_for('create_workout', person_id=person['PersonId']) }}" method="post">
<button
class="sm:inline-flex text-white bg-cyan-600 hover:bg-cyan-700 focus:ring-4 focus:ring-cyan-200 font-medium rounded-lg text-sm px-5 py-2.5 text-center items-center mt-6">New
workout</button>