Added modelFieldDescriptions

Similar to modelFieldNames, returns a list of
note field decriptions (the text seen in the gui
editor when the field is empty)
This commit is contained in:
introt 2022-11-26 14:56:34 +02:00
parent 82ca4b847d
commit 336dc8bb31
3 changed files with 37 additions and 0 deletions

View File

@ -1829,6 +1829,29 @@ corresponding to when the API was available for use.
} }
``` ```
* **modelFieldDescriptions**
Gets the complete list of field descriptions (the text seen in the gui editor when a field is empty) for the provided model name.
*Sample request*:
```json
{
"action": "modelFieldDescriptions",
"version": 6,
"params": {
"modelName": "Basic"
}
}
```
*Sample result*:
```json
{
"result": ["", ""],
"error": null
}
```
* **modelFieldsOnTemplates** * **modelFieldsOnTemplates**
Returns an object indicating the fields on the question and answer side of each card template for the given model Returns an object indicating the fields on the question and answer side of each card template for the given model

View File

@ -1069,6 +1069,15 @@ class AnkiConnect:
return [field['name'] for field in model['flds']] return [field['name'] for field in model['flds']]
@util.api()
def modelFieldDescriptions(self, modelName):
model = self.collection().models.byName(modelName)
if model is None:
raise Exception('model was not found: {}'.format(modelName))
else:
return [field['description'] for field in model['flds']]
@util.api() @util.api()
def modelFieldsOnTemplates(self, modelName): def modelFieldsOnTemplates(self, modelName):
model = self.collection().models.byName(modelName) model = self.collection().models.byName(modelName)

View File

@ -16,6 +16,11 @@ def test_modelFieldNames(setup):
assert result == ["field1", "field2"] assert result == ["field1", "field2"]
def test_modelFieldDescriptions(setup):
result = ac.modelFieldDescriptions(modelName="test_model")
assert result == ["", ""]
def test_modelFieldsOnTemplates(setup): def test_modelFieldsOnTemplates(setup):
result = ac.modelFieldsOnTemplates(modelName="test_model") result = ac.modelFieldsOnTemplates(modelName="test_model")
assert result == { assert result == {