Add changeDeck function

This commit is contained in:
David Bailey 2017-08-10 18:34:43 +01:00
parent caea9cbc08
commit aea292f092
2 changed files with 42 additions and 0 deletions

View File

@ -507,6 +507,23 @@ class AnkiBridge:
return [] return []
def changeDeck(self, cards, deck):
self.startEditing()
did = self.window().col.decks.id(deck)
mod = anki.utils.intTime()
usn = self.window().col.usn()
# normal cards
scids = anki.utils.ids2str(cards)
# remove any cards from filtered deck first
self.window().col.sched.remFromDyn(cards)
# then move into new deck
self.window().col.db.execute('update cards set usn=?, mod=?, did=? where id in ' + scids, usn, mod, did)
self.stopEditing()
def cardsToNotes(self, cards): def cardsToNotes(self, cards):
return self.window().col.db.list('select distinct nid from cards where id in ' + anki.utils.ids2str(cards)) return self.window().col.db.list('select distinct nid from cards where id in ' + anki.utils.ids2str(cards))
@ -785,6 +802,11 @@ class AnkiConnect:
return self.anki.findCards(query) return self.anki.findCards(query)
@webApi
def changeDeck(self, cards, deck):
return self.anki.changeDeck(cards, deck)
@webApi @webApi
def cardsToNotes(self, cards): def cardsToNotes(self, cards):
return self.anki.cardsToNotes(cards) return self.anki.cardsToNotes(cards)

View File

@ -490,6 +490,26 @@ Below is a list of currently supported actions. Requests with invalid actions or
] ]
``` ```
* **changeDeck**
Moves cards with the given IDs to a different deck, creating the deck if it doesn't exist yet.
*Sample request*:
```
{
"action": "changeDeck",
"params": {
"cards": [1502098034045, 1502098034048, 1502298033753],
"deck": "Japanese::JLPT N3"
}
}
```
*Sample response*:
```
null
```
* **cardsToNotes** * **cardsToNotes**
Returns an (unordered) array of note IDs for the given card IDs. For cards with the same note, the ID is only Returns an (unordered) array of note IDs for the given card IDs. For cards with the same note, the ID is only