From 8ec078393a5643c88508614363596de00f6cbcb7 Mon Sep 17 00:00:00 2001 From: Austin Siew <17107540+Aquafina-water-bottle@users.noreply.github.com> Date: Tue, 16 Aug 2022 19:35:32 -0600 Subject: [PATCH] removed the bulk action in favor of the already existing 'multi' action --- README.md | 45 -------------------------------------------- plugin/__init__.py | 27 -------------------------- tests/test_models.py | 39 -------------------------------------- 3 files changed, 111 deletions(-) diff --git a/README.md b/README.md index 2cbe616..9acfb62 100644 --- a/README.md +++ b/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** diff --git a/plugin/__init__.py b/plugin/__init__.py index 6799486..4ff486b 100644 --- a/plugin/__init__.py +++ b/plugin/__init__.py @@ -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() diff --git a/tests/test_models.py b/tests/test_models.py index df8e0fa..72b6da8 100755 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -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"]