Added method

This commit is contained in:
k12ish 2020-12-19 17:59:07 +00:00
parent 3840686241
commit ef1f58c8b6
2 changed files with 13 additions and 7 deletions

View file

@ -379,6 +379,16 @@ class Collection:
def cardCount(self) -> Any:
return self.db.scalar("select count() from cards")
def card_count_from_did(self, did, recursive=False):
dids = [did]
if recursive:
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)

View file

@ -278,13 +278,9 @@ class DeckBrowser:
self.mw.checkpoint(tr(TR.DECKS_DELETE_DECK))
deck = self.mw.col.decks.get(did)
if not deck["dyn"]:
dids = [did] + [r[1] for r in self.mw.col.decks.children(did)]
cnt = self.mw.col.db.scalar(
"select count() from cards where did in {0} or "
"odid in {0}".format(ids2str(dids))
)
if cnt:
extra = tr(TR.DECKS_IT_HAS_CARD, count=cnt)
count = self.mw.col.card_count_from_did(did, recursive=True)
if count:
extra = tr(TR.DECKS_IT_HAS_CARD, count=count)
else:
extra = None
if (