support {{CardFlag}}

https://anki.tenderapp.com/discussions/ankidesktop/32158-flags
This commit is contained in:
Damien Elmes 2019-02-05 12:51:16 +10:00
parent d57511713c
commit 867e4b9f94
3 changed files with 13 additions and 6 deletions

View file

@ -129,7 +129,7 @@ lapses=?, left=?, odue=?, odid=?, did=? where id = ?""",
if not self._qa or reload: if not self._qa or reload:
f = self.note(reload); m = self.model(); t = self.template() f = self.note(reload); m = self.model(); t = self.template()
data = [self.id, f.id, m['id'], self.odid or self.did, self.ord, data = [self.id, f.id, m['id'], self.odid or self.did, self.ord,
f.stringTags(), f.joinedFields()] f.stringTags(), f.joinedFields(), self.flags]
if browser: if browser:
args = (t.get('bqfmt'), t.get('bafmt')) args = (t.get('bqfmt'), t.get('bafmt'))
else: else:

View file

@ -549,7 +549,7 @@ where c.nid = n.id and c.id in %s group by nid""" % ids2str(cids)):
def _renderQA(self, data, qfmt=None, afmt=None): def _renderQA(self, data, qfmt=None, afmt=None):
"Returns hash of id, question, answer." "Returns hash of id, question, answer."
# data is [cid, nid, mid, did, ord, tags, flds] # data is [cid, nid, mid, did, ord, tags, flds, cardFlags]
# unpack fields and create dict # unpack fields and create dict
flist = splitFields(data[6]) flist = splitFields(data[6])
fields = {} fields = {}
@ -560,6 +560,7 @@ where c.nid = n.id and c.id in %s group by nid""" % ids2str(cids)):
fields['Type'] = model['name'] fields['Type'] = model['name']
fields['Deck'] = self.decks.name(data[3]) fields['Deck'] = self.decks.name(data[3])
fields['Subdeck'] = fields['Deck'].split('::')[-1] fields['Subdeck'] = fields['Deck'].split('::')[-1]
fields['CardFlag'] = self._flagNameFromCardFlags(data[7])
if model['type'] == MODEL_STD: if model['type'] == MODEL_STD:
template = model['tmpls'][data[4]] template = model['tmpls'][data[4]]
else: else:
@ -593,13 +594,19 @@ where c.nid = n.id and c.id in %s group by nid""" % ids2str(cids)):
return d return d
def _qaData(self, where=""): def _qaData(self, where=""):
"Return [cid, nid, mid, did, ord, tags, flds] db query" "Return [cid, nid, mid, did, ord, tags, flds, cardFlags] db query"
return self.db.execute(""" return self.db.execute("""
select c.id, f.id, f.mid, c.did, c.ord, f.tags, f.flds select c.id, f.id, f.mid, c.did, c.ord, f.tags, f.flds, c.flags
from cards c, notes f from cards c, notes f
where c.nid == f.id where c.nid == f.id
%s""" % where) %s""" % where)
def _flagNameFromCardFlags(self, flags):
flag = flags & 0b111
if not flag:
return ""
return "flag%d" % flag
# Finding cards # Finding cards
########################################################################## ##########################################################################

View file

@ -503,9 +503,9 @@ select id from notes where mid = ?)""" % " ".join(map),
for f in flds: for f in flds:
a.append("ankiflag") a.append("ankiflag")
b.append("") b.append("")
data = [1, 1, m['id'], 1, t['ord'], "", joinFields(a)] data = [1, 1, m['id'], 1, t['ord'], "", joinFields(a), 0]
full = self.col._renderQA(data)['q'] full = self.col._renderQA(data)['q']
data = [1, 1, m['id'], 1, t['ord'], "", joinFields(b)] data = [1, 1, m['id'], 1, t['ord'], "", joinFields(b), 0]
empty = self.col._renderQA(data)['q'] empty = self.col._renderQA(data)['q']
# if full and empty are the same, the template is invalid and there is # if full and empty are the same, the template is invalid and there is
# no way to satisfy it # no way to satisfy it