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):
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):
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:
aqt.mw.col.sched.suspendCards(cards)
self.collection().sched.suspendCards(cards)
else:
aqt.mw.col.sched.unsuspendCards(cards)
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:
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 []
@ -702,6 +723,11 @@ class AnkiConnect:
return self.anki.suspend(cards, False)
@webApi
def isSuspended(self, card):
return self.anki.isSuspended(card)
@webApi
def upgrade(self):
response = QMessageBox.question(

View File

@ -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**