Anki/anki/stdmodels.py
Damien Elmes ed75e4bee2 refactor cloze deletions and text:field, add forecast
Previously cloze deletions were handled by copying the contents of one field
into another and applying transforms to it. This had a number of problems:
- after you add a card, you can't undo the cloze deletion
- if you spot a mistake, you have to edit it twice (or more if you have more
  than one cloze for a sentence)
- making multiple clozes requires copying & pasting the sentence multiple
  times
- this also lead to much bigger decks if the sentences being cloze-deleted are
  large
- related clozes can't be spaced apart as siblings

To address these issues, we introduce the idea of cloze tags in the card
template and fields. If the template has the text:

{{cloze:1:field}}

And a field has the following contents:

{{c1::hello}}

Then the template will automatically replace that part of the text with either
occluded text, or a highlighted answer. All other clozes in the field are
displayed normally.

At the same time, we add support for text: into the template library, instead
of manually creating text: fields in the dict for every field.

Finally, add a forecast routine to get the due counts for the next week, which
is used in the GUI.
2011-04-28 09:23:56 +09:00

64 lines
1.6 KiB
Python

# -*- coding: utf-8 -*-
# Copyright: Damien Elmes <anki@ichi2.net>
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
from anki.models import Model
from anki.lang import _
models = []
# Basic
##########################################################################
def BasicModel(deck):
m = Model(deck)
m.name = _("Basic")
fm = m.newField()
fm['name'] = _("Front")
fm['req'] = True
fm['uniq'] = True
m.addField(fm)
fm = m.newField()
fm['name'] = _("Back")
m.addField(fm)
t = m.newTemplate()
t['name'] = _("Forward")
t['qfmt'] = "{{" + _("Front") + "}}"
t['afmt'] = "{{" + _("Back") + "}}"
m.addTemplate(t)
t = m.newTemplate()
t['name'] = _("Reverse")
t['qfmt'] = "{{" + _("Back") + "}}"
t['afmt'] = "{{" + _("Front") + "}}"
t['actv'] = False
m.addTemplate(t)
return m
models.append(BasicModel)
# Cloze
##########################################################################
def ClozeModel(deck):
m = Model(deck)
m.name = _("Cloze")
fm = m.newField()
fm['name'] = _("Text")
fm['req'] = True
fm['uniq'] = True
m.addField(fm)
fm = m.newField()
fm['name'] = _("Notes")
m.addField(fm)
for i in range(8):
n = i+1
t = m.newTemplate()
t['name'] = _("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") + "}}"
m.addTemplate(t)
return m
models.append(ClozeModel)