mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
update note type on apkg import when only templates have changed
Previously, it only updated if card/note count was different, even if the templates / styling information had been updated.
This commit is contained in:
parent
0c937074eb
commit
c3434ff751
4 changed files with 26 additions and 0 deletions
|
@ -190,6 +190,11 @@ class Anki2Importer(Importer):
|
|||
dstScm = self.dst.models.scmhash(dstModel)
|
||||
if srcScm == dstScm:
|
||||
# they do; we can reuse this mid
|
||||
model = srcModel.copy()
|
||||
model['id'] = mid
|
||||
model['mod'] = intTime()
|
||||
model['usn'] = self.col.usn()
|
||||
self.dst.models.update(model)
|
||||
break
|
||||
# as they don't match, try next id
|
||||
mid += 1
|
||||
|
|
BIN
tests/support/diffmodeltemplates-1.apkg
Normal file
BIN
tests/support/diffmodeltemplates-1.apkg
Normal file
Binary file not shown.
BIN
tests/support/diffmodeltemplates-2.apkg
Normal file
BIN
tests/support/diffmodeltemplates-2.apkg
Normal file
Binary file not shown.
|
@ -204,6 +204,27 @@ def test_anki2_diffmodels():
|
|||
assert after == before + 1
|
||||
assert dst.cardCount() == 3
|
||||
|
||||
def test_anki2_diffmodel_templates():
|
||||
# different from the above as this one tests only the template text being
|
||||
# changed, not the number of cards/fields
|
||||
dst = getEmptyCol()
|
||||
# import the first version of the model
|
||||
tmp = getUpgradeDeckPath("diffmodeltemplates-1.apkg")
|
||||
imp = AnkiPackageImporter(dst, tmp)
|
||||
imp.dupeOnSchemaChange = True
|
||||
imp.run()
|
||||
# then the version with updated template
|
||||
tmp = getUpgradeDeckPath("diffmodeltemplates-2.apkg")
|
||||
imp = AnkiPackageImporter(dst, tmp)
|
||||
imp.dupeOnSchemaChange = True
|
||||
imp.run()
|
||||
# collection should contain the note we imported
|
||||
assert(dst.noteCount() == 1)
|
||||
# the front template should contain the text added in the 2nd package
|
||||
tcid = dst.findCards("")[0] # only 1 note in collection
|
||||
tnote = dst.getCard(tcid).note()
|
||||
assert("Changed Front Template" in dst.findTemplates(tnote)[0]['qfmt'])
|
||||
|
||||
def test_anki2_updates():
|
||||
# create a new empty deck
|
||||
dst = getEmptyCol()
|
||||
|
|
Loading…
Reference in a new issue