diff --git a/pylib/anki/collection.py b/pylib/anki/collection.py index 1b47dbc10..77eab8716 100644 --- a/pylib/anki/collection.py +++ b/pylib/anki/collection.py @@ -379,16 +379,6 @@ class Collection: def cardCount(self) -> Any: return self.db.scalar("select count() from cards") - def card_count_from_did(self, did: int, count_subdecks: bool = False) -> Any: - dids: List[int] = [did] - if count_subdecks: - dids += [r[1] for r in self.decks.children(did)] - count = self.db.scalar( - "select count() from cards where did in {0} or " - "odid in {0}".format(ids2str(dids)) - ) - return count - def remove_cards_and_orphaned_notes(self, card_ids: Sequence[int]): "You probably want .remove_notes_by_card() instead." self.backend.remove_cards(card_ids=card_ids) diff --git a/pylib/anki/decks.py b/pylib/anki/decks.py index 675da7c21..2c0132b5a 100644 --- a/pylib/anki/decks.py +++ b/pylib/anki/decks.py @@ -210,6 +210,16 @@ class DeckManager: def count(self) -> int: return len(self.all_names_and_ids()) + def card_count(self, did: int, include_subdecks: bool) -> Any: + dids: List[int] = [did] + if include_subdecks: + dids += [r[1] for r in self.children(did)] + count = self.col.db.scalar( + "select count() from cards where did in {0} or " + "odid in {0}".format(ids2str(dids)) + ) + return count + def get(self, did: Union[int, str], default: bool = True) -> Optional[Deck]: if not did: if default: diff --git a/qt/aqt/deckbrowser.py b/qt/aqt/deckbrowser.py index eb3a3adcf..24f0f9df0 100644 --- a/qt/aqt/deckbrowser.py +++ b/qt/aqt/deckbrowser.py @@ -277,12 +277,11 @@ class DeckBrowser: def _delete(self, did: int): self.mw.checkpoint(tr(TR.DECKS_DELETE_DECK)) deck = self.mw.col.decks.get(did) + extra = None if not deck["dyn"]: - count = self.mw.col.card_count_from_did(did, count_subdecks=True) + count = self.mw.col.decks.card_count(did, include_subdecks=True) if count: extra = tr(TR.DECKS_IT_HAS_CARD, count=count) - else: - extra = None if ( deck["dyn"] or not extra