Ensure workouts are printed in order of start date descending

This commit is contained in:
Peter Stockings
2022-12-07 20:56:12 +11:00
parent 14ecae99e4
commit dac5e99f05
2 changed files with 5 additions and 0 deletions

2
app.py
View File

@@ -299,6 +299,8 @@ def my_utility_processor():
return db.get_people_and_workout_count(person_id)
def get_first_element_from_list_with_matching_attribute(list, attribute, value):
if not list:
return None
for element in list:
if element[attribute] == value:
return element

View File

@@ -17,6 +17,9 @@ def get_workouts(topsets):
'StartDate': topsets_in_workout[0]['StartDate'],
'TopSets': [{"TopSetId": t['TopSetId'], "ExerciseId": t['ExerciseId'], "ExerciseName": t['ExerciseName'], "Weight": t['Weight'], "Repetitions": t['Repetitions']} for t in topsets_in_workout if t['TopSetId'] is not None]
})
workouts.sort(key=lambda x: x['StartDate'], reverse=True)
return workouts