Add ability to update workout date

This commit is contained in:
Peter Stockings
2022-11-17 22:03:36 +11:00
parent 369b0520ce
commit 65f8ec9658
3 changed files with 35 additions and 3 deletions

7
app.py
View File

@@ -47,6 +47,13 @@ def delete_workout(person_id, workout_id):
return redirect(url_for('get_person', person_id=person_id)) return redirect(url_for('get_person', person_id=person_id))
@ app.route("/person/<int:person_id>/workout/<int:workout_id>", methods=['POST'])
@ validate_workout
def update_workout(person_id, workout_id):
db.update_workout(workout_id, request.form)
return redirect(url_for('get_workout', person_id=person_id, workout_id=workout_id))
@ app.route("/person/<int:person_id>/workout/<int:workout_id>/topset/<int:topset_id>", methods=['GET', 'POST']) @ app.route("/person/<int:person_id>/workout/<int:workout_id>/topset/<int:topset_id>", methods=['GET', 'POST'])
@ validate_topset @ validate_topset
def get_topset(person_id, workout_id, topset_id): def get_topset(person_id, workout_id, topset_id):

6
db.py
View File

@@ -124,6 +124,10 @@ class DataBase():
ORDER BY ORDER BY
P.PersonId""", [person_id]) P.PersonId""", [person_id])
def update_workout(self, workout_id, form):
self.execute('UPDATE Workout SET StartDate=%s WHERE WorkoutId=%s', [
form.get('start-date'), workout_id], commit=True)
def get_person_final(self, person_id): def get_person_final(self, person_id):
topsets = self.execute(""" topsets = self.execute("""
SELECT SELECT
@@ -173,7 +177,7 @@ class DataBase():
'PersonId': next((t['PersonId'] for t in topsets), -1), 'PersonId': next((t['PersonId'] for t in topsets), -1),
'PersonName': next((t['PersonName'] for t in topsets), 'Unknown'), 'PersonName': next((t['PersonName'] for t in topsets), 'Unknown'),
'WorkoutId': workout_id, 'WorkoutId': workout_id,
'StartDate': datetime.strptime(topsets[0]['StartDate'], "%Y-%m-%d").strftime("%b %d %Y"), 'StartDate': datetime.strptime(topsets[0]['StartDate'], "%Y-%m-%d").strftime("%Y-%m-%d"),
'Exercises': self.get_exercises(), 'Exercises': self.get_exercises(),
'TopSets': [{"TopSetId": t['TopSetId'], "ExerciseId": t['ExerciseId'], "ExerciseName": t['ExerciseName'], "Weight": t['Weight'], "Repetitions": t['Repetitions']} for t in topsets if t['TopSetId'] is not None] 'TopSets': [{"TopSetId": t['TopSetId'], "ExerciseId": t['ExerciseId'], "ExerciseName": t['ExerciseName'], "Weight": t['Weight'], "Repetitions": t['Repetitions']} for t in topsets if t['TopSetId'] is not None]
} }

View File

@@ -7,7 +7,28 @@
<div class="mb-4 flex items-center justify-between"> <div class="mb-4 flex items-center justify-between">
<div> <div>
<h3 class="text-xl font-bold text-gray-900 mb-2">{{ workout['PersonName'] }}</h3> <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> <form
action="{{ url_for('update_workout', person_id=workout['PersonId'], workout_id=workout['WorkoutId']) }}"
method="post">
<div class="relative">
<div class="flex absolute inset-y-0 left-0 items-center pl-3 pointer-events-none">
<svg aria-hidden="true" class="w-5 h-5 text-gray-500 dark:text-gray-400" fill="currentColor"
viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd"
d="M6 2a1 1 0 00-1 1v1H4a2 2 0 00-2 2v10a2 2 0 002 2h12a2 2 0 002-2V6a2 2 0 00-2-2h-1V3a1 1 0 10-2 0v1H7V3a1 1 0 00-1-1zm0 5a1 1 0 000 2h8a1 1 0 100-2H6z"
clip-rule="evenodd"></path>
</svg>
</div>
<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 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
name="start-date" value="{{ workout['StartDate'] }}">
</div>
<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-4"
type="submit">Update</button>
</form>
</div> </div>
<form action="{{ url_for('delete_workout', person_id=workout['PersonId'], workout_id=workout['WorkoutId']) }}" <form action="{{ url_for('delete_workout', person_id=workout['PersonId'], workout_id=workout['WorkoutId']) }}"
method="delete"> method="delete">
@@ -118,7 +139,7 @@
</label> </label>
<input <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" 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"
id="grid-zip" type="number" name="weight"> id="grid-zip" type="number" name="weight" step="any">
</div> </div>
</div> </div>
<button <button