mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
when updating, preserve unmapped fields
This commit is contained in:
parent
5dc69ecd47
commit
b413b1562a
3 changed files with 32 additions and 17 deletions
|
@ -115,10 +115,11 @@ class NoteImporter(Importer):
|
||||||
for id in csums[csum]:
|
for id in csums[csum]:
|
||||||
flds = self.col.db.scalar(
|
flds = self.col.db.scalar(
|
||||||
"select flds from notes where id = ?", id)
|
"select flds from notes where id = ?", id)
|
||||||
if fld0 == splitFields(flds)[0]:
|
sflds = splitFields(flds)
|
||||||
|
if fld0 == sflds[0]:
|
||||||
# duplicate
|
# duplicate
|
||||||
if self.update:
|
if self.update:
|
||||||
data = self.updateData(n, id)
|
data = self.updateData(n, id, sflds)
|
||||||
if data:
|
if data:
|
||||||
updates.append(data)
|
updates.append(data)
|
||||||
# note that we've seen this note once already
|
# note that we've seen this note once already
|
||||||
|
@ -162,9 +163,9 @@ class NoteImporter(Importer):
|
||||||
rows)
|
rows)
|
||||||
|
|
||||||
# need to document that deck is ignored in this case
|
# 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)
|
self._ids.append(id)
|
||||||
if not self.processFields(n):
|
if not self.processFields(n, sflds):
|
||||||
print "no cards generated"
|
print "no cards generated"
|
||||||
return
|
return
|
||||||
self.col.tags.register(n.tags)
|
self.col.tags.register(n.tags)
|
||||||
|
@ -177,8 +178,9 @@ class NoteImporter(Importer):
|
||||||
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)
|
||||||
|
|
||||||
def processFields(self, note):
|
def processFields(self, note, fields=None):
|
||||||
fields = [""]*len(self.model['flds'])
|
if not fields:
|
||||||
|
fields = [""]*len(self.model['flds'])
|
||||||
for c, f in enumerate(self.mapping):
|
for c, f in enumerate(self.mapping):
|
||||||
if not f:
|
if not f:
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -1,11 +1 @@
|
||||||
# this is a test file
|
1 x
|
||||||
|
|
||||||
食べる to ate
|
|
||||||
む to drink
|
|
||||||
テスト testing
|
|
||||||
to eat 食べる
|
|
||||||
飲む to drink
|
|
||||||
多すぎる too many fields
|
|
||||||
not, enough, fields
|
|
||||||
遊ぶ
|
|
||||||
to play
|
|
||||||
|
|
|
@ -96,6 +96,29 @@ def test_csv():
|
||||||
assert i.total == 0
|
assert i.total == 0
|
||||||
deck.close()
|
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():
|
def test_supermemo_xml_01_unicode():
|
||||||
deck = getEmptyDeck()
|
deck = getEmptyDeck()
|
||||||
file = unicode(os.path.join(testDir, "support/supermemo1.xml"))
|
file = unicode(os.path.join(testDir, "support/supermemo1.xml"))
|
||||||
|
|
Loading…
Reference in a new issue