mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
tweak tag handling
This commit is contained in:
parent
ffc096e308
commit
10e1c1b03e
3 changed files with 11 additions and 9 deletions
|
@ -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 = []
|
||||
|
|
|
@ -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():
|
||||
|
|
13
anki/tags.py
13
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."
|
||||
|
|
Loading…
Reference in a new issue