From 12a80ef9c2ff7a933d15b9c8631eefef4b7c6058 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 25 Apr 2012 13:25:19 +0900 Subject: [PATCH] handle cloze note types in changeModel() --- anki/models.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/anki/models.py b/anki/models.py index 5f0a2f8ef..50f6b5c97 100644 --- a/anki/models.py +++ b/anki/models.py @@ -375,7 +375,7 @@ select id from notes where mid = ?)""" % " ".join(map), if fmap: self._changeNotes(nids, newModel, fmap) if cmap: - self._changeCards(nids, newModel, cmap) + self._changeCards(nids, m, newModel, cmap) self.col.genCards(nids) def _changeNotes(self, nids, newModel, map): @@ -397,14 +397,26 @@ select id from notes where mid = ?)""" % " ".join(map), "update notes set flds=:flds,mid=:mid,mod=:m,usn=:u where id = :nid", d) self.col.updateFieldCache(nids) - def _changeCards(self, nids, newModel, map): + def _changeCards(self, nids, oldModel, newModel, map): d = [] deleted = [] for (cid, ord) in self.col.db.execute( "select id, ord from cards where nid in "+ids2str(nids)): - if map[ord] is not None: + # if the src model is a cloze, we ignore the map, as the gui + # doesn't currently support mapping them + if oldModel['type'] == MODEL_CLOZE: + new = ord + 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: + new = None + else: + # mapping from a regular note, so the map should be valid + new = map[ord] + if new is not None: d.append(dict( - cid=cid,new=map[ord],u=self.col.usn(),m=intTime())) + cid=cid,new=new,u=self.col.usn(),m=intTime())) else: deleted.append(cid) self.col.db.executemany(