removed the bulk action in favor of the already existing 'multi' action
This commit is contained in:
parent
cb52e14497
commit
8ec078393a
45
README.md
45
README.md
@ -2198,51 +2198,6 @@ corresponding to when the API was available for use.
|
||||
}
|
||||
```
|
||||
|
||||
* **editFieldNames**
|
||||
|
||||
TODO
|
||||
Bulk version of the above 4 actions.
|
||||
|
||||
*Sample Request*:
|
||||
```json
|
||||
{
|
||||
"action": "editFieldNames",
|
||||
"version": 6,
|
||||
"params": {
|
||||
"modelName": "Basic",
|
||||
"actions": [
|
||||
{
|
||||
"action": "add",
|
||||
"fieldName": "field3",
|
||||
"index": 0
|
||||
},
|
||||
{
|
||||
"action": "reposition",
|
||||
"fieldName": "field3",
|
||||
"index": 2
|
||||
},
|
||||
{
|
||||
"action": "rename",
|
||||
"oldFieldName": "field3",
|
||||
"newFieldName": "renamed_field3"
|
||||
},
|
||||
{
|
||||
"action": "remove",
|
||||
"fieldName": "field3"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
*Sample result*:
|
||||
```json
|
||||
{
|
||||
"result": null,
|
||||
"error": null
|
||||
}
|
||||
```
|
||||
|
||||
#### Note Actions
|
||||
|
||||
* **addNote**
|
||||
|
@ -1187,8 +1187,6 @@ class AnkiConnect:
|
||||
|
||||
@util.api()
|
||||
def modelFieldRename(self, modelName, oldFieldName, newFieldName):
|
||||
#self.startEditing()
|
||||
|
||||
mm = self.collection().models
|
||||
model = mm.byName(modelName)
|
||||
if model is None:
|
||||
@ -1202,7 +1200,6 @@ class AnkiConnect:
|
||||
mm.renameField(model, field, newFieldName)
|
||||
|
||||
self.save_model(mm, model)
|
||||
#self.stopEditing()
|
||||
|
||||
|
||||
@util.api()
|
||||
@ -1224,8 +1221,6 @@ class AnkiConnect:
|
||||
|
||||
@util.api()
|
||||
def modelFieldAdd(self, modelName, fieldName, index=None):
|
||||
#self.startEditing()
|
||||
|
||||
mm = self.collection().models
|
||||
model = mm.byName(modelName)
|
||||
if model is None:
|
||||
@ -1244,13 +1239,10 @@ class AnkiConnect:
|
||||
mm.repositionField(model, newField, index)
|
||||
|
||||
self.save_model(mm, model)
|
||||
#self.stopEditing()
|
||||
|
||||
|
||||
@util.api()
|
||||
def modelFieldRemove(self, modelName, fieldName):
|
||||
#self.startEditing()
|
||||
|
||||
mm = self.collection().models
|
||||
model = mm.byName(modelName)
|
||||
if model is None:
|
||||
@ -1264,25 +1256,6 @@ class AnkiConnect:
|
||||
mm.removeField(model, field)
|
||||
|
||||
self.save_model(mm, model)
|
||||
#self.stopEditing()
|
||||
|
||||
|
||||
@util.api()
|
||||
def editFieldNames(self, modelName, actions):
|
||||
actionToFuncMap = {
|
||||
'rename': self.modelFieldRename,
|
||||
'reposition': self.modelFieldReposition,
|
||||
'add': self.modelFieldAdd,
|
||||
'remove': self.modelFieldRemove,
|
||||
}
|
||||
|
||||
for actionDict in actions:
|
||||
action = actionDict['action']
|
||||
if action not in actionToFuncMap:
|
||||
raise Exception('invalid edit field name action: {}'.format(action))
|
||||
func = actionToFuncMap[action]
|
||||
args = {k: v for k, v in actionDict.items() if k != 'action'}
|
||||
func(modelName=modelName, **args)
|
||||
|
||||
|
||||
@util.api()
|
||||
|
@ -167,42 +167,3 @@ class TestModelFieldNames:
|
||||
|
||||
result = ac.modelFieldNames(modelName="test_model")
|
||||
assert result == ["field2"]
|
||||
|
||||
def test_editFieldNames(self, setup):
|
||||
editFieldNames_kwargs = {
|
||||
"modelName": "test_model",
|
||||
"actions": [
|
||||
{
|
||||
"action": "add",
|
||||
"fieldName": "field3",
|
||||
},
|
||||
{
|
||||
"action": "add",
|
||||
"fieldName": "field4",
|
||||
"index": 1,
|
||||
},
|
||||
{
|
||||
"action": "add",
|
||||
"fieldName": "field5",
|
||||
},
|
||||
{
|
||||
"action": "reposition",
|
||||
"fieldName": "field3",
|
||||
"index": 0,
|
||||
},
|
||||
{
|
||||
"action": "rename",
|
||||
"oldFieldName": "field3",
|
||||
"newFieldName": "renamed_field3",
|
||||
},
|
||||
{
|
||||
"action": "remove",
|
||||
"fieldName": "field5",
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
ac.editFieldNames(**editFieldNames_kwargs)
|
||||
|
||||
result = ac.modelFieldNames(modelName="test_model")
|
||||
assert result == ["renamed_field3", "field1", "field4", "field2"]
|
||||
|
Loading…
Reference in New Issue
Block a user