From f177083bcbb6a9096968a8e5489000428965cf91 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 20 Mar 2012 05:41:58 +0900 Subject: [PATCH] make importing with an explicit deck work again This change was necessary as we moved away from note decks. However, now that I think about it, decks may not be a terribly useful thing to specify per-line in a text file. Committing in case the code is needed later, but I will revert in the next commit. --- anki/importing/noteimp.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/anki/importing/noteimp.py b/anki/importing/noteimp.py index 83532b2b0..10e5aff02 100644 --- a/anki/importing/noteimp.py +++ b/anki/importing/noteimp.py @@ -100,6 +100,7 @@ class NoteImporter(Importer): new = [] self._ids = [] self._cards = [] + self._cdecks = [] for n in notes: fld0 = n.fields[fld0idx] csum = fieldChecksum(fld0) @@ -140,8 +141,9 @@ class NoteImporter(Importer): self.col.updateFieldCache(self._ids) # generate cards assert not self.col.genCards(self._ids) - # apply scheduling updates + # apply scheduling updates and decks self.updateCards() + self.updateDecks() # make sure to update sflds, etc self.total = len(self._ids) @@ -155,6 +157,10 @@ class NoteImporter(Importer): # note id for card updates later for ord, c in n.cards.items(): self._cards.append((id, ord, c)) + # did they override the default deck? + if n.deck: + did = self.col.decks.id(n.deck) + self._cdecks.append((did, id)) self.col.tags.register(n.tags) return [id, guid64(), self.model['id'], intTime(), self.col.usn(), self.col.tags.join(n.tags), @@ -204,3 +210,7 @@ where id = ? and (flds != ? or tags != ?)""", rows) self.col.db.executemany(""" update cards set type = 2, queue = 2, ivl = ?, due = ?, factor = ?, reps = ?, lapses = ? where nid = ? and ord = ?""", data) + + def updateDecks(self): + self.col.db.executemany( + "update cards set did = ? where nid = ?", self._cdecks)