95
99
# The time *should* be in the same format as the DB (since it should
96
100
# be bounced back to us from the getattempts output). Assume this.
98
date = time.strptime(date, db.TIMESTAMP_FORMAT)
102
date = datetime.datetime.strptime(date, db.TIMESTAMP_FORMAT)
99
103
except ValueError:
100
104
# Date was not in correct format
101
105
req.throw_error(req.HTTP_BAD_REQUEST)
176
180
req.write(cjson.encode(test_results))
178
def handle_getattempts(req, exercise):
182
def handle_getattempts(req, exercisename):
179
183
"""Handles a getattempts action."""
182
attempts = conn.get_problem_attempts(
183
login=req.user.login,
184
exercisename=exercise,
185
allow_inactive=HISTORY_ALLOW_INACTIVE)
186
req.write(cjson.encode(attempts))
184
exercise = ivle.database.Exercise.get_by_name(req.store, exercisename)
185
attempts = ivle.worksheet.get_exercise_attempts(req.store, req.user,
186
exercise, allow_inactive=HISTORY_ALLOW_INACTIVE)
187
# attempts is a list of ExerciseAttempt objects. Convert to dictionaries.
188
time_fmt = lambda dt: datetime.datetime.strftime(dt, db.TIMESTAMP_FORMAT)
189
attempts = [{'date': time_fmt(a.date), 'complete': a.complete}
191
req.write(cjson.encode(attempts))
190
def handle_getattempt(req, exercise, date):
191
"""Handles a getattempts action. Date is a struct_time."""
193
def handle_getattempt(req, exercisename, date):
194
"""Handles a getattempts action. Date is a datetime.datetime."""
194
attempt = conn.get_problem_attempt(
195
login=req.user.login,
196
exercisename=exercise,
198
allow_inactive=HISTORY_ALLOW_INACTIVE)
199
# attempt may be None; will write "null"
200
req.write(cjson.encode({'code': attempt}))
196
exercise = ivle.database.Exercise.get_by_name(req.store, exercisename)
197
attempt = ivle.worksheet.get_exercise_attempt(req.store, req.user,
198
exercise, as_of=date, allow_inactive=HISTORY_ALLOW_INACTIVE)
199
if attempt is not None:
200
attempt = attempt.text
201
# attempt may be None; will write "null"
202
req.write(cjson.encode({'code': attempt}))