mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
don't create empty tags on export
This commit is contained in:
parent
187caa874b
commit
582a9dd290
2 changed files with 8 additions and 6 deletions
|
@ -54,7 +54,8 @@ class Exporter(object):
|
|||
if not self.limitTags:
|
||||
cards = self.deck.s.column0("select id from cards")
|
||||
else:
|
||||
d = tagIds(self.deck.s, self.limitTags)
|
||||
d = tagIds(self.deck.s, self.limitTags, create=False)
|
||||
print d
|
||||
cards = self.deck.s.column0(
|
||||
"select cardId from cardTags where tagid in %s" %
|
||||
ids2str(d.values()))
|
||||
|
|
11
anki/tags.py
11
anki/tags.py
|
@ -36,21 +36,22 @@ primary key(id))""")
|
|||
except:
|
||||
pass
|
||||
|
||||
def tagId(s, tag):
|
||||
def tagId(s, tag, create=True):
|
||||
"Return ID for tag, creating if necessary."
|
||||
id = s.scalar("select id from tags where tag = :tag", tag=tag)
|
||||
if id:
|
||||
if id or not create:
|
||||
return id
|
||||
s.statement("""
|
||||
insert or ignore into tags
|
||||
(tag) values (:tag)""", tag=tag)
|
||||
return s.scalar("select id from tags where tag = :tag", tag=tag)
|
||||
|
||||
def tagIds(s, tags):
|
||||
def tagIds(s, tags, create=True):
|
||||
"Return an ID for all tags, creating if necessary."
|
||||
ids = {}
|
||||
s.statements("insert or ignore into tags (tag) values (:tag)",
|
||||
[{'tag': t} for t in tags])
|
||||
if create:
|
||||
s.statements("insert or ignore into tags (tag) values (:tag)",
|
||||
[{'tag': t} for t in tags])
|
||||
tagsD = dict([(x.lower(), y) for (x, y) in s.all("""
|
||||
select tag, id from tags
|
||||
where tag in (%s)""" % ",".join([
|
||||
|
|
Loading…
Reference in a new issue