From ac8f613acadf10318c4e47eade095e69ec35e921 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sun, 28 Nov 2010 02:06:54 +0900 Subject: [PATCH] use pystache for template rendering; autoconvert old style for now --- anki/models.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/anki/models.py b/anki/models.py index 208bb3b17..b794a17a9 100644 --- a/anki/models.py +++ b/anki/models.py @@ -12,7 +12,7 @@ Model - define the way in which facts are added and shown """ -import time +import time, re, pystache from sqlalchemy.ext.orderinglist import ordering_list from anki.db import * from anki.utils import genID, canonifyTags @@ -149,10 +149,11 @@ def formatQA(cid, mid, fact, tags, cm): ret = [] for (type, format) in (("question", cm.qformat), ("answer", cm.aformat)): - try: - html = format % fields - except (KeyError, TypeError, ValueError): - html = _("[invalid question/answer format]") + # convert old style + format = re.sub("%\((.+?)\)s", "{{\\1}}", format) + # allow custom rendering functions & info + fields = runFilter("prepareFields", fields, cid, mid, fact, tags, cm) + html = pystache.render(format, fields) d[type] = runFilter("formatQA", html, type, cid, mid, fact, tags, cm) return d