Only add total_in_deck to deckStats in supported Anki versions

This commit is contained in:
郑佩茹 2022-05-23 11:27:40 -06:00
parent b55ac78f84
commit 5e701e30aa

View File

@ -347,12 +347,15 @@ class AnkiConnect:
raise NotFoundError('Note was not found: {}'.format(note_id)) raise NotFoundError('Note was not found: {}'.format(note_id))
def deckStatsToJson(self, due_tree): def deckStatsToJson(self, due_tree):
return {'deck_id': due_tree.deck_id, deckStats = {'deck_id': due_tree.deck_id,
'name': due_tree.name, 'name': due_tree.name,
'new_count': due_tree.new_count, 'new_count': due_tree.new_count,
'learn_count': due_tree.learn_count, 'learn_count': due_tree.learn_count,
'review_count': due_tree.review_count, 'review_count': due_tree.review_count}
'total_in_deck': due_tree.total_in_deck} if anki_version > (2, 1, 46):
# total_in_deck is not supported on lower Anki versions
deckStats['total_in_deck'] = due_tree.total_in_deck
return deckStats
def collectDeckTreeChildren(self, parent_node): def collectDeckTreeChildren(self, parent_node):
allNodes = {parent_node.deck_id: parent_node} allNodes = {parent_node.deck_id: parent_node}