log updates & duplicates (#859)

This commit is contained in:
Damien Elmes 2013-05-16 17:19:11 +09:00
parent a7b9a7b055
commit 3dd72ad4d6
2 changed files with 7 additions and 1 deletions

View file

@ -109,6 +109,9 @@ class NoteImporter(Importer):
self._nextID = timestampID(self.col.db, "notes")
# loop through the notes
updates = []
updateLog = []
updateLogTxt = _("Update as first field matched: %s")
dupeLogTxt = _("Added duplicate with first field: %s")
new = []
self._ids = []
self._cards = []
@ -146,10 +149,12 @@ class NoteImporter(Importer):
data = self.updateData(n, id, sflds)
if data:
updates.append(data)
updateLog.append(updateLogTxt % fld0)
found = True
break
elif self.importMode == 2:
# allow duplicates in this case
updateLog.append(dupeLogTxt % fld0)
found = False
# newly add
if not found:
@ -171,6 +176,7 @@ class NoteImporter(Importer):
part1 = ngettext("%d note added", "%d notes added", len(new)) % len(new)
part2 = ngettext("%d note updated", "%d notes updated", self.updateCount) % self.updateCount
self.log.append("%s, %s." % (part1, part2))
self.log.extend(updateLog)
if self._emptyNotes:
self.log.append(_("""\
One or more notes were not imported, because they didn't generate any cards. \

View file

@ -213,7 +213,7 @@ def test_csv():
assert i.total == 5
# if we run the import again, it should update instead
i.run()
assert len(i.log) == 5
assert len(i.log) == 10
assert i.total == 5
# but importing should not clobber tags if they're unmapped
n = deck.getNote(deck.db.scalar("select id from notes"))