From 57a96683508989be5c5e34b6ef9a0e88786b2671 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 5 Jul 2012 05:39:25 +0900 Subject: [PATCH] fix cloze->basic model changing --- anki/models.py | 2 +- tests/test_models.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/anki/models.py b/anki/models.py index 8ede3a643..cf1d7c644 100644 --- a/anki/models.py +++ b/anki/models.py @@ -422,7 +422,7 @@ select id from notes where mid = ?)""" % " ".join(map), if newModel['type'] != MODEL_CLOZE: # if we're mapping to a regular note, we need to check if # the destination ord is valid - if len(newModel['flds']) <= ord: + if len(newModel['tmpls']) <= ord: new = None else: # mapping from a regular note, so the map should be valid diff --git a/tests/test_models.py b/tests/test_models.py index 918c24f67..79fad3af1 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -231,6 +231,11 @@ def test_modelChange(): f.load() assert f['Text'] == "f2" assert len(f.cards()) == 2 + # back the other way, with deletion of second ord + deck.models.remTemplate(basic, basic['tmpls'][1]) + assert deck.db.scalar("select count() from cards where nid = ?", f.id) == 2 + deck.models.change(cloze, [f.id], basic, map, map) + assert deck.db.scalar("select count() from cards where nid = ?", f.id) == 1 def test_availOrds(): d = getEmptyDeck()