replaceTags and clearUnusedTags are added (#219)

* clearUnusedTags and replaceTags are added

* added clearUnusedTags and replaceTags

* added clearUnusedTags and replaceTags

* removed whitespaces and indentations

* removed white spaces and indentations
This commit is contained in:
Venkata Ramana 2021-01-02 22:35:35 +05:30 committed by GitHub
parent 5386364c8d
commit 311cb7e192
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 105 additions and 1 deletions

View File

@ -284,6 +284,75 @@
}
```
* **clearUnusedTags**
Clears all the unused tags in the notes for the current user.
*Sample request*:
```json
{
"action": "clearUnusedTags",
"version": 6
}
```
*Sample result*:
```json
{
"result": null,
"error": null
}
```
* **replaceTags**
Replace tags in notes by note ID.
*Sample request*:
```json
{
"action": "replaceTags",
"version": 6,
"params": {
"notes": [1483959289817, 1483959291695],
"tag_to_replace": "european-languages",
"replace_with_tag": "french-languages"
}
}
```
*Sample result*:
```json
{
"result": null,
"error": null
}
```
* **replaceTagsInAllNotes**
Replace tags in all the notes for the current user.
*Sample request*:
```json
{
"action": "replaceTagsInAllCards",
"version": 6,
"params": {
"tag_to_replace": "european-languages",
"replace_with_tag": "french-languages"
}
}
```
*Sample result*:
```json
{
"result": null,
"error": null
}
```
* **findNotes**
Returns an array of note IDs for a given query. Same query syntax as `guiBrowse`.

View File

@ -615,6 +615,41 @@ class AnkiConnect:
def getTags(self):
return self.collection().tags.all()
@util.api()
def clearUnusedTags(self):
self.collection().tags.registerNotes()
@util.api()
def replaceTags(self, notes, tag_to_replace, replace_with_tag):
if self.collection() is not None:
self.window().progress.start()
for nid in notes:
note = self.collection().getNote(nid)
if note.hasTag(tag_to_replace):
note.delTag(tag_to_replace)
note.addtag(replace_with_tag)
note.flush()
self.window().requireReset()
self.window().progress.finish()
self.window().reset()
@util.api()
def replaceTagsInAllNotes(self, tag_to_replace, replace_with_tag):
collection = self.collection()
if collection is not None:
nids = collection.db.list('select id from notes')
self.window().progress.start()
for nid in nids:
note = collection.getNote(nid)
if note.hasTag(tag_to_replace):
note.delTag(tag_to_replace)
note.addtag(replace_with_tag)
note.flush()
self.window().requireReset()
self.window().progress.finish()
self.window().reset()
return False
@util.api()
def setEaseFactors(self, cards, easeFactors):
couldSetEaseFactors = []