@@ 377,15 377,36 @@ class AnkiBridge:
def addTags(self, notes, tags, add=True):
self.startEditing()
- aqt.mw.col.tags.bulkAdd(notes, tags, add)
+ self.collection().tags.bulkAdd(notes, tags, add)
self.stopEditing()
def suspend(self, cards, suspend=True):
- if suspend:
- aqt.mw.col.sched.suspendCards(cards)
+ for card in cards:
+ isSuspended = self.isSuspended(card)
+ if suspend and isSuspended:
+ cards.remove(card)
+ elif not suspend and not isSuspended:
+ cards.remove(card)
+
+ if cards:
+ self.startEditing()
+ if suspend:
+ self.collection().sched.suspendCards(cards)
+ else:
+ self.collection().sched.unsuspendCards(cards)
+ self.stopEditing()
+ return True
+
+ return False
+
+
+ def isSuspended(self, card):
+ card = self.collection().getCard(card)
+ if card.queue == -1:
+ return True
else:
- aqt.mw.col.sched.unsuspendCards(cards)
+ return False
def startEditing(self):
@@ 464,14 485,14 @@ class AnkiBridge:
def findNotes(self, query=None):
if query is not None:
- return aqt.mw.col.findNotes(query)
+ return self.collection().findNotes(query)
else:
return []
def findCards(self, query=None):
if query is not None:
- return aqt.mw.col.findCards(query)
+ return self.collection().findCards(query)
else:
return []
@@ 703,6 724,11 @@ class AnkiConnect:
@webApi
+ def isSuspended(self, card):
+ return self.anki.isSuspended(card)
+
+
+ @webApi
def upgrade(self):
response = QMessageBox.question(
self.anki.window(),
@@ 347,7 347,8 @@ Below is a list of currently supported actions. Requests with invalid actions or
* **suspend**
- Suspend cards by card ID.
+ Suspend cards by card ID; returns `true` if successful (at least one card wasn't already suspended) or `false`
+ otherwise.
*Sample request*:
```
@@ 361,12 362,13 @@ Below is a list of currently supported actions. Requests with invalid actions or
*Sample response*:
```
- null
+ true
```
* **unsuspend**
- Unsuspend cards by card ID.
+ Unsuspend cards by card ID; returns `true` if successful (at least one card was previously suspended) or `false`
+ otherwise.
*Sample request*:
```
@@ 380,7 382,26 @@ Below is a list of currently supported actions. Requests with invalid actions or
*Sample response*:
```
- null
+ true
+ ```
+
+* **isSuspended**
+
+ Returns `true` if the given card is suspended or `false` otherwise.
+
+ *Sample request*:
+ ```
+ {
+ "action": "isSuspended",
+ "params": {
+ "card": 1483959291685
+ }
+ }
+ ```
+
+ *Sample response*:
+ ```
+ false
```
* **findNotes**