fix card:<n> and card:cloze in cloze types

This commit is contained in:
Damien Elmes 2012-04-24 02:30:02 +09:00
parent 92472045d7
commit 5514b75d6b

View file

@ -4,6 +4,7 @@
import re import re
from anki.utils import ids2str, splitFields, joinFields, stripHTML, intTime from anki.utils import ids2str, splitFields, joinFields, stripHTML, intTime
from anki.consts import *
SEARCH_TAG = 0 SEARCH_TAG = 0
SEARCH_TYPE = 1 SEARCH_TYPE = 1
@ -215,14 +216,23 @@ flds %s like :_text_%d escape '\\')""" % (extra, c, extra, c))
except: except:
num = None num = None
lims = [] lims = []
# were we given an ordinal number?
if num is not None:
found = True
self.lims['preds'].append("ord %s %d" % (comp, num))
else:
# search for template names
for m in self.col.models.all(): for m in self.col.models.all():
for t in m['tmpls']: for t in m['tmpls']:
# ordinal number?
if num is not None and t['ord'] == num:
self.lims['preds'].append("ord %s %d" % (comp, num))
found = True
# template name? # template name?
elif t['name'].lower() == val.lower(): if t['name'].lower() == val.lower():
if m['type'] == MODEL_CLOZE:
# if the user has asked for a cloze card, we want
# to give all ordinals, so we just limit to the
# model instead
lims.append("(mid = %s)" % m['id'])
found = True
else:
lims.append(( lims.append((
"(nid in (select id from notes where mid = %s) " "(nid in (select id from notes where mid = %s) "
"and ord %s %d)") % (m['id'], comp, t['ord'])) "and ord %s %d)") % (m['id'], comp, t['ord']))