diff --git a/anki/importing/noteimp.py b/anki/importing/noteimp.py index df74a41f1..fe8c7d853 100644 --- a/anki/importing/noteimp.py +++ b/anki/importing/noteimp.py @@ -115,10 +115,11 @@ class NoteImporter(Importer): for id in csums[csum]: flds = self.col.db.scalar( "select flds from notes where id = ?", id) - if fld0 == splitFields(flds)[0]: + sflds = splitFields(flds) + if fld0 == sflds[0]: # duplicate if self.update: - data = self.updateData(n, id) + data = self.updateData(n, id, sflds) if data: updates.append(data) # note that we've seen this note once already @@ -162,9 +163,9 @@ class NoteImporter(Importer): rows) # need to document that deck is ignored in this case - def updateData(self, n, id): + def updateData(self, n, id, sflds): self._ids.append(id) - if not self.processFields(n): + if not self.processFields(n, sflds): print "no cards generated" return self.col.tags.register(n.tags) @@ -177,8 +178,9 @@ class NoteImporter(Importer): update notes set mod = ?, usn = ?, flds = ?, tags = ? where id = ? and (flds != ? or tags != ?)""", rows) - def processFields(self, note): - fields = [""]*len(self.model['flds']) + def processFields(self, note, fields=None): + if not fields: + fields = [""]*len(self.model['flds']) for c, f in enumerate(self.mapping): if not f: continue diff --git a/tests/support/text-update.txt b/tests/support/text-update.txt index f87113172..5253c89d1 100644 --- a/tests/support/text-update.txt +++ b/tests/support/text-update.txt @@ -1,11 +1 @@ -# this is a test file - -食べる to ate -む to drink -テスト testing -to eat 食べる -飲む to drink -多すぎる too many fields -not, enough, fields -遊ぶ - to play +1 x diff --git a/tests/test_importing.py b/tests/test_importing.py index c5170961c..5422065a2 100644 --- a/tests/test_importing.py +++ b/tests/test_importing.py @@ -96,6 +96,29 @@ def test_csv(): assert i.total == 0 deck.close() +def test_csv2(): + deck = getEmptyDeck() + mm = deck.models + m = mm.current() + f = mm.newField("Three") + mm.addField(m, f) + mm.save(m) + n = deck.newNote() + n['Front'] = "1" + n['Back'] = "2" + n['Three'] = "3" + deck.addNote(n) + # an update with unmapped fields should not clobber those fields + file = unicode(os.path.join(testDir, "support/text-update.txt")) + i = TextImporter(deck, file) + i.initMapping() + i.run() + n.load() + assert n['Front'] == "1" + assert n['Back'] == "x" + assert n['Three'] == "3" + deck.close() + def test_supermemo_xml_01_unicode(): deck = getEmptyDeck() file = unicode(os.path.join(testDir, "support/supermemo1.xml"))