make sure we update guid in note object too

This commit is contained in:
Damien Elmes 2012-10-27 21:11:16 +09:00
parent bd1c6d4395
commit 29e93f8c1d
4 changed files with 24 additions and 5 deletions

View file

@ -97,9 +97,10 @@ class Anki2Importer(Importer):
note = list(note)
guid, mid = note[1:3]
duplicate = False
guidChange = False
first = True
# do we have the same guid?
if guid in self._notes:
first = False
# and do they share the same model id?
if self._notes[guid][2] == mid:
# and do they share the same schema?
@ -109,9 +110,6 @@ class Anki2Importer(Importer):
self.src.models.scmhash(dstM)):
# then it's safe to treat as a duplicate
duplicate = True
if not duplicate:
# not identical models, so we need to change guid
guidChange = True
# missing from local col or divergent model?
if not duplicate:
# get corresponding local model
@ -129,8 +127,9 @@ class Anki2Importer(Importer):
dirty.append(note[0])
# if it was originally the same as a note in this deck but the
# models have diverged, we need to change the guid
if guidChange:
if not first:
guid = guid64()
note[1] = guid
# note we have the added note
self._notes[guid] = (note[0], note[3], note[2])
else:

Binary file not shown.

Binary file not shown.

View file

@ -158,6 +158,26 @@ def test_anki1_diffmodels():
# as the model schemas differ, should have been imported as new model
assert after == before + 1
def test_anki2_diffmodels():
# create a new empty deck
dst = getEmptyDeck()
# import the 1 card version of the model
tmp = getUpgradeDeckPath("diffmodels2-1.apkg")
imp = AnkiPackageImporter(dst, tmp)
imp.run()
before = dst.noteCount()
# repeating the process should do nothing
imp = AnkiPackageImporter(dst, tmp)
imp.run()
assert before == dst.noteCount()
# then the 2 card version
tmp = getUpgradeDeckPath("diffmodels2-2.apkg")
imp = AnkiPackageImporter(dst, tmp)
imp.run()
after = dst.noteCount()
# as the model schemas differ, should have been imported as new model
assert after == before + 1
def test_csv():
deck = getEmptyDeck()
file = unicode(os.path.join(testDir, "support/text-2fields.txt"))