add the ability to reverse sort order

This commit is contained in:
Damien Elmes 2011-04-11 19:42:06 +09:00
parent 6617214708
commit d089deae5a
3 changed files with 10 additions and 3 deletions

View file

@ -31,7 +31,7 @@ defaultQconf = {
'timeLim': 600,
}
# scheduling and other options
# other options
defaultConf = {
'currentModelId': None,
'currentGroupId': 1,
@ -52,7 +52,8 @@ defaultConf = {
'latexPost': "\\end{document}",
'fontFamilies': [
[u' 明朝',u'ヒラギノ明朝 Pro W3',u'Kochi Mincho', u'東風明朝']
]
],
'sortBackwards': False,
}
# this is initialized by storage.Deck

View file

@ -30,7 +30,10 @@ class Finder(object):
return []
(q, args) = self._whereClause()
query = self._orderedSelect(sort, q)
return self.deck.db.list(query, **args)
res = self.deck.db.list(query, **args)
if self.deck.conf['sortBackwards']:
res.reverse()
return res
def _whereClause(self):
x = []

View file

@ -84,6 +84,9 @@ def test_findCards():
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['sortBackwards'] = True
assert deck.findCards("", sort="cardMod")[0] == c.id
# model
assert len(deck.findCards("model:basic")) == 5
assert len(deck.findCards("-model:basic")) == 0