mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 00:36:38 -04:00
distinguish between buried siblings and manually buried cards
This commit is contained in:
parent
62c1fa4a17
commit
4e52f43365
3 changed files with 84 additions and 28 deletions
|
@ -16,7 +16,7 @@ from anki.hooks import runHook
|
||||||
|
|
||||||
# card types: 0=new, 1=lrn, 2=rev, 3=relrn
|
# card types: 0=new, 1=lrn, 2=rev, 3=relrn
|
||||||
# queue types: 0=new, 1=(re)lrn, 2=rev, 3=day (re)lrn,
|
# queue types: 0=new, 1=(re)lrn, 2=rev, 3=day (re)lrn,
|
||||||
# 4=preview, -1=suspended, -2=buried
|
# 4=preview, -1=suspended, -2=sibling buried, -3=manually buried
|
||||||
# revlog types: 0=lrn, 1=rev, 2=relrn, 3=cram
|
# revlog types: 0=lrn, 1=rev, 2=relrn, 3=cram
|
||||||
# positive revlog intervals are in days (rev), negative in seconds (lrn)
|
# positive revlog intervals are in days (rev), negative in seconds (lrn)
|
||||||
# odue/odid store original due/did when cards moved to filtered deck
|
# odue/odid store original due/did when cards moved to filtered deck
|
||||||
|
@ -1198,6 +1198,7 @@ did = ?, due = ?, usn = ? where id = ?
|
||||||
unburied = self.col.conf.get("lastUnburied", 0)
|
unburied = self.col.conf.get("lastUnburied", 0)
|
||||||
if unburied < self.today:
|
if unburied < self.today:
|
||||||
self.unburyCards()
|
self.unburyCards()
|
||||||
|
self.col.conf['lastUnburied'] = self.today
|
||||||
|
|
||||||
def _checkDay(self):
|
def _checkDay(self):
|
||||||
# check if the day has rolled over
|
# check if the day has rolled over
|
||||||
|
@ -1252,12 +1253,21 @@ To study outside of the normal schedule, click the Custom Study button below."""
|
||||||
("select 1 from cards where did in %s and queue = 0 "
|
("select 1 from cards where did in %s and queue = 0 "
|
||||||
"limit 1") % self._deckLimit())
|
"limit 1") % self._deckLimit())
|
||||||
|
|
||||||
def haveBuried(self):
|
def haveBuriedSiblings(self):
|
||||||
sdids = ids2str(self.col.decks.active())
|
sdids = ids2str(self.col.decks.active())
|
||||||
cnt = self.col.db.scalar(
|
cnt = self.col.db.scalar(
|
||||||
"select 1 from cards where queue = -2 and did in %s limit 1" % sdids)
|
"select 1 from cards where queue = -2 and did in %s limit 1" % sdids)
|
||||||
return not not cnt
|
return not not cnt
|
||||||
|
|
||||||
|
def haveManuallyBuried(self):
|
||||||
|
sdids = ids2str(self.col.decks.active())
|
||||||
|
cnt = self.col.db.scalar(
|
||||||
|
"select 1 from cards where queue = -3 and did in %s limit 1" % sdids)
|
||||||
|
return not not cnt
|
||||||
|
|
||||||
|
def haveBuried(self):
|
||||||
|
return self.haveManuallyBuried() or self.haveBuriedSiblings()
|
||||||
|
|
||||||
# Next time reports
|
# Next time reports
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
@ -1344,11 +1354,12 @@ end)
|
||||||
"where queue = -1 and id in %s") % (self._restoreQueueSnippet, ids2str(ids)),
|
"where queue = -1 and id in %s") % (self._restoreQueueSnippet, ids2str(ids)),
|
||||||
intTime(), self.col.usn())
|
intTime(), self.col.usn())
|
||||||
|
|
||||||
def buryCards(self, cids):
|
def buryCards(self, cids, manual=True):
|
||||||
|
queue = manual and -3 or -2
|
||||||
self.col.log(cids)
|
self.col.log(cids)
|
||||||
self.col.db.execute("""
|
self.col.db.execute("""
|
||||||
update cards set queue=-2,mod=?,usn=? where id in """+ids2str(cids),
|
update cards set queue=?,mod=?,usn=? where id in """+ids2str(cids),
|
||||||
intTime(), self.col.usn())
|
queue, intTime(), self.col.usn())
|
||||||
|
|
||||||
def buryNote(self, nid):
|
def buryNote(self, nid):
|
||||||
"Bury all cards for note until next session."
|
"Bury all cards for note until next session."
|
||||||
|
@ -1357,21 +1368,29 @@ update cards set queue=-2,mod=?,usn=? where id in """+ids2str(cids),
|
||||||
self.buryCards(cids)
|
self.buryCards(cids)
|
||||||
|
|
||||||
def unburyCards(self):
|
def unburyCards(self):
|
||||||
"Unbury cards."
|
"Unbury all buried cards in all decks."
|
||||||
self.col.conf['lastUnburied'] = self.today
|
|
||||||
self.col.log(
|
self.col.log(
|
||||||
self.col.db.list("select id from cards where queue = -2"))
|
self.col.db.list("select id from cards where queue in (-2, -3)"))
|
||||||
self.col.db.execute(
|
self.col.db.execute(
|
||||||
"update cards set %s where queue = -2" % self._restoreQueueSnippet)
|
"update cards set %s where queue in (-2, -3)" % self._restoreQueueSnippet)
|
||||||
|
|
||||||
|
def unburyCardsForDeck(self, type="all"):
|
||||||
|
if type == "all":
|
||||||
|
queue = "queue in (-2, -3)"
|
||||||
|
elif type == "manual":
|
||||||
|
queue = "queue = -3"
|
||||||
|
elif type == "siblings":
|
||||||
|
queue = "queue = -2"
|
||||||
|
else:
|
||||||
|
raise Exception("unknown type")
|
||||||
|
|
||||||
def unburyCardsForDeck(self):
|
|
||||||
sids = ids2str(self.col.decks.active())
|
sids = ids2str(self.col.decks.active())
|
||||||
self.col.log(
|
self.col.log(
|
||||||
self.col.db.list("select id from cards where queue = -2 and did in %s"
|
self.col.db.list("select id from cards where %s and did in %s"
|
||||||
% sids))
|
% (queue, sids)))
|
||||||
self.col.db.execute(
|
self.col.db.execute(
|
||||||
"update cards set mod=?,usn=?,%s where queue = -2 and did in %s"
|
"update cards set mod=?,usn=?,%s where %s and did in %s"
|
||||||
% (self._restoreQueueSnippet, sids), intTime(), self.col.usn())
|
% (self._restoreQueueSnippet, queue, sids), intTime(), self.col.usn())
|
||||||
|
|
||||||
# Sibling spacing
|
# Sibling spacing
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
@ -1405,10 +1424,7 @@ and (queue=0 or (queue=2 and due<=?))""",
|
||||||
pass
|
pass
|
||||||
# then bury
|
# then bury
|
||||||
if toBury:
|
if toBury:
|
||||||
self.col.db.execute(
|
self.buryCards(toBury, manual=False)
|
||||||
"update cards set queue=-2,mod=?,usn=? where id in "+ids2str(toBury),
|
|
||||||
intTime(), self.col.usn())
|
|
||||||
self.col.log(toBury)
|
|
||||||
|
|
||||||
# Resetting
|
# Resetting
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
# Copyright: Damien Elmes <anki@ichi2.net>
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
from aqt.utils import openLink, shortcut, tooltip
|
from aqt.utils import openLink, shortcut, tooltip, askUserDialog
|
||||||
from anki.utils import isMac
|
from anki.utils import isMac
|
||||||
import aqt
|
import aqt
|
||||||
from anki.sound import clearAudioQueue
|
from anki.sound import clearAudioQueue
|
||||||
|
@ -57,8 +57,7 @@ class Overview:
|
||||||
elif url == "studymore":
|
elif url == "studymore":
|
||||||
self.onStudyMore()
|
self.onStudyMore()
|
||||||
elif url == "unbury":
|
elif url == "unbury":
|
||||||
self.mw.col.sched.unburyCardsForDeck()
|
self.onUnbury()
|
||||||
self.mw.reset()
|
|
||||||
elif url.lower().startswith("http"):
|
elif url.lower().startswith("http"):
|
||||||
openLink(url)
|
openLink(url)
|
||||||
return False
|
return False
|
||||||
|
@ -69,7 +68,7 @@ class Overview:
|
||||||
("r", self.onRebuildKey),
|
("r", self.onRebuildKey),
|
||||||
("e", self.onEmptyKey),
|
("e", self.onEmptyKey),
|
||||||
("c", self.onCustomStudyKey),
|
("c", self.onCustomStudyKey),
|
||||||
("u", self.onUnburyKey)
|
("u", self.onUnbury)
|
||||||
]
|
]
|
||||||
|
|
||||||
def _filteredDeck(self):
|
def _filteredDeck(self):
|
||||||
|
@ -89,8 +88,28 @@ class Overview:
|
||||||
if not self._filteredDeck():
|
if not self._filteredDeck():
|
||||||
self.onStudyMore()
|
self.onStudyMore()
|
||||||
|
|
||||||
def onUnburyKey(self):
|
def onUnbury(self):
|
||||||
self.mw.col.sched.unburyCardsForDeck()
|
sibs = self.mw.col.sched.haveBuriedSiblings()
|
||||||
|
man = self.mw.col.sched.haveManuallyBuried()
|
||||||
|
|
||||||
|
if sibs and man:
|
||||||
|
opts = [_("Manually Buried Cards"),
|
||||||
|
_("Buried Siblings"),
|
||||||
|
_("All Buried Cards"),
|
||||||
|
_("Cancel")]
|
||||||
|
|
||||||
|
diag = askUserDialog(_("What would you like to unbury?"), opts)
|
||||||
|
diag.setDefault(0)
|
||||||
|
ret = diag.run()
|
||||||
|
if ret == opts[0]:
|
||||||
|
self.mw.col.sched.unburyCardsForDeck(type="manual")
|
||||||
|
elif ret == opts[1]:
|
||||||
|
self.mw.col.sched.unburyCardsForDeck(type="siblings")
|
||||||
|
elif ret == opts[2]:
|
||||||
|
self.mw.col.sched.unburyCardsForDeck(type="all")
|
||||||
|
else:
|
||||||
|
self.mw.col.sched.unburyCardsForDeck(type="all")
|
||||||
|
|
||||||
self.mw.reset()
|
self.mw.reset()
|
||||||
|
|
||||||
# HTML
|
# HTML
|
||||||
|
|
|
@ -478,19 +478,40 @@ def test_nextIvl():
|
||||||
assert ni(c, 4) == 28080000
|
assert ni(c, 4) == 28080000
|
||||||
assert d.sched.nextIvlStr(c, 4) == "10.8 months"
|
assert d.sched.nextIvlStr(c, 4) == "10.8 months"
|
||||||
|
|
||||||
def test_misc():
|
def test_bury():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
f = d.newNote()
|
||||||
f['Front'] = "one"
|
f['Front'] = "one"
|
||||||
d.addNote(f)
|
d.addNote(f)
|
||||||
c = f.cards()[0]
|
c = f.cards()[0]
|
||||||
|
f = d.newNote()
|
||||||
|
f['Front'] = "two"
|
||||||
|
d.addNote(f)
|
||||||
|
c2 = f.cards()[0]
|
||||||
# burying
|
# burying
|
||||||
d.sched.buryNote(c.nid)
|
d.sched.buryCards([c.id], manual=True)
|
||||||
|
c.load()
|
||||||
|
assert c.queue == -3
|
||||||
|
d.sched.buryCards([c2.id], manual=False)
|
||||||
|
c2.load()
|
||||||
|
assert c2.queue == -2
|
||||||
|
|
||||||
d.reset()
|
d.reset()
|
||||||
assert not d.sched.getCard()
|
assert not d.sched.getCard()
|
||||||
d.sched.unburyCards()
|
|
||||||
|
d.sched.unburyCardsForDeck(type="manual")
|
||||||
|
c.load(); assert c.queue == 0
|
||||||
|
c2.load(); assert c2.queue == -2
|
||||||
|
|
||||||
|
d.sched.unburyCardsForDeck(type="siblings")
|
||||||
|
c2.load(); assert c2.queue == 0
|
||||||
|
|
||||||
|
d.sched.buryCards([c.id, c2.id])
|
||||||
|
d.sched.unburyCardsForDeck(type="all")
|
||||||
|
|
||||||
d.reset()
|
d.reset()
|
||||||
assert d.sched.getCard()
|
|
||||||
|
assert d.sched.counts() == (2, 0, 0)
|
||||||
|
|
||||||
def test_suspend():
|
def test_suspend():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
|
|
Loading…
Reference in a new issue