61
61
num_attempts = store.find(ExerciseAttempt, is_relevant).count()
63
63
return first_success is not None, num_attempts
65
def get_exercise_stored_text(store, user, exercise):
66
"""Given a storm.store, User and Exercise, returns the text of the last
67
saved/submitted attempt for this question, as an
68
ivle.database.ExerciseSave object (note that ExerciseAttempt is a subclass
70
Returns None if the user has not saved or made an attempt on this
72
If the user has both saved and submitted, it returns whichever was
75
ExerciseSave = ivle.database.ExerciseSave
76
ExerciseAttempt = ivle.database.ExerciseAttempt
78
# Get the saved text, or None
79
saved = store.find(ExerciseSave,
80
ExerciseSave.user_id == user.id,
81
ExerciseSave.exercise_id == exercise.id).one()
83
# Get the most recent attempt, or None
84
attempt = store.find(ExerciseAttempt,
85
ExerciseAttempt.user_id == user.id,
86
ExerciseAttempt.exercise_id == exercise.id,
87
ExerciseAttempt.active == True,
88
).order_by(Asc(ExerciseAttempt.date)).last()
90
# Pick the most recent of these two
92
if attempt is not None:
93
return saved if saved.date > attempt.date else attempt
97
if attempt is not None: