From 10e1c1b03ee5dcbf69ee93425fb11a3b7b3ceca2 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 23 Nov 2011 11:39:33 +0900 Subject: [PATCH] tweak tag handling --- anki/facts.py | 5 ++++- anki/sched.py | 2 +- anki/tags.py | 13 ++++++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/anki/facts.py b/anki/facts.py index 15885cd06..5e93a0ba4 100644 --- a/anki/facts.py +++ b/anki/facts.py @@ -122,7 +122,10 @@ insert or replace into facts values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""", return self.deck.tags.inList(tag, self.tags) def stringTags(self): - return self.deck.tags.canonify(self.tags) + return self.deck.tags.join(self.deck.tags.canonify(self.tags)) + + def setTagsFromStr(self, str): + self.tags = self.deck.tags.split(str) def delTag(self, tag): rem = [] diff --git a/anki/sched.py b/anki/sched.py index a70b49e3d..10cc6a9b9 100644 --- a/anki/sched.py +++ b/anki/sched.py @@ -121,7 +121,7 @@ order by due""" % self._groupLimit(), ########################################################################## def groupCounts(self): - "Returns [groupname, hasDue, hasNew]" + "Returns [groupname, gid, hasDue, hasNew]" # find groups with 1 or more due cards gids = {} for g in self.deck.groups.all(): diff --git a/anki/tags.py b/anki/tags.py index 9b05b27c9..07de18723 100644 --- a/anki/tags.py +++ b/anki/tags.py @@ -114,12 +114,12 @@ class TagManager(object): return u" %s " % u" ".join(tags) def addToStr(self, addtags, tags): - "Add tags if they don't exist." + "Add tags if they don't exist, and canonify." currentTags = self.split(tags) for tag in self.split(addtags): if not self.inList(tag, currentTags): currentTags.append(tag) - return self.canonify(currentTags) + return self.join(self.canonify(currentTags)) def remFromStr(self, deltags, tags): "Delete tags if they don't exists." @@ -133,15 +133,14 @@ class TagManager(object): # remove them for r in remove: currentTags.remove(r) - return self.canonify(currentTags) + return self.join(currentTags) # List-based utilities ########################################################################## - def canonify(self, tags): - "Strip leading/trailing/superfluous spaces and duplicates." - tags = [t.lstrip(":") for t in set(tags)] - return self.join(sorted(tags)) + def canonify(self, tagList): + "Strip duplicates and sort." + return sorted(set(tagList)) def inList(self, tag, tags): "True if TAG is in TAGS. Ignore case."