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('modified', Float, nullable=False, default=time.time),
|
||||
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")),
|
||||
# syncing
|
||||
Column('syncName', UnicodeText),
|
||||
|
|
@ -1408,7 +1408,13 @@ where id in %s""" % ids2str(cardIds), newId=newCardModelId)
|
|||
def tagsList(self, where="", priority=", cards.priority"):
|
||||
"Return a list of (cardId, allTags, priority)"
|
||||
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
|
||||
cards.factId == facts.id and facts.modelId == models.id
|
||||
and cards.cardModelId = cardModels.id %s""" % (priority, where))
|
||||
|
|
@ -2479,9 +2485,31 @@ where interval < 1""")
|
|||
DeckStorage._addViews(deck)
|
||||
DeckStorage._addIndices(deck)
|
||||
deck.updateDynamicIndices()
|
||||
deck.s.statement("vacuum")
|
||||
deck.version = 25
|
||||
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
|
||||
_upgradeDeck = staticmethod(_upgradeDeck)
|
||||
|
||||
|
|
|
|||
|
|
@ -182,12 +182,11 @@ to be integers."""
|
|||
|
||||
def parseTags(tags):
|
||||
"Parse a string and return a list of tags."
|
||||
tags = tags.split(",")
|
||||
tags = [tag.strip() for tag in tags if tag.strip()]
|
||||
return tags
|
||||
tags = re.split(" |, ?", tags)
|
||||
return [t.strip() for t in tags if t.strip()]
|
||||
|
||||
def joinTags(tags):
|
||||
return u", ".join(tags)
|
||||
return u" ".join(tags)
|
||||
|
||||
def canonifyTags(tags):
|
||||
"Strip leading/trailing/superfluous commas and duplicates."
|
||||
|
|
|
|||
Loading…
Reference in a new issue