diff --git a/app.py b/app.py index 03660d5..7e92b9f 100644 --- a/app.py +++ b/app.py @@ -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 diff --git a/utils.py b/utils.py index 6fc465a..5f95835 100644 --- a/utils.py +++ b/utils.py @@ -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