Update createModel method to create Cloze models (#250)
This commit is contained in:
parent
1a08d79454
commit
17d8ecf60f
@ -99,7 +99,9 @@
|
|||||||
* **createModel**
|
* **createModel**
|
||||||
|
|
||||||
Creates a new model to be used in Anki. User must provide the `modelName`, `inOrderFields` and `cardTemplates` to be
|
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.
|
card names will be `Card 1`, `Card 2`, and so on.
|
||||||
|
|
||||||
*Sample request*
|
*Sample request*
|
||||||
@ -111,6 +113,7 @@
|
|||||||
"modelName": "newModelName",
|
"modelName": "newModelName",
|
||||||
"inOrderFields": ["Field1", "Field2", "Field3"],
|
"inOrderFields": ["Field1", "Field2", "Field3"],
|
||||||
"css": "Optional CSS with default to builtin css",
|
"css": "Optional CSS with default to builtin css",
|
||||||
|
"isCloze": False,
|
||||||
"cardTemplates": [
|
"cardTemplates": [
|
||||||
{
|
{
|
||||||
"Name": "My Card 1",
|
"Name": "My Card 1",
|
||||||
|
@ -34,6 +34,7 @@ import anki.exporting
|
|||||||
import anki.storage
|
import anki.storage
|
||||||
import aqt
|
import aqt
|
||||||
from anki.cards import Card
|
from anki.cards import Card
|
||||||
|
from anki.consts import MODEL_CLOZE
|
||||||
|
|
||||||
from anki.exporting import AnkiPackageExporter
|
from anki.exporting import AnkiPackageExporter
|
||||||
from anki.importing import AnkiPackageImporter
|
from anki.importing import AnkiPackageImporter
|
||||||
@ -821,7 +822,7 @@ class AnkiConnect:
|
|||||||
|
|
||||||
|
|
||||||
@util.api()
|
@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
|
# https://github.com/dae/anki/blob/b06b70f7214fb1f2ce33ba06d2b095384b81f874/anki/stdmodels.py
|
||||||
if len(inOrderFields) == 0:
|
if len(inOrderFields) == 0:
|
||||||
raise Exception('Must provide at least one field for inOrderFields')
|
raise Exception('Must provide at least one field for inOrderFields')
|
||||||
@ -835,6 +836,8 @@ class AnkiConnect:
|
|||||||
|
|
||||||
# Generate new Note
|
# Generate new Note
|
||||||
m = mm.new(modelName)
|
m = mm.new(modelName)
|
||||||
|
if isCloze:
|
||||||
|
m['type'] = MODEL_CLOZE
|
||||||
|
|
||||||
# Create fields and add them to Note
|
# Create fields and add them to Note
|
||||||
for field in inOrderFields:
|
for field in inOrderFields:
|
||||||
|
Loading…
Reference in New Issue
Block a user