mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 06:52:21 -04:00
remove card tags
This commit is contained in:
parent
7e305111ad
commit
75a61a00cc
3 changed files with 19 additions and 33 deletions
44
anki/deck.py
44
anki/deck.py
|
@ -1200,14 +1200,15 @@ where cardModelId in %s""" % strids, now=time.time())
|
||||||
def tagsList(self, where="", priority=", cards.priority"):
|
def tagsList(self, where="", priority=", cards.priority"):
|
||||||
"Return a list of (cardId, allTags, priority)"
|
"Return a list of (cardId, allTags, priority)"
|
||||||
return self.s.all("""
|
return self.s.all("""
|
||||||
select cards.id, cards.tags || "," || facts.tags || "," || models.tags || "," ||
|
select cards.id, facts.tags || "," || models.tags || "," ||
|
||||||
cardModels.name %s from cards, facts, models, cardModels where
|
cardModels.name %s from cards, facts, models, cardModels where
|
||||||
cards.factId == facts.id and facts.modelId == models.id
|
cards.factId == facts.id and facts.modelId == models.id
|
||||||
and cards.cardModelId = cardModels.id %s""" % (priority, where))
|
and cards.cardModelId = cardModels.id %s""" % (priority, where))
|
||||||
|
|
||||||
def shortTagsList(self, where=""):
|
def shortTagsList(self, where=""):
|
||||||
|
# no card model
|
||||||
return self.s.all("""
|
return self.s.all("""
|
||||||
select cards.id, cards.tags || "," || facts.tags || "," || models.tags
|
select cards.id, facts.tags || "," || models.tags
|
||||||
from cards, facts, models where
|
from cards, facts, models where
|
||||||
cards.factId == facts.id and facts.modelId == models.id
|
cards.factId == facts.id and facts.modelId == models.id
|
||||||
%s""" % where)
|
%s""" % where)
|
||||||
|
@ -1215,27 +1216,20 @@ cards.factId == facts.id and facts.modelId == models.id
|
||||||
def cardsWithNoTags(self):
|
def cardsWithNoTags(self):
|
||||||
return self.s.column0("""
|
return self.s.column0("""
|
||||||
select cards.id from cards, facts where
|
select cards.id from cards, facts where
|
||||||
cards.tags = "" and facts.tags = ""
|
facts.tags = ""
|
||||||
and cards.factId = facts.id""")
|
and cards.factId = facts.id""")
|
||||||
|
|
||||||
def allTags(self):
|
def allTags(self):
|
||||||
"Return a hash listing tags in model, fact and cards."
|
"Return a hash listing tags in model & fact."
|
||||||
return list(set(parseTags(",".join([x[1] for x in self.tagsList()]))))
|
return list(set(parseTags(",".join([x[1] for x in self.tagsList()]))))
|
||||||
|
|
||||||
def cardTags(self, ids):
|
|
||||||
return self.s.all("""
|
|
||||||
select id, tags from cards
|
|
||||||
where id in %s""" % ids2str(ids))
|
|
||||||
|
|
||||||
def factTags(self, ids):
|
def factTags(self, ids):
|
||||||
return self.s.all("""
|
return self.s.all("""
|
||||||
select id, tags from facts
|
select id, tags from facts
|
||||||
where id in %s""" % ids2str(ids))
|
where id in %s""" % ids2str(ids))
|
||||||
|
|
||||||
def addCardTags(self, ids, tags, idfunc=None, table="cards"):
|
def addTags(self, ids, tags):
|
||||||
if not idfunc:
|
tlist = self.factTags(ids)
|
||||||
idfunc=self.cardTags
|
|
||||||
tlist = idfunc(ids)
|
|
||||||
newTags = parseTags(tags)
|
newTags = parseTags(tags)
|
||||||
now = time.time()
|
now = time.time()
|
||||||
pending = []
|
pending = []
|
||||||
|
@ -1246,20 +1240,15 @@ where id in %s""" % ids2str(ids))
|
||||||
pending.append(
|
pending.append(
|
||||||
{'id': id, 'now': now, 'tags': ", ".join(tmpTags)})
|
{'id': id, 'now': now, 'tags': ", ".join(tmpTags)})
|
||||||
self.s.statements("""
|
self.s.statements("""
|
||||||
update %s set
|
update facts set
|
||||||
tags = :tags,
|
tags = :tags,
|
||||||
modified = :now
|
modified = :now
|
||||||
where id = :id""" % table, pending)
|
where id = :id""", pending)
|
||||||
self.updateCardQACacheFromCardIds([x[0] for x in tlist], type=table)
|
self.updateCardQACacheFromCardIds([x[0] for x in tlist], type="facts")
|
||||||
self.flushMod()
|
self.flushMod()
|
||||||
|
|
||||||
def addFactTags(self, ids, tags):
|
def deleteTags(self, ids, tags):
|
||||||
self.addCardTags(ids, tags, idfunc=self.factTags, table="facts")
|
tlist = self.factTags(ids)
|
||||||
|
|
||||||
def deleteCardTags(self, ids, tags, idfunc=None, table="cards"):
|
|
||||||
if not idfunc:
|
|
||||||
idfunc=self.cardTags
|
|
||||||
tlist = idfunc(ids)
|
|
||||||
newTags = parseTags(tags)
|
newTags = parseTags(tags)
|
||||||
now = time.time()
|
now = time.time()
|
||||||
pending = []
|
pending = []
|
||||||
|
@ -1275,16 +1264,13 @@ where id = :id""" % table, pending)
|
||||||
pending.append(
|
pending.append(
|
||||||
{'id': id, 'now': now, 'tags': ", ".join(tmpTags)})
|
{'id': id, 'now': now, 'tags': ", ".join(tmpTags)})
|
||||||
self.s.statements("""
|
self.s.statements("""
|
||||||
update %s set
|
update facts set
|
||||||
tags = :tags,
|
tags = :tags,
|
||||||
modified = :now
|
modified = :now
|
||||||
where id = :id""" % table, pending)
|
where id = :id""", pending)
|
||||||
self.updateCardQACacheFromCardIds([x[0] for x in tlist], type=table)
|
self.updateCardQACacheFromCardIds([x[0] for x in tlist], type="facts")
|
||||||
self.flushMod()
|
self.flushMod()
|
||||||
|
|
||||||
def deleteFactTags(self, ids, tags):
|
|
||||||
self.deleteCardTags(ids, tags, idfunc=self.factTags, table="facts")
|
|
||||||
|
|
||||||
# File-related
|
# File-related
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ class Anki10Importer(Importer):
|
||||||
bulkClient.sync()
|
bulkClient.sync()
|
||||||
# add tags
|
# add tags
|
||||||
fids = [f[0] for f in res['added-facts']['facts']]
|
fids = [f[0] for f in res['added-facts']['facts']]
|
||||||
self.deck.addFactTags(fids, self.tagsToAdd)
|
self.deck.addTags(fids, self.tagsToAdd)
|
||||||
self.total = len(res['added-facts']['facts'])
|
self.total = len(res['added-facts']['facts'])
|
||||||
src.s.rollback()
|
src.s.rollback()
|
||||||
self.deck.flushMod()
|
self.deck.flushMod()
|
||||||
|
|
|
@ -149,10 +149,10 @@ def rebuildMediaDir(deck, deleteRefs=False, dirty=True):
|
||||||
# fix tags
|
# fix tags
|
||||||
if dirty:
|
if dirty:
|
||||||
if deleteRefs:
|
if deleteRefs:
|
||||||
deck.deleteFactTags(modifiedFacts.keys(), _("Media Missing"))
|
deck.deleteTags(modifiedFacts.keys(), _("Media Missing"))
|
||||||
else:
|
else:
|
||||||
deck.addFactTags(modifiedFacts.keys(), _("Media Missing"))
|
deck.addTags(modifiedFacts.keys(), _("Media Missing"))
|
||||||
deck.deleteFactTags(unmodifiedFacts.keys(), _("Media Missing"))
|
deck.deleteTags(unmodifiedFacts.keys(), _("Media Missing"))
|
||||||
# build cache of db records
|
# build cache of db records
|
||||||
mediaIds = dict(deck.s.all("select filename, id from media"))
|
mediaIds = dict(deck.s.all("select filename, id from media"))
|
||||||
# look through the media dir for any unused files, and delete
|
# look through the media dir for any unused files, and delete
|
||||||
|
|
Loading…
Reference in a new issue