From 0e2637a9996e66860caeb110ca0462e67f9e0aa9 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sun, 6 May 2012 01:55:18 +0900 Subject: [PATCH] when cram deck removed, cards in learning need to be reset --- anki/sched.py | 7 +++++-- tests/test_sched.py | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/anki/sched.py b/anki/sched.py index 5b9a7ce9f..9bb8fd196 100644 --- a/anki/sched.py +++ b/anki/sched.py @@ -770,9 +770,12 @@ did = ? and queue = 2 and due <= ? limit ?""", def remDyn(self, did, lim=None): if not lim: lim = "did = %s" % did + # move out of cram queue self.col.db.execute(""" -update cards set did = odid, queue = type, due = odue, odue = 0, odid = 0, -usn = ?, mod = ? where %s""" % lim, self.col.usn(), intTime()) +update cards set did = odid, queue = (case when type = 1 then 0 +else type end), type = (case when type = 1 then 0 else type end), +due = odue, odue = 0, odid = 0, usn = ?, mod = ? where %s""" % lim, + self.col.usn(), intTime()) def remFromDyn(self, cids): self.remDyn(None, "id in %s and odid" % ids2str(cids)) diff --git a/tests/test_sched.py b/tests/test_sched.py index 6a89afad8..ea0894853 100644 --- a/tests/test_sched.py +++ b/tests/test_sched.py @@ -577,6 +577,26 @@ def test_cram(): # it should have been moved back to the original deck assert c.did == 1 +def test_cram_rem(): + d = getEmptyDeck() + f = d.newNote() + f['Front'] = u"one" + d.addNote(f) + oldDue = f.cards()[0].due + did = d.decks.newDyn("Cram") + d.sched.rebuildDyn(did) + d.reset() + c = d.sched.getCard() + d.sched.answerCard(c, 2) + # answering the card will put it in the learning queue + assert c.type == c.queue == 1 + assert c.due != oldDue + # if we terminate cramming prematurely it should be set back to new + d.sched.remDyn(did) + c.load() + assert c.type == c.queue == 0 + assert c.due == oldDue + def test_adjIvl(): d = getEmptyDeck() # add two more templates and set second active