mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
custom browser q/a columns
This commit is contained in:
parent
5aa840e848
commit
233bf555b4
3 changed files with 16 additions and 7 deletions
|
@ -122,8 +122,8 @@ lapses=?, left=?, odue=?, odid=?, did=? where id = ?""",
|
|||
self.factor, self.reps, self.lapses,
|
||||
self.left, self.odue, self.odid, self.did, self.id)
|
||||
|
||||
def q(self, reload=False):
|
||||
return self.css() + self._getQA(reload)['q']
|
||||
def q(self, reload=False, browser=False):
|
||||
return self.css() + self._getQA(reload, browser)['q']
|
||||
|
||||
def a(self):
|
||||
return self.css() + self._getQA()['a']
|
||||
|
@ -131,12 +131,16 @@ lapses=?, left=?, odue=?, odid=?, did=? where id = ?""",
|
|||
def css(self):
|
||||
return "<style>%s</style>" % self.model()['css']
|
||||
|
||||
def _getQA(self, reload=False):
|
||||
def _getQA(self, reload=False, browser=False):
|
||||
if not self._qa or reload:
|
||||
f = self.note(reload); m = self.model()
|
||||
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()]
|
||||
self._qa = self.col._renderQA(data)
|
||||
if browser:
|
||||
args = (t.get('bqfmt'), t.get('bafmt'))
|
||||
else:
|
||||
args = tuple()
|
||||
self._qa = self.col._renderQA(data, *args)
|
||||
return self._qa
|
||||
|
||||
def note(self, reload=False):
|
||||
|
|
|
@ -463,7 +463,7 @@ where c.nid = n.id and c.id in %s group by nid""" % ids2str(cids)):
|
|||
return [self._renderQA(row)
|
||||
for row in self._qaData(where)]
|
||||
|
||||
def _renderQA(self, data):
|
||||
def _renderQA(self, data, qfmt=None, afmt=None):
|
||||
"Returns hash of id, question, answer."
|
||||
# data is [cid, nid, mid, did, ord, tags, flds]
|
||||
# unpack fields and create dict
|
||||
|
@ -483,7 +483,9 @@ where c.nid = n.id and c.id in %s group by nid""" % ids2str(cids)):
|
|||
fields['c%d' % (data[4]+1)] = "1"
|
||||
# render q & a
|
||||
d = dict(id=data[0])
|
||||
for (type, format) in (("q", template['qfmt']), ("a", template['afmt'])):
|
||||
qfmt = qfmt or template['qfmt']
|
||||
afmt = afmt or template['afmt']
|
||||
for (type, format) in (("q", qfmt), ("a", afmt)):
|
||||
if type == "q":
|
||||
format = format.replace("{{cloze:", "{{cq:%d:" % (
|
||||
data[4]+1))
|
||||
|
|
|
@ -59,6 +59,9 @@ defaultTemplate = {
|
|||
'qfmt': "",
|
||||
'afmt': "",
|
||||
'did': None,
|
||||
# added in beta 13
|
||||
'bqfmt': "",
|
||||
'bafmt': "",
|
||||
}
|
||||
|
||||
class ModelManager(object):
|
||||
|
|
Loading…
Reference in a new issue