fix card state negation

This commit is contained in:
Damien Elmes 2011-04-12 01:52:49 +09:00
parent 437b4780c0
commit 8c1c729544
2 changed files with 9 additions and 6 deletions

View file

@ -124,6 +124,7 @@ order by %s""" % (lim, sort)
"tags %s like :_tag_%d""" % (extra, c))
def _findCardState(self, val, neg):
cond = None
if val in ("rev", "new", "lrn"):
if val == "rev":
n = 2
@ -131,15 +132,16 @@ order by %s""" % (lim, sort)
n = 0
else:
n = 1
self.lims['card'].append("type = %d" % n)
cond = "type = %d" % n
elif val == "suspended":
self.lims['card'].append("queue = -1")
cond = "queue = -1"
elif val == "due":
self.lims['card'].append("(queue = 2 and due <= %d)" %
self.deck.sched.today)
cond = "(queue = 2 and due <= %d)" % self.deck.sched.today
elif val == "recent":
self.lims['card'].append(
"c.id in (select id from cards order by mod desc limit 100)")
cond = "c.id in (select id from cards order by mod desc limit 100)"
if neg:
cond = "not (%s)" % cond
self.lims['card'].append(cond)
def _findText(self, val, neg, c):
val = val.replace("*", "%")

View file

@ -58,6 +58,7 @@ def test_findCards():
c.due = 0; c.queue = 2
c.flush()
assert deck.findCards("is:due") == [c.id]
assert len(deck.findCards("-is:due")) == 4
c.queue = -1
# ensure this card gets a later mod time
import time; time.sleep(1)