mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -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)
|
return self.deck.tags.inList(tag, self.tags)
|
||||||
|
|
||||||
def stringTags(self):
|
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):
|
def delTag(self, tag):
|
||||||
rem = []
|
rem = []
|
||||||
|
|
|
@ -121,7 +121,7 @@ order by due""" % self._groupLimit(),
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
def groupCounts(self):
|
def groupCounts(self):
|
||||||
"Returns [groupname, hasDue, hasNew]"
|
"Returns [groupname, gid, hasDue, hasNew]"
|
||||||
# find groups with 1 or more due cards
|
# find groups with 1 or more due cards
|
||||||
gids = {}
|
gids = {}
|
||||||
for g in self.deck.groups.all():
|
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)
|
return u" %s " % u" ".join(tags)
|
||||||
|
|
||||||
def addToStr(self, addtags, 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)
|
currentTags = self.split(tags)
|
||||||
for tag in self.split(addtags):
|
for tag in self.split(addtags):
|
||||||
if not self.inList(tag, currentTags):
|
if not self.inList(tag, currentTags):
|
||||||
currentTags.append(tag)
|
currentTags.append(tag)
|
||||||
return self.canonify(currentTags)
|
return self.join(self.canonify(currentTags))
|
||||||
|
|
||||||
def remFromStr(self, deltags, tags):
|
def remFromStr(self, deltags, tags):
|
||||||
"Delete tags if they don't exists."
|
"Delete tags if they don't exists."
|
||||||
|
@ -133,15 +133,14 @@ class TagManager(object):
|
||||||
# remove them
|
# remove them
|
||||||
for r in remove:
|
for r in remove:
|
||||||
currentTags.remove(r)
|
currentTags.remove(r)
|
||||||
return self.canonify(currentTags)
|
return self.join(currentTags)
|
||||||
|
|
||||||
# List-based utilities
|
# List-based utilities
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
def canonify(self, tags):
|
def canonify(self, tagList):
|
||||||
"Strip leading/trailing/superfluous spaces and duplicates."
|
"Strip duplicates and sort."
|
||||||
tags = [t.lstrip(":") for t in set(tags)]
|
return sorted(set(tagList))
|
||||||
return self.join(sorted(tags))
|
|
||||||
|
|
||||||
def inList(self, tag, tags):
|
def inList(self, tag, tags):
|
||||||
"True if TAG is in TAGS. Ignore case."
|
"True if TAG is in TAGS. Ignore case."
|
||||||
|
|
Loading…
Reference in a new issue