63
63
return first_success is not None, num_attempts
65
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
66
"""Given a storm.store, User and Exercise, returns an
67
ivle.database.ExerciseSave object for the last saved/submitted attempt for
68
this question (note that ExerciseAttempt is a subclass of ExerciseSave).
70
69
Returns None if the user has not saved or made an attempt on this
72
71
If the user has both saved and submitted, it returns whichever was
101
def _get_exercise_attempts(store, user, exercise, as_of=None,
102
allow_inactive=False):
103
"""Same as get_exercise_attempts, but doesn't convert Storm's iterator
105
ExerciseAttempt = ivle.database.ExerciseAttempt
107
# Get the most recent attempt before as_of, or None
108
return store.find(ExerciseAttempt,
109
ExerciseAttempt.user_id == user.id,
110
ExerciseAttempt.exercise_id == exercise.id,
111
True if allow_inactive else ExerciseAttempt.active == True,
112
True if as_of is None else ExerciseAttempt.date <= as_of,
113
).order_by(Desc(ExerciseAttempt.date))
115
def get_exercise_attempts(store, user, exercise, as_of=None,
116
allow_inactive=False):
117
"""Given a storm.store, User and Exercise, returns a list of
118
ivle.database.ExerciseAttempt objects, one for each attempt made for the
119
exercise, sorted from latest to earliest.
121
as_of: Optional datetime.datetime object. If supplied, only returns
122
attempts made before or at this time.
123
allow_inactive: If True, will return disabled attempts.
125
return list(_get_exercise_attempts(store, user, exercise, as_of,
128
def get_exercise_attempt(store, user, exercise, as_of=None,
129
allow_inactive=False):
130
"""Given a storm.store, User and Exercise, returns an
131
ivle.database.ExerciseAttempt object for the last submitted attempt for
133
Returns None if the user has not made an attempt on this
136
as_of: Optional datetime.datetime object. If supplied, only returns
137
attempts made before or at this time.
138
allow_inactive: If True, will return disabled attempts.
140
return _get_exercise_attempts(store, user, exercise, as_of,
141
allow_inactive).first()