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,18 +216,27 @@ flds %s like :_text_%d escape '\\')""" % (extra, c, extra, c))
except: except:
num = None num = None
lims = [] lims = []
for m in self.col.models.all(): # were we given an ordinal number?
for t in m['tmpls']: if num is not None:
# ordinal number? found = True
if num is not None and t['ord'] == num: self.lims['preds'].append("ord %s %d" % (comp, num))
self.lims['preds'].append("ord %s %d" % (comp, num)) else:
found = True # search for template names
# template name? for m in self.col.models.all():
elif t['name'].lower() == val.lower(): for t in m['tmpls']:
lims.append(( # template name?
"(nid in (select id from notes where mid = %s) " if t['name'].lower() == val.lower():
"and ord %s %d)") % (m['id'], comp, t['ord'])) if m['type'] == MODEL_CLOZE:
found = True # 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((
"(nid in (select id from notes where mid = %s) "
"and ord %s %d)") % (m['id'], comp, t['ord']))
found = True
if lims: if lims:
self.lims['preds'].append("(" + " or ".join(lims) + ")") self.lims['preds'].append("(" + " or ".join(lims) + ")")
self.lims['valid'] = found self.lims['valid'] = found