Fix issue #20; add isSuspended function; update code style

This commit is contained in:
David Bailey 2017-08-06 02:29:59 +01:00
parent f48e6431b5
commit dc01014daf
2 changed files with 57 additions and 10 deletions

View File

@ -377,15 +377,36 @@ class AnkiBridge:
def addTags(self, notes, tags, add=True): def addTags(self, notes, tags, add=True):
self.startEditing() self.startEditing()
aqt.mw.col.tags.bulkAdd(notes, tags, add) self.collection().tags.bulkAdd(notes, tags, add)
self.stopEditing() self.stopEditing()
def suspend(self, cards, suspend=True): def suspend(self, cards, suspend=True):
if suspend: for card in cards:
aqt.mw.col.sched.suspendCards(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: else:
aqt.mw.col.sched.unsuspendCards(cards) return False
def startEditing(self): def startEditing(self):
@ -464,14 +485,14 @@ class AnkiBridge:
def findNotes(self, query=None): def findNotes(self, query=None):
if query is not None: if query is not None:
return aqt.mw.col.findNotes(query) return self.collection().findNotes(query)
else: else:
return [] return []
def findCards(self, query=None): def findCards(self, query=None):
if query is not None: if query is not None:
return aqt.mw.col.findCards(query) return self.collection().findCards(query)
else: else:
return [] return []
@ -702,6 +723,11 @@ class AnkiConnect:
return self.anki.suspend(cards, False) return self.anki.suspend(cards, False)
@webApi
def isSuspended(self, card):
return self.anki.isSuspended(card)
@webApi @webApi
def upgrade(self): def upgrade(self):
response = QMessageBox.question( response = QMessageBox.question(

View File

@ -347,7 +347,8 @@ Below is a list of currently supported actions. Requests with invalid actions or
* **suspend** * **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*: *Sample request*:
``` ```
@ -361,12 +362,13 @@ Below is a list of currently supported actions. Requests with invalid actions or
*Sample response*: *Sample response*:
``` ```
null true
``` ```
* **unsuspend** * **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*: *Sample request*:
``` ```
@ -380,7 +382,26 @@ Below is a list of currently supported actions. Requests with invalid actions or
*Sample response*: *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** * **findNotes**