def generate_new_workouts(user, move_to_next_week=True): user.workout_logger = WorkoutLogger.for_user(user) user.workout_logger.log_start() old_framework = DayFrameworkCollection.get_for_user(user) if move_to_next_week: # added the option to backfill workouts in case of a bug user.move_to_next_week() day_framework_collection = _generate_day_frameworks(user) user.workout_logger.log_initial_day_framework_collection(day_framework_collection) new_workouts = _generate_workouts(user, day_framework_collection) workout_collection = WorkoutCollection(new_workouts, day_framework_collection) _swap_empty_workouts(workout_collection) _swap_one_cardio_day(workout_collection) for workout in workout_collection.workout_list: _trim_to_time(workout, user) old_framework.delete() user.workout_logger.log_end() user.workout_logger.commit() return workout_collection