tweak naming and move method into col.decks

This commit is contained in:
Damien Elmes 2020-12-20 10:26:16 +10:00
parent c739b9782e
commit e99a7c0f90
3 changed files with 12 additions and 13 deletions

View file

@ -379,16 +379,6 @@ class Collection:
def cardCount(self) -> Any: def cardCount(self) -> Any:
return self.db.scalar("select count() from cards") 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]): def remove_cards_and_orphaned_notes(self, card_ids: Sequence[int]):
"You probably want .remove_notes_by_card() instead." "You probably want .remove_notes_by_card() instead."
self.backend.remove_cards(card_ids=card_ids) self.backend.remove_cards(card_ids=card_ids)

View file

@ -210,6 +210,16 @@ class DeckManager:
def count(self) -> int: def count(self) -> int:
return len(self.all_names_and_ids()) 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]: def get(self, did: Union[int, str], default: bool = True) -> Optional[Deck]:
if not did: if not did:
if default: if default:

View file

@ -277,12 +277,11 @@ class DeckBrowser:
def _delete(self, did: int): def _delete(self, did: int):
self.mw.checkpoint(tr(TR.DECKS_DELETE_DECK)) self.mw.checkpoint(tr(TR.DECKS_DELETE_DECK))
deck = self.mw.col.decks.get(did) deck = self.mw.col.decks.get(did)
extra = None
if not deck["dyn"]: 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: if count:
extra = tr(TR.DECKS_IT_HAS_CARD, count=count) extra = tr(TR.DECKS_IT_HAS_CARD, count=count)
else:
extra = None
if ( if (
deck["dyn"] deck["dyn"]
or not extra or not extra