From 55812bef86da469ab4198f6647ea5e9b7ab7c2fb Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 17 Apr 2012 22:53:48 +0900 Subject: [PATCH] remove cards from cram decks and the relearning queue on suspend --- anki/sched.py | 14 ++++++++++++-- tests/test_sched.py | 13 +++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/anki/sched.py b/anki/sched.py index a6a003231..58438fcb5 100644 --- a/anki/sched.py +++ b/anki/sched.py @@ -747,10 +747,15 @@ did = ? and queue = 2 and due <= ? limit ?""", # and change to our new deck self.col.decks.select(did) - def remDyn(self, did): + def remDyn(self, did, lim=None): + if not lim: + lim = "did = %d" % did self.col.db.execute(""" update cards set did = odid, queue = type, due = odue, odue = 0, odid = 0, -usn = ?, mod = ? where did = ?""", self.col.usn(), intTime(), did) +usn = ?, mod = ? where %s""" % lim, self.col.usn(), intTime()) + + def remFromDyn(self, cids): + self.remDyn(None, "id in %s and odid" % ids2str(cids)) def _dynOrder(self, deck): o = deck['order'] @@ -994,6 +999,8 @@ your short-term review workload will become.""")) def suspendCards(self, ids): "Suspend cards." + self.remFromDyn(ids) + self.removeFailed(ids) self.col.db.execute( "update cards set queue=-1,mod=?,usn=? where id in "+ ids2str(ids), intTime(), self.col.usn()) @@ -1008,6 +1015,9 @@ your short-term review workload will become.""")) def buryNote(self, nid): "Bury all cards for note until next session." self.col.setDirty() + cids = self.col.db.list("select id from cards where nid = ?", nid) + self.remFromDyn(cids) + self.removeFailed(cids) self.col.db.execute("update cards set queue = -2 where nid = ?", nid) # Resetting diff --git a/tests/test_sched.py b/tests/test_sched.py index ab6d93039..d0df38c22 100644 --- a/tests/test_sched.py +++ b/tests/test_sched.py @@ -450,6 +450,19 @@ def test_suspend(): c.load() assert c.queue == 2 assert c.type == 2 + assert c.due == 1 + # should cope with cards in cram decks + c.due = 0 + c.flush() + cram = d.decks.newDyn("tmp") + d.sched.rebuildDyn() + c.load() + assert c.due != 1 + assert c.did != 1 + d.sched.suspendCards([c.id]) + c.load() + assert c.due == 1 + assert c.did == 1 def test_cram(): d = getEmptyDeck()