From 1235f8362aaaed04241547bb4bfcafc8ca990dea Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 28 Nov 2011 15:15:38 +0900 Subject: [PATCH] type answer is now a template replacement --- anki/models.py | 1 - anki/template/template.py | 4 ++++ anki/upgrade.py | 13 ++++++++----- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/anki/models.py b/anki/models.py index 950514932..efc7461ec 100644 --- a/anki/models.py +++ b/anki/models.py @@ -49,7 +49,6 @@ defaultTemplate = { 'ord': None, 'qfmt': "", 'afmt': "", - 'typeAns': None, 'did': None, } diff --git a/anki/template/template.py b/anki/template/template.py index a165b4799..ec9c67b40 100644 --- a/anki/template/template.py +++ b/anki/template/template.py @@ -157,6 +157,10 @@ class Template(object): if txt: return stripHTML(txt) 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 tag_name.startswith("ca:") or tag_name.startswith("cactx:")): diff --git a/anki/upgrade.py b/anki/upgrade.py index c574f17f2..56a432ccd 100644 --- a/anki/upgrade.py +++ b/anki/upgrade.py @@ -374,7 +374,6 @@ order by ordinal""", mid)): db = self.db dconf = anki.models.defaultTemplate tmpls = [] - # align and bg are used in upgrade then discarded for c, row in enumerate(db.all(""" select name, active, qformat, aformat, questionInAnswer, questionAlign, lastFontColour, typeAnswer from cardModels @@ -385,14 +384,12 @@ order by ordinal""", mid)): conf['actv'], conf['qfmt'], conf['afmt'], + # the following are used in upgrade then discarded hideq, conf['align'], conf['bg'], - conf['typeAns']) = row + typeAns) = row conf['ord'] = c - # q fields now in a - if not hideq: - conf['afmt'] = conf['qfmt'] + "\n\n
\n\n" + conf['afmt'] for type in ("qfmt", "afmt"): # ensure the new style field format conf[type] = re.sub("%\((.+?)\)s", "{{\\1}}", conf[type]) @@ -403,6 +400,12 @@ order by ordinal""", mid)): "(?i){{cardModel}}", "{{Template}}", conf[type]) conf[type] = re.sub( "(?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
\n\n" + conf['afmt'] tmpls.append(conf) return tmpls