mirror of
https://github.com/ankitects/anki.git
synced 2025-11-09 06:07:11 -05:00
add support for updating tags for a given model
This commit is contained in:
parent
6af560da9a
commit
cd44f3308b
1 changed files with 23 additions and 0 deletions
23
anki/deck.py
23
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue