Merge pull request #363 from introt/modelFieldDescriptions
Added modelFieldDescriptions
This commit is contained in:
commit
42a6de39b3
23
README.md
23
README.md
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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 == {
|
||||
|
Loading…
Reference in New Issue
Block a user