~foosoft/anki-connect

bdeb2fe0c522f88e4551899a8caf0ff4366dccbb — Alex Yatskov 6 years ago 01e5065 + 36a55ad
Merge pull request #99 from bertoncelj1/feature_allowDuplicate

Add option to allow adding duplicate notes
2 files changed, 15 insertions(+), 1 deletions(-)

M AnkiConnect.py
M README.md
M AnkiConnect.py => AnkiConnect.py +10 -0
@@ 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:

M README.md => README.md +5 -1
@@ 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"
                ],

Do not follow this link