513
513
frozenset(['date', 'text']),
514
514
frozenset(['problemid', 'loginid']))
516
def get_problem_stored_text(self, login, exercisename, dry=False):
517
"""Given a login name and exercise name, returns the text of the
518
last saved/submitted attempt for this question.
519
Returns None if the user has not saved or made an attempt on this
521
(If the user has both saved and submitted, it returns whichever was
524
Note: Even if dry, will still physically call get_problem_problemid,
525
which may mutate the DB, and get_user_loginid, which may fail.
527
problemid = self.get_problem_problemid(exercisename)
528
loginid = self.get_user_loginid(login) # May raise a DBException
529
# This very complex query finds all submissions made by this user for
530
# this problem, as well as the save made by this user for this
531
# problem, and returns the text of the newest one.
532
# (Whichever is newer out of the save or the submit).
533
query = """SELECT text FROM
535
(SELECT * FROM problem_save WHERE loginid = %d AND problemid = %d)
537
(SELECT problemid, loginid, date, text FROM problem_attempt
538
AS problem_attempt (problemid, loginid, date, text)
539
WHERE loginid = %d AND problemid = %d AND active)
543
LIMIT 1;""" % (loginid, problemid, loginid, problemid)
545
result = self.db.query(query)
546
if result.ntuples() == 1:
547
# The user has made at least 1 attempt. Return the newest.
548
return result.getresult()[0][0]
552
516
def get_problem_attempts(self, login, exercisename, allow_inactive=True,
554
518
"""Given a login name and exercise name, returns a list of dicts, one
556
520
Dicts are {'date': 'formatted_time', 'complete': bool}.
557
521
Ordered with the newest first.
559
Note: By default, returns de-activated problem attempts (unlike
560
get_problem_stored_text).
523
Note: By default, returns de-activated problem attempts.
561
524
If allow_inactive is False, will not return disabled attempts.
563
526
Note: Even if dry, will still physically call get_problem_problemid,
582
545
Returns None if the user had not made an attempt on this problem at
585
Note: By default, returns de-activated problem attempts (unlike
586
get_problem_stored_text).
548
Note: By default, returns de-activated problem attempts.
587
549
If allow_inactive is False, will not return disabled attempts.
589
551
Note: Even if dry, will still physically call get_problem_problemid,