Merge pull request #363 from introt/modelFieldDescriptions

Added modelFieldDescriptions
This commit is contained in:
Alexei Yatskov 2022-12-10 09:44:25 -08:00 committed by GitHub
commit 42a6de39b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 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**
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,20 @@ class AnkiConnect:
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:
try:
return [field['description'] for field in model['flds']]
except KeyError:
# older versions of Anki don't have field descriptions
return ['' for field in model['flds']]
@util.api()
def modelFieldsOnTemplates(self, modelName):
model = self.collection().models.byName(modelName)

View File

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