mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00

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.
55 lines
1.5 KiB
Python
55 lines
1.5 KiB
Python
# coding: utf-8
|
|
|
|
import time
|
|
from anki.db import DB
|
|
from anki.consts import *
|
|
from anki.utils import hexifyID
|
|
from tests.shared import getEmptyDeck
|
|
|
|
def test_previewCards():
|
|
deck = getEmptyDeck()
|
|
f = deck.newNote()
|
|
f['Front'] = u'1'
|
|
f['Back'] = u'2'
|
|
# non-empty and active
|
|
cards = deck.previewCards(f, 0)
|
|
assert len(cards) == 1
|
|
assert cards[0].ord == 0
|
|
# all templates
|
|
cards = deck.previewCards(f, 2)
|
|
assert len(cards) == 1
|
|
# add the note, and test existing preview
|
|
deck.addNote(f)
|
|
cards = deck.previewCards(f, 1)
|
|
assert len(cards) == 1
|
|
assert cards[0].ord == 0
|
|
# make sure we haven't accidentally added cards to the db
|
|
assert deck.cardCount() == 1
|
|
|
|
def test_delete():
|
|
deck = getEmptyDeck()
|
|
f = deck.newNote()
|
|
f['Front'] = u'1'
|
|
f['Back'] = u'2'
|
|
deck.addNote(f)
|
|
cid = f.cards()[0].id
|
|
deck.reset()
|
|
deck.sched.answerCard(deck.sched.getCard(), 2)
|
|
assert deck.db.scalar("select count() from revlog") == 1
|
|
deck.remCards([cid])
|
|
assert deck.cardCount() == 0
|
|
assert deck.noteCount() == 0
|
|
assert deck.db.scalar("select count() from notes") == 0
|
|
assert deck.db.scalar("select count() from cards") == 0
|
|
assert deck.db.scalar("select count() from revlog") == 0
|
|
assert deck.db.scalar("select count() from graves") == 2
|
|
|
|
def test_misc():
|
|
d = getEmptyDeck()
|
|
f = d.newNote()
|
|
f['Front'] = u'1'
|
|
f['Back'] = u'2'
|
|
d.addNote(f)
|
|
c = f.cards()[0]
|
|
id = d.models.current()['id']
|
|
assert c.template()['ord'] == 0
|