From 9fc3f17f5cd203532298913daad226709acf8c25 Mon Sep 17 00:00:00 2001 From: Arthur Milchior Date: Thu, 30 Jan 2020 19:40:51 -0800 Subject: [PATCH] QUEUE_TYPE_SIBLING_BURIED --- pylib/anki/consts.py | 1 + pylib/anki/find.py | 2 +- pylib/anki/sched.py | 16 ++++++++-------- pylib/anki/schedv2.py | 5 ++--- pylib/tests/test_schedv2.py | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/pylib/anki/consts.py b/pylib/anki/consts.py index 363ef1b9d..ddeddd03b 100644 --- a/pylib/anki/consts.py +++ b/pylib/anki/consts.py @@ -16,6 +16,7 @@ NEW_CARDS_DUE = 1 # Queue types QUEUE_TYPE_MANUALLY_BURIED = -3 +QUEUE_TYPE_SIBLING_BURIED = -2 QUEUE_TYPE_NEW = 0 QUEUE_TYPE_LRN = 1 diff --git a/pylib/anki/find.py b/pylib/anki/find.py index e44726153..4fbb209b2 100644 --- a/pylib/anki/find.py +++ b/pylib/anki/find.py @@ -278,7 +278,7 @@ select distinct(n.id) from cards c, notes n where c.nid=n.id and """ elif val == "suspended": return "c.queue = -1" elif val == "buried": - return f"c.queue in (-2, {QUEUE_TYPE_MANUALLY_BURIED})" + return f"c.queue in ({QUEUE_TYPE_SIBLING_BURIED}, {QUEUE_TYPE_MANUALLY_BURIED})" elif val == "due": return f""" (c.queue in (2,3) and c.due <= %d) or diff --git a/pylib/anki/sched.py b/pylib/anki/sched.py index 626bf656d..7fcc07257 100644 --- a/pylib/anki/sched.py +++ b/pylib/anki/sched.py @@ -153,18 +153,18 @@ order by due""" def unburyCards(self): "Unbury cards." self.col.conf["lastUnburied"] = self.today - self.col.log(self.col.db.list("select id from cards where queue = -2")) - self.col.db.execute("update cards set queue=type where queue = -2") + self.col.log(self.col.db.list(f"select id from cards where queue = {QUEUE_TYPE_SIBLING_BURIED}")) + self.col.db.execute(f"update cards set queue=type where queue = {QUEUE_TYPE_SIBLING_BURIED}") def unburyCardsForDeck(self): sids = ids2str(self.col.decks.active()) self.col.log( self.col.db.list( - "select id from cards where queue = -2 and did in %s" % sids + f"select id from cards where queue = {QUEUE_TYPE_SIBLING_BURIED} and did in %s" % sids ) ) self.col.db.execute( - "update cards set mod=?,usn=?,queue=type where queue = -2 and did in %s" + f"update cards set mod=?,usn=?,queue=type where queue = {QUEUE_TYPE_SIBLING_BURIED} and did in %s" % sids, intTime(), self.col.usn(), @@ -1328,7 +1328,7 @@ To study outside of the normal schedule, click the Custom Study button below.""" def haveBuried(self): sdids = ids2str(self.col.decks.active()) cnt = self.col.db.scalar( - "select 1 from cards where queue = -2 and did in %s limit 1" % sdids + f"select 1 from cards where queue = {QUEUE_TYPE_SIBLING_BURIED} and did in %s limit 1" % sdids ) return not not cnt @@ -1411,8 +1411,8 @@ To study outside of the normal schedule, click the Custom Study button below.""" self.remFromDyn(cids) self.removeLrn(cids) self.col.db.execute( - """ -update cards set queue=-2,mod=?,usn=? where id in """ + f""" +update cards set queue={QUEUE_TYPE_SIBLING_BURIED},mod=?,usn=? where id in """ + ids2str(cids), intTime(), self.col.usn(), @@ -1462,7 +1462,7 @@ and (queue={QUEUE_TYPE_NEW} or (queue=2 and due<=?))""", # then bury if toBury: self.col.db.execute( - "update cards set queue=-2,mod=?,usn=? where id in " + ids2str(toBury), + f"update cards set queue={QUEUE_TYPE_SIBLING_BURIED},mod=?,usn=? where id in " + ids2str(toBury), intTime(), self.col.usn(), ) diff --git a/pylib/anki/schedv2.py b/pylib/anki/schedv2.py index 0c70e399b..9dc4a4c5d 100644 --- a/pylib/anki/schedv2.py +++ b/pylib/anki/schedv2.py @@ -27,7 +27,6 @@ CARD_TYPE_RELEARNING = 3 # 4=preview, -1=suspended, -2=sibling buried, -3=manually buried QUEUE_TYPE_PREVIEW = 4 QUEUE_TYPE_DAY_LEARN_RELEARN = 3 -QUEUE_TYPE_SIBLING_BURIED = -2 # revlog types: 0=lrn, 1=rev, 2=relrn, 3=early review # positive revlog intervals are in days (rev), negative in seconds (lrn) @@ -1655,11 +1654,11 @@ update cards set queue=?,mod=?,usn=? where id in """ "Unbury all buried cards in all decks." self.col.log( self.col.db.list( - f"select id from cards where queue in (-2, {QUEUE_TYPE_MANUALLY_BURIED})" + f"select id from cards where queue in ({QUEUE_TYPE_SIBLING_BURIED}, {QUEUE_TYPE_MANUALLY_BURIED})" ) ) self.col.db.execute( - f"update cards set %s where queue in (-2, {QUEUE_TYPE_MANUALLY_BURIED})" + f"update cards set %s where queue in ({QUEUE_TYPE_SIBLING_BURIED}, {QUEUE_TYPE_MANUALLY_BURIED})" % self._restoreQueueSnippet ) diff --git a/pylib/tests/test_schedv2.py b/pylib/tests/test_schedv2.py index 22fef573c..88181b100 100644 --- a/pylib/tests/test_schedv2.py +++ b/pylib/tests/test_schedv2.py @@ -627,7 +627,7 @@ def test_bury(): assert c.queue == QUEUE_TYPE_MANUALLY_BURIED d.sched.buryCards([c2.id], manual=False) # pylint: disable=unexpected-keyword-arg c2.load() - assert c2.queue == -2 + assert c2.queue == QUEUE_TYPE_SIBLING_BURIED d.reset() assert not d.sched.getCard() @@ -636,7 +636,7 @@ def test_bury(): c.load() assert c.queue == QUEUE_TYPE_NEW c2.load() - assert c2.queue == -2 + assert c2.queue == QUEUE_TYPE_SIBLING_BURIED d.sched.unburyCardsForDeck( # pylint: disable=unexpected-keyword-arg type="siblings" @@ -1233,7 +1233,7 @@ def test_moveVersions(): # card should have moved queues c.load() - assert c.queue == -2 + assert c.queue == QUEUE_TYPE_SIBLING_BURIED # and it should be new again when unburied col.sched.unburyCards()