Merge pull request #854 from k12ish/master
Add method `card_count_from_did()`
This commit is contained in:
commit
c739b9782e
@ -379,6 +379,16 @@ 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)
|
||||||
|
@ -265,7 +265,7 @@ class DeckBrowser:
|
|||||||
node.collapsed = not node.collapsed
|
node.collapsed = not node.collapsed
|
||||||
self._renderPage(reuse=True)
|
self._renderPage(reuse=True)
|
||||||
|
|
||||||
def _dragDeckOnto(self, draggedDeckDid, ontoDeckDid):
|
def _dragDeckOnto(self, draggedDeckDid: int, ontoDeckDid: int):
|
||||||
try:
|
try:
|
||||||
self.mw.col.decks.renameForDragAndDrop(draggedDeckDid, ontoDeckDid)
|
self.mw.col.decks.renameForDragAndDrop(draggedDeckDid, ontoDeckDid)
|
||||||
gui_hooks.sidebar_should_refresh_decks()
|
gui_hooks.sidebar_should_refresh_decks()
|
||||||
@ -274,17 +274,13 @@ class DeckBrowser:
|
|||||||
|
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
def _delete(self, did):
|
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)
|
||||||
if not deck["dyn"]:
|
if not deck["dyn"]:
|
||||||
dids = [did] + [r[1] for r in self.mw.col.decks.children(did)]
|
count = self.mw.col.card_count_from_did(did, count_subdecks=True)
|
||||||
cnt = self.mw.col.db.scalar(
|
if count:
|
||||||
"select count() from cards where did in {0} or "
|
extra = tr(TR.DECKS_IT_HAS_CARD, count=count)
|
||||||
"odid in {0}".format(ids2str(dids))
|
|
||||||
)
|
|
||||||
if cnt:
|
|
||||||
extra = tr(TR.DECKS_IT_HAS_CARD, count=cnt)
|
|
||||||
else:
|
else:
|
||||||
extra = None
|
extra = None
|
||||||
if (
|
if (
|
||||||
|
Loading…
Reference in New Issue
Block a user