mirror of
https://github.com/ankitects/anki.git
synced 2025-11-10 14:47:12 -05:00
separate tags with spaces
This commit is contained in:
parent
28f738f069
commit
d127ae4175
2 changed files with 34 additions and 7 deletions
34
anki/deck.py
34
anki/deck.py
|
|
@ -53,7 +53,7 @@ decksTable = Table(
|
||||||
Column('created', Float, nullable=False, default=time.time),
|
Column('created', Float, nullable=False, default=time.time),
|
||||||
Column('modified', Float, nullable=False, default=time.time),
|
Column('modified', Float, nullable=False, default=time.time),
|
||||||
Column('description', UnicodeText, nullable=False, default=u""),
|
Column('description', UnicodeText, nullable=False, default=u""),
|
||||||
Column('version', Integer, nullable=False, default=25),
|
Column('version', Integer, nullable=False, default=26),
|
||||||
Column('currentModelId', Integer, ForeignKey("models.id")),
|
Column('currentModelId', Integer, ForeignKey("models.id")),
|
||||||
# syncing
|
# syncing
|
||||||
Column('syncName', UnicodeText),
|
Column('syncName', UnicodeText),
|
||||||
|
|
@ -1408,7 +1408,13 @@ where id in %s""" % ids2str(cardIds), newId=newCardModelId)
|
||||||
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, facts.tags || "," || models.tags || "," ||
|
select cards.id, facts.tags || " " || models.tags || " " ||
|
||||||
|
cardModels.name %s from cards, facts, models, cardModels where
|
||||||
|
cards.factId == facts.id and facts.modelId == models.id
|
||||||
|
and cards.cardModelId = cardModels.id %s""" % (priority, where))
|
||||||
|
|
||||||
|
return self.s.all("""
|
||||||
|
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))
|
||||||
|
|
@ -2479,9 +2485,31 @@ where interval < 1""")
|
||||||
DeckStorage._addViews(deck)
|
DeckStorage._addViews(deck)
|
||||||
DeckStorage._addIndices(deck)
|
DeckStorage._addIndices(deck)
|
||||||
deck.updateDynamicIndices()
|
deck.updateDynamicIndices()
|
||||||
deck.s.statement("vacuum")
|
|
||||||
deck.version = 25
|
deck.version = 25
|
||||||
deck.s.commit()
|
deck.s.commit()
|
||||||
|
if deck.version < 26:
|
||||||
|
# no spaces in tags anymore, separated by space
|
||||||
|
rows = deck.s.all('select id, tags from facts')
|
||||||
|
d = []
|
||||||
|
for (id, tags) in rows:
|
||||||
|
d.append({
|
||||||
|
'i': id,
|
||||||
|
't': joinTags(
|
||||||
|
[t.strip().replace(" ", "-") for t in
|
||||||
|
tags.split(",") if t.strip()]),
|
||||||
|
'tt': time.time(),
|
||||||
|
})
|
||||||
|
deck.s.statements(
|
||||||
|
"update facts set tags = :t, modified = :tt where id = :i", d)
|
||||||
|
for m in deck.models:
|
||||||
|
for cm in m.cardModels:
|
||||||
|
cm.name = cm.name.replace(" ", "-")
|
||||||
|
m.tags = m.tags.replace(" ", "-")
|
||||||
|
m.setModified()
|
||||||
|
deck.updateCardsFromModel(m, dirty=False)
|
||||||
|
deck.version = 26
|
||||||
|
deck.s.commit()
|
||||||
|
deck.s.statement("vacuum")
|
||||||
return deck
|
return deck
|
||||||
_upgradeDeck = staticmethod(_upgradeDeck)
|
_upgradeDeck = staticmethod(_upgradeDeck)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -182,12 +182,11 @@ to be integers."""
|
||||||
|
|
||||||
def parseTags(tags):
|
def parseTags(tags):
|
||||||
"Parse a string and return a list of tags."
|
"Parse a string and return a list of tags."
|
||||||
tags = tags.split(",")
|
tags = re.split(" |, ?", tags)
|
||||||
tags = [tag.strip() for tag in tags if tag.strip()]
|
return [t.strip() for t in tags if t.strip()]
|
||||||
return tags
|
|
||||||
|
|
||||||
def joinTags(tags):
|
def joinTags(tags):
|
||||||
return u", ".join(tags)
|
return u" ".join(tags)
|
||||||
|
|
||||||
def canonifyTags(tags):
|
def canonifyTags(tags):
|
||||||
"Strip leading/trailing/superfluous commas and duplicates."
|
"Strip leading/trailing/superfluous commas and duplicates."
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue