add support for updating tags for a given model

This commit is contained in:
Damien Elmes 2009-03-19 11:26:33 +09:00
parent 6af560da9a
commit cd44f3308b

View file

@ -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