From 1f1220cf7c17ecbb9f3c190ecbdfb94a8baf3018 Mon Sep 17 00:00:00 2001 From: bogdanteleaga Date: Fri, 20 Nov 2015 20:14:12 +0200 Subject: [PATCH] Limit tags in custom study dialog to those in the selected deck --- anki/tags.py | 13 +++++++++++++ aqt/taglimit.py | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/anki/tags.py b/anki/tags.py index e752fdb7c..b87b0ddeb 100644 --- a/anki/tags.py +++ b/anki/tags.py @@ -67,6 +67,19 @@ class TagManager(object): def save(self): self.changed = True + def byDeck(self, did, children=False): + basequery = "select n.tags from cards c, notes n WHERE c.nid = n.id" + if not children: + query = basequery + " AND c.did=?" + res = self.col.db.list(query, did) + return list(set(self.split(" ".join(res)))) + dids = [did] + for name, id in self.col.decks.children(did): + dids.append(id) + query = basequery + " AND c.did IN " + ids2str(dids) + res = self.col.db.list(query) + return list(set(self.split(" ".join(res)))) + # Bulk addition/removal from notes ############################################################# diff --git a/aqt/taglimit.py b/aqt/taglimit.py index 6ade8bee8..77edd7999 100644 --- a/aqt/taglimit.py +++ b/aqt/taglimit.py @@ -19,7 +19,7 @@ class TagLimit(QDialog): self.exec_() def rebuildTagList(self): - usertags = self.mw.col.tags.all() + usertags = self.mw.col.tags.byDeck(self.deck['id'], True) yes = self.deck.get("activeTags", []) no = self.deck.get("inactiveTags", []) yesHash = {}