mirror of
https://github.com/ankitects/anki.git
synced 2025-09-22 07:52:24 -04:00
use the sort property set in the deck
This commit is contained in:
parent
d089deae5a
commit
2a225b1fae
3 changed files with 21 additions and 13 deletions
|
@ -53,6 +53,7 @@ defaultConf = {
|
|||
'fontFamilies': [
|
||||
[u'MS 明朝',u'ヒラギノ明朝 Pro W3',u'Kochi Mincho', u'東風明朝']
|
||||
],
|
||||
'sortType': "factFld",
|
||||
'sortBackwards': False,
|
||||
}
|
||||
|
||||
|
@ -633,9 +634,9 @@ update facts set tags = :t, mod = :n where id = :id""", [fix(row) for row in res
|
|||
# Finding cards
|
||||
##########################################################################
|
||||
|
||||
def findCards(self, query, sort=None):
|
||||
def findCards(self, query):
|
||||
import anki.find
|
||||
return anki.find.Finder(self).findCards(query, sort)
|
||||
return anki.find.Finder(self).findCards(query)
|
||||
|
||||
def findReplace(self, *args, **kwargs):
|
||||
import anki.find
|
||||
|
|
10
anki/find.py
10
anki/find.py
|
@ -22,14 +22,15 @@ class Finder(object):
|
|||
def __init__(self, deck):
|
||||
self.deck = deck
|
||||
|
||||
def findCards(self, query, sort=None):
|
||||
def findCards(self, query):
|
||||
"Return a list of card ids for QUERY."
|
||||
self.query = query
|
||||
self._findLimits()
|
||||
if not self.lims['valid']:
|
||||
return []
|
||||
(q, args) = self._whereClause()
|
||||
query = self._orderedSelect(sort, q)
|
||||
query = self._orderedSelect(q)
|
||||
print query, args
|
||||
res = self.deck.db.list(query, **args)
|
||||
if self.deck.conf['sortBackwards']:
|
||||
res.reverse()
|
||||
|
@ -47,7 +48,8 @@ class Finder(object):
|
|||
q = "1"
|
||||
return q, self.lims['args']
|
||||
|
||||
def _orderedSelect(self, type, lim):
|
||||
def _orderedSelect(self, lim):
|
||||
type = self.deck.conf['sortType']
|
||||
if not type:
|
||||
return "select id from cards c where " + lim
|
||||
elif type.startswith("fact"):
|
||||
|
@ -60,7 +62,7 @@ class Finder(object):
|
|||
else:
|
||||
raise Exception()
|
||||
return """
|
||||
select c.id from cards c, facts f where %s and c.id=f.id
|
||||
select c.id from cards c, facts f where %s and c.fid=f.id
|
||||
order by %s""" % (lim, sort)
|
||||
elif type.startswith("card"):
|
||||
if type == "cardMod":
|
||||
|
|
|
@ -9,6 +9,7 @@ def test_findCards():
|
|||
f['Back'] = u'cat'
|
||||
f.tags.append(u"monkey")
|
||||
deck.addFact(f)
|
||||
firstCardId = f.cards()[0].id
|
||||
f = deck.newFact()
|
||||
f['Front'] = u'goats are fun'
|
||||
f['Back'] = u'sheep'
|
||||
|
@ -24,6 +25,7 @@ def test_findCards():
|
|||
f['Back'] = u'foo bar'
|
||||
f.model().templates[1]['actv'] = True
|
||||
deck.addFact(f)
|
||||
latestCardIds = [c.id for c in f.cards()]
|
||||
# tag searches
|
||||
assert not deck.findCards("tag:donkey")
|
||||
assert len(deck.findCards("tag:sheep")) == 1
|
||||
|
@ -79,14 +81,17 @@ def test_findCards():
|
|||
assert len(deck.findCards("-back:sheep")) == 3
|
||||
assert len(deck.findCards("front:")) == 5
|
||||
# ordering
|
||||
assert deck.findCards("front:", sort="factCrt")[-1] == c.id
|
||||
assert deck.findCards("", sort="factCrt")[-1] == c.id
|
||||
assert deck.findCards("", sort="factFld")[0] == catCard.id
|
||||
assert deck.findCards("", sort="factFld")[-1] == c.id
|
||||
assert deck.findCards("", sort="cardMod")[-1] == c.id
|
||||
assert not deck.findCards("", sort="cardMod")[0] == c.id
|
||||
deck.conf['sortType'] = "factCrt"
|
||||
assert deck.findCards("front:")[-1] in latestCardIds
|
||||
assert deck.findCards("")[-1] in latestCardIds
|
||||
deck.conf['sortType'] = "factFld"
|
||||
assert deck.findCards("")[0] == catCard.id
|
||||
assert deck.findCards("")[-1] in latestCardIds
|
||||
deck.conf['sortType'] = "cardMod"
|
||||
assert deck.findCards("")[-1] in latestCardIds
|
||||
assert deck.findCards("")[0] == firstCardId
|
||||
deck.conf['sortBackwards'] = True
|
||||
assert deck.findCards("", sort="cardMod")[0] == c.id
|
||||
assert deck.findCards("")[0] in latestCardIds
|
||||
# model
|
||||
assert len(deck.findCards("model:basic")) == 5
|
||||
assert len(deck.findCards("-model:basic")) == 0
|
||||
|
|
Loading…
Reference in a new issue