Add modelNamesAndIds action

This commit is contained in:
David Bailey 2017-08-21 17:15:11 +01:00
parent 75a3a25e91
commit 2e09db9dab
2 changed files with 38 additions and 0 deletions

View File

@ -512,6 +512,18 @@ class AnkiBridge:
return collection.models.allNames()
def modelNamesAndIds(self):
models = {}
modelNames = self.modelNames()
for model in modelNames:
mid = self.collection().models.byName(model)['id']
mid = int(mid) # sometimes Anki stores the ID as a string
models[model] = mid
return models
def modelNameFromId(self, modelId):
collection = self.collection()
if collection is not None:
@ -884,6 +896,11 @@ class AnkiConnect:
return self.anki.modelNames()
@webApi
def modelNamesAndIds(self):
return self.anki.modelNamesAndIds()
@webApi
def modelFieldNames(self, modelName):
return self.anki.modelFieldNames(modelName)

View File

@ -187,6 +187,27 @@ Below is a list of currently supported actions. Requests with invalid actions or
]
```
* **modelNamesAndIds**
Gets the complete list of model names and their corresponding IDs for the current user.
*Sample request*:
```
{
"action": "modelNamesAndIds"
}
```
*Sample response*:
```
{
"Basic": 1483883011648
"Basic (and reversed card)": 1483883011644
"Basic (optional reversed card)": 1483883011631
"Cloze": 1483883011630
}
```
* **modelFieldNames**
Gets the complete list of field names for the provided model name.