mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 01:06:35 -04:00
don't clobber tags if they're not mapped
This commit is contained in:
parent
f2fffce6d1
commit
e3da64f00b
2 changed files with 26 additions and 5 deletions
|
@ -85,6 +85,11 @@ class NoteImporter(Importer):
|
||||||
def importNotes(self, notes):
|
def importNotes(self, notes):
|
||||||
"Convert each card into a note, apply attributes and add to col."
|
"Convert each card into a note, apply attributes and add to col."
|
||||||
assert self.mappingOk()
|
assert self.mappingOk()
|
||||||
|
# note whether tags are mapped
|
||||||
|
self._tagsMapped = False
|
||||||
|
for f in self.mapping:
|
||||||
|
if f == "_tags":
|
||||||
|
self._tagsMapped = True
|
||||||
# gather checks for duplicate comparison
|
# gather checks for duplicate comparison
|
||||||
csums = {}
|
csums = {}
|
||||||
for csum, id in self.col.db.execute(
|
for csum, id in self.col.db.execute(
|
||||||
|
@ -182,16 +187,25 @@ class NoteImporter(Importer):
|
||||||
if not self.processFields(n, sflds):
|
if not self.processFields(n, sflds):
|
||||||
print "no cards generated"
|
print "no cards generated"
|
||||||
return
|
return
|
||||||
|
if self._tagsMapped:
|
||||||
self.col.tags.register(n.tags)
|
self.col.tags.register(n.tags)
|
||||||
tags = self.col.tags.join(n.tags)
|
tags = self.col.tags.join(n.tags)
|
||||||
return [intTime(), self.col.usn(), n.fieldsStr, tags,
|
return [intTime(), self.col.usn(), n.fieldsStr, tags,
|
||||||
id, n.fieldsStr, tags]
|
id, n.fieldsStr, tags]
|
||||||
|
else:
|
||||||
|
return [intTime(), self.col.usn(), n.fieldsStr,
|
||||||
|
id, n.fieldsStr]
|
||||||
|
|
||||||
def addUpdates(self, rows):
|
def addUpdates(self, rows):
|
||||||
old = self.col.db.totalChanges()
|
old = self.col.db.totalChanges()
|
||||||
|
if self._tagsMapped:
|
||||||
self.col.db.executemany("""
|
self.col.db.executemany("""
|
||||||
update notes set mod = ?, usn = ?, flds = ?, tags = ?
|
update notes set mod = ?, usn = ?, flds = ?, tags = ?
|
||||||
where id = ? and (flds != ? or tags != ?)""", rows)
|
where id = ? and (flds != ? or tags != ?)""", rows)
|
||||||
|
else:
|
||||||
|
self.col.db.executemany("""
|
||||||
|
update notes set mod = ?, usn = ?, flds = ?
|
||||||
|
where id = ? and flds != ?""", rows)
|
||||||
self.updateCount = self.col.db.totalChanges() - old
|
self.updateCount = self.col.db.totalChanges() - old
|
||||||
|
|
||||||
def processFields(self, note, fields=None):
|
def processFields(self, note, fields=None):
|
||||||
|
|
|
@ -152,6 +152,13 @@ def test_csv():
|
||||||
i.run()
|
i.run()
|
||||||
assert len(i.log) == 5
|
assert len(i.log) == 5
|
||||||
assert i.total == 5
|
assert i.total == 5
|
||||||
|
# but importing should not clobber tags if they're unmapped
|
||||||
|
n = deck.getNote(deck.db.scalar("select id from notes"))
|
||||||
|
n.addTag("test")
|
||||||
|
n.flush()
|
||||||
|
i.run()
|
||||||
|
n.load()
|
||||||
|
assert n.tags == ['test']
|
||||||
# if updating is disabled, count will be 0
|
# if updating is disabled, count will be 0
|
||||||
i.update = False
|
i.update = False
|
||||||
i.run()
|
i.run()
|
||||||
|
|
Loading…
Reference in a new issue