mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 07:22:23 -04:00
make sure card model tags are included in allTags(), fix upgrade code
This commit is contained in:
parent
6d7ef66640
commit
55cf34e8ee
1 changed files with 13 additions and 9 deletions
22
anki/deck.py
22
anki/deck.py
|
@ -1438,6 +1438,7 @@ and cards.factId = facts.id""")
|
||||||
"Return a hash listing tags in model & fact."
|
"Return a hash listing tags in model & fact."
|
||||||
t = self.s.column0("select tags from facts")
|
t = self.s.column0("select tags from facts")
|
||||||
t += self.s.column0("select tags from models")
|
t += self.s.column0("select tags from models")
|
||||||
|
t += self.s.column0("select name from cardModels")
|
||||||
return sorted(list(set(parseTags(joinTags(t)))))
|
return sorted(list(set(parseTags(joinTags(t)))))
|
||||||
|
|
||||||
def allUserTags(self):
|
def allUserTags(self):
|
||||||
|
@ -2490,28 +2491,31 @@ where interval < 1""")
|
||||||
deck.s.commit()
|
deck.s.commit()
|
||||||
if deck.version < 26:
|
if deck.version < 26:
|
||||||
# no spaces in tags anymore, separated by space
|
# no spaces in tags anymore, separated by space
|
||||||
|
def munge(tags):
|
||||||
|
tags = re.sub(", ?", "--tmp--", tags)
|
||||||
|
tags = re.sub(" - ", "-", tags)
|
||||||
|
tags = re.sub(" ", "-", tags)
|
||||||
|
tags = re.sub("--tmp--", " ", tags)
|
||||||
|
tags = canonifyTags(tags)
|
||||||
|
return tags
|
||||||
|
|
||||||
rows = deck.s.all('select id, tags from facts')
|
rows = deck.s.all('select id, tags from facts')
|
||||||
d = []
|
d = []
|
||||||
for (id, tags) in rows:
|
for (id, tags) in rows:
|
||||||
d.append({
|
d.append({
|
||||||
'i': id,
|
'i': id,
|
||||||
't': joinTags(sorted(
|
't': munge(tags),
|
||||||
[t.strip().replace(" ", "-") for t in
|
|
||||||
tags.split(",") if t.strip()])),
|
|
||||||
})
|
})
|
||||||
deck.s.statements(
|
deck.s.statements(
|
||||||
"update facts set tags = :t where id = :i", d)
|
"update facts set tags = :t where id = :i", d)
|
||||||
for k in ('highPriority', 'medPriority',
|
for k in ('highPriority', 'medPriority',
|
||||||
'lowPriority', 'suspended'):
|
'lowPriority', 'suspended'):
|
||||||
x = getattr(deck, k)
|
x = getattr(deck, k)
|
||||||
x = re.sub("([^,]) +", "\\1-", x)
|
setattr(deck, k, munge(x))
|
||||||
x = re.sub(",", " ", x)
|
|
||||||
setattr(deck, k, x)
|
|
||||||
for m in deck.models:
|
for m in deck.models:
|
||||||
for cm in m.cardModels:
|
for cm in m.cardModels:
|
||||||
cm.name = cm.name.replace(" ", "-")
|
cm.name = munge(cm.name)
|
||||||
m.tags = re.sub(", ?", " ", m.tags)
|
m.tags = munge(m.tags)
|
||||||
m.tags = canonifyTags(m.tags)
|
|
||||||
deck.updateCardsFromModel(m, dirty=False)
|
deck.updateCardsFromModel(m, dirty=False)
|
||||||
deck.version = 26
|
deck.version = 26
|
||||||
deck.s.commit()
|
deck.s.commit()
|
||||||
|
|
Loading…
Reference in a new issue