mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00

The old template handling was too complicated, and generated frequent questions on the forums. By dropping non-active templates we can do away with the generate cards function, and advanced users can simulate the old behaviour by using conditional field templates.
53 lines
1.4 KiB
Python
53 lines
1.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
from anki.lang import _
|
|
|
|
models = []
|
|
|
|
# Basic
|
|
##########################################################################
|
|
|
|
def addBasicModel(deck):
|
|
mm = deck.models
|
|
m = mm.new(_("Basic"))
|
|
fm = mm.newField(_("Front"))
|
|
fm['req'] = True
|
|
fm['uniq'] = True
|
|
mm.addField(m, fm)
|
|
fm = mm.newField(_("Back"))
|
|
mm.addField(m, fm)
|
|
t = mm.newTemplate(_("Forward"))
|
|
t['qfmt'] = "{{" + _("Front") + "}}"
|
|
t['afmt'] = "{{" + _("Back") + "}}"
|
|
mm.addTemplate(m, t)
|
|
mm.save(m)
|
|
return m
|
|
|
|
models.append((_("Basic"), addBasicModel))
|
|
|
|
# Cloze
|
|
##########################################################################
|
|
|
|
def addClozeModel(deck):
|
|
mm = deck.models
|
|
m = mm.new(_("Cloze"))
|
|
fm = mm.newField(_("Text"))
|
|
fm['req'] = True
|
|
fm['uniq'] = True
|
|
mm.addField(m, fm)
|
|
fm = mm.newField(_("Notes"))
|
|
mm.addField(m, fm)
|
|
for i in range(8):
|
|
n = i+1
|
|
t = mm.newTemplate(_("Cloze") + " %d" % n)
|
|
t['qfmt'] = ("{{#cloze:%d:Text}}<br>{{cloze:%d:%s}}<br>"+
|
|
"{{/cloze:%d:Text}}") % (n, n, _("Text"), n)
|
|
t['afmt'] = ("{{cloze:%d:" + _("Text") + "}}") % n
|
|
t['afmt'] += "<br>{{" + _("Notes") + "}}"
|
|
mm.addTemplate(m, t)
|
|
mm.save(m)
|
|
return m
|
|
|
|
models.append((_("Cloze"), addClozeModel))
|