From 17d8ecf60fa5372dbb1da9dbf64c6717c9a09e87 Mon Sep 17 00:00:00 2001 From: Kirill Salnikov Date: Fri, 7 May 2021 05:11:03 +0300 Subject: [PATCH] Update createModel method to create Cloze models (#250) --- actions/models.md | 5 ++++- plugin/__init__.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/actions/models.md b/actions/models.md index ef3e817..77c9023 100644 --- a/actions/models.md +++ b/actions/models.md @@ -99,7 +99,9 @@ * **createModel** Creates a new model to be used in Anki. User must provide the `modelName`, `inOrderFields` and `cardTemplates` to be - used in the model. Optionally the `Name` field can be provided for each entry of `cardTemplates`. By default the + used in the model. There are optinal fields `css` and `isCloze`. If not specified, `css` will use the default Anki css and `isCloze` will be equal to `False`. If `isCloze` is `True` then model will be created as Cloze. + + Optionally the `Name` field can be provided for each entry of `cardTemplates`. By default the card names will be `Card 1`, `Card 2`, and so on. *Sample request* @@ -111,6 +113,7 @@ "modelName": "newModelName", "inOrderFields": ["Field1", "Field2", "Field3"], "css": "Optional CSS with default to builtin css", + "isCloze": False, "cardTemplates": [ { "Name": "My Card 1", diff --git a/plugin/__init__.py b/plugin/__init__.py index fabf5d8..6c07df2 100644 --- a/plugin/__init__.py +++ b/plugin/__init__.py @@ -34,6 +34,7 @@ import anki.exporting import anki.storage import aqt from anki.cards import Card +from anki.consts import MODEL_CLOZE from anki.exporting import AnkiPackageExporter from anki.importing import AnkiPackageImporter @@ -821,7 +822,7 @@ class AnkiConnect: @util.api() - def createModel(self, modelName, inOrderFields, cardTemplates, css = None): + def createModel(self, modelName, inOrderFields, cardTemplates, css = None, isCloze = False): # https://github.com/dae/anki/blob/b06b70f7214fb1f2ce33ba06d2b095384b81f874/anki/stdmodels.py if len(inOrderFields) == 0: raise Exception('Must provide at least one field for inOrderFields') @@ -835,6 +836,8 @@ class AnkiConnect: # Generate new Note m = mm.new(modelName) + if isCloze: + m['type'] = MODEL_CLOZE # Create fields and add them to Note for field in inOrderFields: