type answer is now a template replacement

This commit is contained in:
Damien Elmes 2011-11-28 15:15:38 +09:00
parent 223cc48052
commit 1235f8362a
3 changed files with 12 additions and 6 deletions

View file

@ -49,7 +49,6 @@ defaultTemplate = {
'ord': None, 'ord': None,
'qfmt': "", 'qfmt': "",
'afmt': "", 'afmt': "",
'typeAns': None,
'did': None, 'did': None,
} }

View file

@ -157,6 +157,10 @@ class Template(object):
if txt: if txt:
return stripHTML(txt) return stripHTML(txt)
return "" return ""
elif tag_name.startswith("type:"):
# type answer field; convert it to [[type:...]] for the gui code
# to process
return "[[%s]]" % tag_name
elif (tag_name.startswith("cq:") or elif (tag_name.startswith("cq:") or
tag_name.startswith("ca:") or tag_name.startswith("ca:") or
tag_name.startswith("cactx:")): tag_name.startswith("cactx:")):

View file

@ -374,7 +374,6 @@ order by ordinal""", mid)):
db = self.db db = self.db
dconf = anki.models.defaultTemplate dconf = anki.models.defaultTemplate
tmpls = [] tmpls = []
# align and bg are used in upgrade then discarded
for c, row in enumerate(db.all(""" for c, row in enumerate(db.all("""
select name, active, qformat, aformat, questionInAnswer, select name, active, qformat, aformat, questionInAnswer,
questionAlign, lastFontColour, typeAnswer from cardModels questionAlign, lastFontColour, typeAnswer from cardModels
@ -385,14 +384,12 @@ order by ordinal""", mid)):
conf['actv'], conf['actv'],
conf['qfmt'], conf['qfmt'],
conf['afmt'], conf['afmt'],
# the following are used in upgrade then discarded
hideq, hideq,
conf['align'], conf['align'],
conf['bg'], conf['bg'],
conf['typeAns']) = row typeAns) = row
conf['ord'] = c conf['ord'] = c
# q fields now in a
if not hideq:
conf['afmt'] = conf['qfmt'] + "\n\n<hr>\n\n" + conf['afmt']
for type in ("qfmt", "afmt"): for type in ("qfmt", "afmt"):
# ensure the new style field format # ensure the new style field format
conf[type] = re.sub("%\((.+?)\)s", "{{\\1}}", conf[type]) conf[type] = re.sub("%\((.+?)\)s", "{{\\1}}", conf[type])
@ -403,6 +400,12 @@ order by ordinal""", mid)):
"(?i){{cardModel}}", "{{Template}}", conf[type]) "(?i){{cardModel}}", "{{Template}}", conf[type])
conf[type] = re.sub( conf[type] = re.sub(
"(?i){{modelTags}}", "{{Model}}", conf[type]) "(?i){{modelTags}}", "{{Model}}", conf[type])
# type answer is now embedded in the format
if typeAns:
conf[type] += '{{type:%s}}' % typeAns
# q fields now in a
if not hideq:
conf['afmt'] = conf['qfmt'] + "\n\n<hr>\n\n" + conf['afmt']
tmpls.append(conf) tmpls.append(conf)
return tmpls return tmpls