From d127ae4175dc72d983f1de424a79926969888a89 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sun, 8 Feb 2009 03:13:37 +0900 Subject: [PATCH] separate tags with spaces --- anki/deck.py | 34 +++++++++++++++++++++++++++++++--- anki/utils.py | 7 +++---- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/anki/deck.py b/anki/deck.py index 03ecc2480..196ebbb27 100644 --- a/anki/deck.py +++ b/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) diff --git a/anki/utils.py b/anki/utils.py index abe8e815d..e7854411b 100644 --- a/anki/utils.py +++ b/anki/utils.py @@ -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."