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

Like the previous change, models have been moved from a separate DB table to an entry in the deck. We need them for many operations including reviewing, and it's easier to keep them in memory than half on disk with a cache that gets cleared every time we .reset(). This means they are easily serialized as well - previously they were part Python and part JSON, which made access confusing. Because the data is all pulled from JSON now, the instance methods have been moved to the model registry. Eg: model.addField(...) -> deck.models.addField(model, ...). - IDs are now timestamped as with groups et al. - The data field for plugins was also removed. Config info can be added to deck.conf; larger data should be stored externally. - Upgrading needs to be updated for the new model structure. - HexifyID() now accepts strings as well, as our IDs get converted to strings in the serialization process.
58 lines
1.6 KiB
Python
58 lines
1.6 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)
|
|
t = mm.newTemplate(_("Reverse"))
|
|
t['qfmt'] = "{{" + _("Back") + "}}"
|
|
t['afmt'] = "{{" + _("Front") + "}}"
|
|
t['actv'] = False
|
|
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))
|