Merge pull request #21 from techdavid/tag-suspend-bugfix
Fix issue #20; add isSuspended function; update code style
This commit is contained in:
commit
9298f867f6
@ -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):
|
||||||
|
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:
|
if suspend:
|
||||||
aqt.mw.col.sched.suspendCards(cards)
|
self.collection().sched.suspendCards(cards)
|
||||||
else:
|
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):
|
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(
|
||||||
|
29
README.md
29
README.md
@ -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**
|
||||||
|
Loading…
Reference in New Issue
Block a user