Anki/anki/stdmodels.py
Damien Elmes b5c0b1f2c7 drop required/unique field properties
Instead of having required and unique flags for every field, enforce both
requirements on the first field, and neither on the rest. This mirrors the
subject/body format people are used to in note-taking apps. The subject
defines the object being learnt, and the remaining fields represent properties
of that object.

In the past, duplicate checking served two purposes: it quickly notified the
user that they're entering the same fact twice, and it notified the user if
they'd accidentally mistyped a secondary field. The former behaviour is
important for avoiding wasted effort, and so it should be done in real time.
The latter behaviour is not essential however - a typo is not wasted effort,
and it could be fixed in a periodic 'find duplicates' function. Given that
some users ended up with sluggish decks due to the overhead a large number of
facts * a large number of unique fields caused, this seems like a change for
the better.

This also means Anki will let you add notes as long as as the first field has
been filled out. Again, this is not a big deal: Anki is still checking to make
sure one or more cards will be generated, and the user can easily add any
missing fields later.

As a bonus, this change simplifies field configuration somewhat. As the card
layout and field dialogs are a popular point of confusion, the more they can
be simplified, the better.
2011-11-24 22:16:03 +09:00

49 lines
1.3 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(col):
mm = col.models
m = mm.new(_("Basic"))
fm = mm.newField(_("Front"))
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(col):
mm = col.models
m = mm.new(_("Cloze"))
fm = mm.newField(_("Text"))
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))