Fixed deck config id actions (#273)

The follow deck configuration actions were updated to conform to Anki’s current deck configuration access. Specifically, `decks.conf` is no longer available.

setDeckConfigId no longer check for existence of configuration id, because the access to the list of config id’s appears to be only through decks; and the config may theoretically be orphaned.
This commit is contained in:
NSBum 2021-07-14 21:22:10 -04:00 committed by GitHub
parent a34c1de0b4
commit 4e41429165
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -562,37 +562,40 @@ class AnkiConnect:
@util.api() @util.api()
def setDeckConfigId(self, decks, configId): def setDeckConfigId(self, decks, configId):
configId = str(configId) configId = int(configId)
for deck in decks: for deck in decks:
if not deck in self.deckNames(): if not deck in self.deckNames():
return False return False
collection = self.collection() collection = self.collection()
if configId not in collection.decks.dconf:
return False
for deck in decks: for deck in decks:
try:
did = str(collection.decks.id(deck)) did = str(collection.decks.id(deck))
aqt.mw.col.decks.decks[did]['conf'] = configId deck_dict = aqt.mw.col.decks.decks[did]
deck_dict['conf'] = configId
collection.decks.save(deck_dict)
except:
return False
return True return True
@util.api() @util.api()
def cloneDeckConfigId(self, name, cloneFrom='1'): def cloneDeckConfigId(self, name, cloneFrom='1'):
configId = str(cloneFrom) configId = int(cloneFrom)
if configId not in self.collection().decks.dconf: collection = self.collection()
if configId not in [c['id'] for c in collection.decks.all_config()]:
return False return False
config = self.collection().decks.getConf(configId) config = collection.decks.getConf(configId)
return self.collection().decks.confId(name, config) return collection.decks.confId(name, config)
@util.api() @util.api()
def removeDeckConfigId(self, configId): def removeDeckConfigId(self, configId):
configId = str(configId)
collection = self.collection() collection = self.collection()
if configId not in collection.decks.dconf: if int(configId) not in [c['id'] for c in collection.decks.all_config()]:
return False return False
collection.decks.remConf(configId) collection.decks.remConf(configId)