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:
f = self.note(reload); m = self.model(); t = self.template()
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:
args = (t.get('bqfmt'), t.get('bafmt'))
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):
"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
flist = splitFields(data[6])
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['Deck'] = self.decks.name(data[3])
fields['Subdeck'] = fields['Deck'].split('::')[-1]
fields['CardFlag'] = self._flagNameFromCardFlags(data[7])
if model['type'] == MODEL_STD:
template = model['tmpls'][data[4]]
else:
@ -593,13 +594,19 @@ where c.nid = n.id and c.id in %s group by nid""" % ids2str(cids)):
return d
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("""
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
where c.nid == f.id
%s""" % where)
def _flagNameFromCardFlags(self, flags):
flag = flags & 0b111
if not flag:
return ""
return "flag%d" % flag
# Finding cards
##########################################################################

View file

@ -503,9 +503,9 @@ select id from notes where mid = ?)""" % " ".join(map),
for f in flds:
a.append("ankiflag")
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']
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']
# if full and empty are the same, the template is invalid and there is
# no way to satisfy it