Merge pull request #99 from bertoncelj1/feature_allowDuplicate

Add option to allow adding duplicate notes
This commit is contained in:
Alex Yatskov 2018-11-07 12:50:48 -08:00 committed by GitHub
commit bdeb2fe0c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -449,11 +449,21 @@ class AnkiConnect:
if name in ankiNote: if name in ankiNote:
ankiNote[name] = value 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() duplicateOrEmpty = ankiNote.dupeOrEmpty()
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:
if not allowDuplicate:
raise Exception('cannot create note because it is a duplicate') raise Exception('cannot create note because it is a duplicate')
else:
return ankiNote
elif duplicateOrEmpty == False: elif duplicateOrEmpty == False:
return ankiNote return ankiNote
else: 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 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 `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 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*: *Sample request*:
```json ```json
@ -700,6 +701,9 @@ guarantee that your application continues to function properly in the future.
"Front": "front content", "Front": "front content",
"Back": "back content" "Back": "back content"
}, },
"options": {
"allowDuplicate": false
},
"tags": [ "tags": [
"yomichan" "yomichan"
], ],