Add modelNamesAndIds action
This commit is contained in:
parent
75a3a25e91
commit
2e09db9dab
@ -512,6 +512,18 @@ class AnkiBridge:
|
|||||||
return collection.models.allNames()
|
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):
|
def modelNameFromId(self, modelId):
|
||||||
collection = self.collection()
|
collection = self.collection()
|
||||||
if collection is not None:
|
if collection is not None:
|
||||||
@ -884,6 +896,11 @@ class AnkiConnect:
|
|||||||
return self.anki.modelNames()
|
return self.anki.modelNames()
|
||||||
|
|
||||||
|
|
||||||
|
@webApi
|
||||||
|
def modelNamesAndIds(self):
|
||||||
|
return self.anki.modelNamesAndIds()
|
||||||
|
|
||||||
|
|
||||||
@webApi
|
@webApi
|
||||||
def modelFieldNames(self, modelName):
|
def modelFieldNames(self, modelName):
|
||||||
return self.anki.modelFieldNames(modelName)
|
return self.anki.modelFieldNames(modelName)
|
||||||
|
21
README.md
21
README.md
@ -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**
|
* **modelFieldNames**
|
||||||
|
|
||||||
Gets the complete list of field names for the provided model name.
|
Gets the complete list of field names for the provided model name.
|
||||||
|
Loading…
Reference in New Issue
Block a user