Fix api method deleteDecks
The method was failing due to Anki API changes. Also, make it mandatory to call the method with `cardsToo=True`, since deleting decks on Anki >= 2.1.28 without cards is no longer supported, and the deprecated `decks.rem()` method on Anki >= 2.1.45 ignores keyword arguments.
This commit is contained in:
parent
0fdc93abc6
commit
baed642489
@ -745,8 +745,8 @@ corresponding to when the API was available for use.
|
||||
|
||||
* **deleteDecks**
|
||||
|
||||
Deletes decks with the given names. If `cardsToo` is `true` (defaults to `false` if unspecified), the cards within
|
||||
the deleted decks will also be deleted; otherwise they will be moved to the default deck.
|
||||
Deletes decks with the given names.
|
||||
The argument `cardsToo` *must* be specified and set to `true`.
|
||||
|
||||
*Sample request*:
|
||||
```json
|
||||
|
@ -531,12 +531,22 @@ class AnkiConnect:
|
||||
|
||||
@util.api()
|
||||
def deleteDecks(self, decks, cardsToo=False):
|
||||
if not cardsToo:
|
||||
# since f592672fa952260655881a75a2e3c921b2e23857 (2.1.28)
|
||||
# (see anki$ git log "-Gassert cardsToo")
|
||||
# you can't delete decks without deleting cards as well.
|
||||
# however, since 62c23c6816adf912776b9378c008a52bb50b2e8d (2.1.45)
|
||||
# passing cardsToo to `rem` (long deprecated) won't raise an error!
|
||||
# this is dangerous, so let's raise our own exception
|
||||
if self._anki21_version >= 28:
|
||||
raise Exception("Since Anki 2.1.28 it's not possible "
|
||||
"to delete decks without deleting cards as well")
|
||||
try:
|
||||
self.startEditing()
|
||||
decks = filter(lambda d: d in self.deckNames(), decks)
|
||||
for deck in decks:
|
||||
did = self.decks().id(deck)
|
||||
self.decks().rem(did, cardsToo)
|
||||
self.decks().rem(did, cardsToo=cardsToo)
|
||||
finally:
|
||||
self.stopEditing()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user