Add tagging and suspend functions

This commit is contained in:
David Bailey 2017-08-03 21:07:22 +01:00
parent 5dfffadda7
commit e8088146f3
2 changed files with 112 additions and 0 deletions

View File

@ -375,6 +375,20 @@ class AnkiBridge:
return note return note
def addTags(self, query, tags, add=True):
notes = aqt.mw.col.findNotes(query)
aqt.mw.col.tags.bulkAdd(notes, tags, add)
def suspend(self, query, suspend=True):
cards = aqt.mw.col.findCards(query)
if suspend:
suspendFunction = aqt.mw.col.sched.suspendCards
else:
suspendFunction = aqt.mw.col.sched.unsuspendCards
suspendFunction(cards)
def startEditing(self): def startEditing(self):
self.window().requireReset() self.window().requireReset()
@ -662,6 +676,26 @@ class AnkiConnect:
return results return results
@webApi
def addTags(self, query, tags, add=True):
return self.anki.addTags(query, tags, add)
@webApi
def removeTags(self, query, tags):
return self.anki.addTags(query, tags, False)
@webApi
def suspend(self, query, suspend=True):
return self.anki.suspend(query, suspend)
@webApi
def unsuspend(self, query):
return self.anki.suspend(query, False)
@webApi @webApi
def upgrade(self): def upgrade(self):
response = QMessageBox.question( response = QMessageBox.question(

View File

@ -305,6 +305,84 @@ Below is a list of currently supported actions. Requests with invalid actions or
] ]
``` ```
* **addTags**
Adds tags to notes matching a query (same syntax as **browse**/**guiBrowse**).
*Sample request*:
```
{
"action": "addTags",
"params": {
"query": "deck:French or deck:Spanish",
"tags": "european-languages"
}
}
```
*Sample response*:
```
null
```
* **removeTags**
Remove tags from notes matching a query (same syntax as **browse**/**guiBrowse**).
*Sample request*:
```
{
"action": "removeTags",
"params": {
"query": "deck:Japanese or deck:Chinese",
"tags": "european-languages"
}
}
```
*Sample response*:
```
null
```
* **suspend**
Suspend cards matching a query (same syntax as **browse**/**guiBrowse**).
*Sample request*:
```
{
"action": "suspend",
"params": {
"query": "tag:difficult"
}
}
```
*Sample response*:
```
null
```
* **unsuspend**
Unsuspend cards matching a query (same syntax as **browse**/**guiBrowse**).
*Sample request*:
```
{
"action": "unsuspend",
"params": {
"query": "tag:easy"
}
}
```
*Sample response*:
```
null
```
* **guiBrowse** * **guiBrowse**
Invokes the card browser and searches for a given query. Returns an array of identifiers of the cards that were found. Invokes the card browser and searches for a given query. Returns an array of identifiers of the cards that were found.