Ignore duplicates which are not in the target deck
This commit is contained in:
parent
0b66f6a4b5
commit
7ccfa7938e
@ -207,7 +207,7 @@ class AnkiConnect:
|
|||||||
if type(allowDuplicate) is not bool:
|
if type(allowDuplicate) is not bool:
|
||||||
raise Exception('option parameter \'allowDuplicate\' must be boolean')
|
raise Exception('option parameter \'allowDuplicate\' must be boolean')
|
||||||
|
|
||||||
duplicateOrEmpty = ankiNote.dupeOrEmpty()
|
duplicateOrEmpty = self.isNoteDuplicateOrEmptyInDeck(ankiNote, deck)
|
||||||
if duplicateOrEmpty == 1:
|
if duplicateOrEmpty == 1:
|
||||||
raise Exception('cannot create note because it is empty')
|
raise Exception('cannot create note because it is empty')
|
||||||
elif duplicateOrEmpty == 2:
|
elif duplicateOrEmpty == 2:
|
||||||
@ -220,6 +220,32 @@ class AnkiConnect:
|
|||||||
else:
|
else:
|
||||||
raise Exception('cannot create note for unknown reason')
|
raise Exception('cannot create note for unknown reason')
|
||||||
|
|
||||||
|
def isNoteDuplicateOrEmptyInDeck(self, note, deck):
|
||||||
|
"1 if first is empty; 2 if first is a duplicate, False otherwise."
|
||||||
|
result = note.dupeOrEmpty()
|
||||||
|
if result != 2:
|
||||||
|
return result
|
||||||
|
|
||||||
|
# dupeOrEmpty returns if a note is a global duplicate
|
||||||
|
# the rest of the function checks to see if the note is a duplicate in the deck
|
||||||
|
val = note.fields[0].strip()
|
||||||
|
did = deck['id']
|
||||||
|
csum = anki.utils.fieldChecksum(val)
|
||||||
|
|
||||||
|
for noteId in note.col.db.list(
|
||||||
|
"select id from notes where csum = ? and id != ? and mid = ?",
|
||||||
|
csum,
|
||||||
|
note.id or 0,
|
||||||
|
note.mid,
|
||||||
|
):
|
||||||
|
if note.col.db.scalar(
|
||||||
|
"select id from cards where nid = ? and did = ?",
|
||||||
|
noteId,
|
||||||
|
did
|
||||||
|
):
|
||||||
|
return 2
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Miscellaneous
|
# Miscellaneous
|
||||||
|
Loading…
Reference in New Issue
Block a user