mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 01:06:35 -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:
|
if not self.limitTags:
|
||||||
cards = self.deck.s.column0("select id from cards")
|
cards = self.deck.s.column0("select id from cards")
|
||||||
else:
|
else:
|
||||||
d = tagIds(self.deck.s, self.limitTags)
|
d = tagIds(self.deck.s, self.limitTags, create=False)
|
||||||
|
print d
|
||||||
cards = self.deck.s.column0(
|
cards = self.deck.s.column0(
|
||||||
"select cardId from cardTags where tagid in %s" %
|
"select cardId from cardTags where tagid in %s" %
|
||||||
ids2str(d.values()))
|
ids2str(d.values()))
|
||||||
|
|
|
@ -36,19 +36,20 @@ primary key(id))""")
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def tagId(s, tag):
|
def tagId(s, tag, create=True):
|
||||||
"Return ID for tag, creating if necessary."
|
"Return ID for tag, creating if necessary."
|
||||||
id = s.scalar("select id from tags where tag = :tag", tag=tag)
|
id = s.scalar("select id from tags where tag = :tag", tag=tag)
|
||||||
if id:
|
if id or not create:
|
||||||
return id
|
return id
|
||||||
s.statement("""
|
s.statement("""
|
||||||
insert or ignore into tags
|
insert or ignore into tags
|
||||||
(tag) values (:tag)""", tag=tag)
|
(tag) values (:tag)""", tag=tag)
|
||||||
return s.scalar("select id from tags where tag = :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."
|
"Return an ID for all tags, creating if necessary."
|
||||||
ids = {}
|
ids = {}
|
||||||
|
if create:
|
||||||
s.statements("insert or ignore into tags (tag) values (:tag)",
|
s.statements("insert or ignore into tags (tag) values (:tag)",
|
||||||
[{'tag': t} for t in tags])
|
[{'tag': t} for t in tags])
|
||||||
tagsD = dict([(x.lower(), y) for (x, y) in s.all("""
|
tagsD = dict([(x.lower(), y) for (x, y) in s.all("""
|
||||||
|
|
Loading…
Reference in a new issue