Add option to allow adding duplicate notes

This commit is contained in:
Anže Bertoncelj 2018-11-07 21:05:02 +01:00
parent 01e506588c
commit 36a55adf0a
2 changed files with 15 additions and 1 deletions

View File

@ -449,11 +449,21 @@ class AnkiConnect:
if name in ankiNote:
ankiNote[name] = value
allowDuplicate = False
if 'options' in note:
if 'allowDuplicate' in note['options']:
allowDuplicate = note['options']['allowDuplicate']
if type(allowDuplicate) is not bool:
raise Exception('option parameter \'allowDuplicate\' must be boolean')
duplicateOrEmpty = ankiNote.dupeOrEmpty()
if duplicateOrEmpty == 1:
raise Exception('cannot create note because it is empty')
elif duplicateOrEmpty == 2:
if not allowDuplicate:
raise Exception('cannot create note because it is a duplicate')
else:
return ankiNote
elif duplicateOrEmpty == False:
return ankiNote
else:

View File

@ -685,7 +685,8 @@ guarantee that your application continues to function properly in the future.
optional and can be omitted. If you choose to include it, the `url` and `filename` fields must be also defined. The
`skipHash` field can be optionally provided to skip the inclusion of downloaded files with an MD5 hash that matches
the provided value. This is useful for avoiding the saving of error pages and stub files. The `fields` member is a
list of fields that should play audio when the card is displayed in Anki.
list of fields that should play audio when the card is displayed in Anki. The 'allowDuplicate' member inside 'options'
group can be set to true to enable adding duplicate cards. Normally duplicate cards can not be added and trigger exception.
*Sample request*:
```json
@ -700,6 +701,9 @@ guarantee that your application continues to function properly in the future.
"Front": "front content",
"Back": "back content"
},
"options": {
"allowDuplicate": false
},
"tags": [
"yomichan"
],