Merge pull request #141 from mauamy/add-card-name-option-in-model-template

Add card name option in model template
This commit is contained in:
Alex Yatskov 2020-03-13 17:31:23 -07:00 committed by GitHub
commit 955b749aac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -709,7 +709,8 @@ guarantee that your application continues to function properly in the future.
* **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. used in the model. 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* *Sample request*
```json ```json
@ -722,6 +723,7 @@ guarantee that your application continues to function properly in the future.
"css": "Optional CSS with default to builtin css", "css": "Optional CSS with default to builtin css",
"cardTemplates": [ "cardTemplates": [
{ {
"Name": "My Card 1",
"Front": "Front html {{Field1}}", "Front": "Front html {{Field1}}",
"Back": "Back html {{Field2}}" "Back": "Back html {{Field2}}"
} }
@ -772,7 +774,7 @@ guarantee that your application continues to function properly in the future.
], ],
"tmpls":[ "tmpls":[
{ {
"name":"Card 1", "name":"My Card 1",
"ord":0, "ord":0,
"qfmt":"", "qfmt":"",
"afmt":"This is the back of the card {{Field2}}", "afmt":"This is the back of the card {{Field2}}",

View File

@ -647,7 +647,11 @@ class AnkiConnect:
# Generate new card template(s) # Generate new card template(s)
cardCount = 1 cardCount = 1
for card in cardTemplates: for card in cardTemplates:
t = mm.newTemplate(anki.lang._('Card ' + str(cardCount))) cardName = 'Card ' + str(cardCount)
if 'Name' in card:
cardName = card['Name']
t = mm.newTemplate(anki.lang._(cardName))
cardCount += 1 cardCount += 1
t['qfmt'] = card['Front'] t['qfmt'] = card['Front']
t['afmt'] = card['Back'] t['afmt'] = card['Back']