From cd44f3308bf28285d4c3e9897d385f365ab43884 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 19 Mar 2009 11:26:33 +0900 Subject: [PATCH] add support for updating tags for a given model --- anki/deck.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/anki/deck.py b/anki/deck.py index be7314ca2..265cc26ba 100644 --- a/anki/deck.py +++ b/anki/deck.py @@ -1541,6 +1541,29 @@ facts.modelId = :id""", id=modelId)) self.s.statements(""" insert into cardTags (cardId, tagId, src) values +(:cardId, :tagId, :src)""", d) + + def updateTagsForModel(self, model): + cardIds = self.s.column0(""" +select cards.id from cards, facts where +facts.modelId = :m and cards.factId = facts.id""", m=model.id) + factIds = self.s.column0(""" +select facts.id from facts where +facts.modelId = :m""", m=model.id) + tids = tagIds(self.s, parseTags(model.tags)) + self.s.statement(""" +delete from cardTags where cardId in %s +and src = 1""" % ids2str(cardIds)) + d = [] + for tag in parseTags(model.tags): + for id in cardIds: + d.append({"cardId": id, + "tagId": tids[tag.lower()], + "src": 1}) + if d: + self.s.statements(""" +insert into cardTags +(cardId, tagId, src) values (:cardId, :tagId, :src)""", d) # Tags: adding/removing in bulk