Added category support to @tag command; also fixed some bugs.
This commit is contained in:
parent
88d103b55f
commit
3aeec1298a
2 changed files with 30 additions and 13 deletions
|
|
@ -2132,15 +2132,22 @@ class CmdTag(MuxCommand):
|
||||||
return
|
return
|
||||||
if "search" in self.switches:
|
if "search" in self.switches:
|
||||||
# search by tag
|
# search by tag
|
||||||
objs = search.search_tag(self.args)
|
tag = self.args
|
||||||
|
category = None
|
||||||
|
if ":" in tag:
|
||||||
|
tag, category = [part.strip() for part in tag.split(":", 1)]
|
||||||
|
category = "object_%s" % category
|
||||||
|
objs = search.search_tag(tag, category=category)
|
||||||
nobjs = len(objs)
|
nobjs = len(objs)
|
||||||
if nobjs > 0:
|
if nobjs > 0:
|
||||||
string = "Found %i object%s with tag '%s':\n %s" % (nobjs,
|
string = "Found %i object%s with tag '%s'%s:\n %s" % (nobjs,
|
||||||
"s" if nobjs > 1 else "",
|
"s" if nobjs > 1 else "",
|
||||||
self.args,
|
tag,
|
||||||
", ".join(o.key for o in objs))
|
" (category: %s)" % category if category else "",
|
||||||
|
", ".join("%s(#%i)" % (o.key, o.dbid) for o in objs))
|
||||||
else:
|
else:
|
||||||
string = "No objects found with tag %s." % self.args
|
string = "No objects found with tag '%s%s'." % (tag,
|
||||||
|
" (category: %s)" % category if category else "")
|
||||||
self.caller.msg(string)
|
self.caller.msg(string)
|
||||||
return
|
return
|
||||||
if "del" in self.switches:
|
if "del" in self.switches:
|
||||||
|
|
@ -2155,7 +2162,9 @@ class CmdTag(MuxCommand):
|
||||||
if ":" in tag:
|
if ":" in tag:
|
||||||
tag, category = [part.strip() for part in tag.split(":", 1)]
|
tag, category = [part.strip() for part in tag.split(":", 1)]
|
||||||
obj.tags.remove(tag, category=category)
|
obj.tags.remove(tag, category=category)
|
||||||
string = "Removed tag '%s' from %s (if it existed)" % (tag, obj)
|
string = "Removed tag '%s'%s from %s (if it existed)" % (tag,
|
||||||
|
" (category: %s)" % category if category else "",
|
||||||
|
obj)
|
||||||
else:
|
else:
|
||||||
# no tag specified, clear all tags
|
# no tag specified, clear all tags
|
||||||
obj.tags.clear()
|
obj.tags.clear()
|
||||||
|
|
@ -2174,19 +2183,22 @@ class CmdTag(MuxCommand):
|
||||||
tag, category = [part.strip() for part in tag.split(":", 1)]
|
tag, category = [part.strip() for part in tag.split(":", 1)]
|
||||||
# create the tag
|
# create the tag
|
||||||
obj.tags.add(tag, category=category)
|
obj.tags.add(tag, category=category)
|
||||||
string = "Added tag '%s' to %s." % (tag, obj)
|
string = "Added tag '%s'%s to %s." % (tag,
|
||||||
|
" (category: %s)" % category if category else "",
|
||||||
|
obj)
|
||||||
self.caller.msg(string)
|
self.caller.msg(string)
|
||||||
else:
|
else:
|
||||||
# no = found - list tags on object
|
# no = found - list tags on object
|
||||||
obj = self.caller.search(self.args, global_search=True)
|
obj = self.caller.search(self.args, global_search=True)
|
||||||
if not obj:
|
if not obj:
|
||||||
return
|
return
|
||||||
tags = obj.tags.all()
|
tags = obj.db_tags.all()
|
||||||
ntags = len(tags)
|
ntags = len(tags)
|
||||||
|
categories = [tag.db_category.split("_", 1)[1] for tag in tags]
|
||||||
|
categories = [" (category: %s)" % cater if cater else "" for cater in categories]
|
||||||
if ntags:
|
if ntags:
|
||||||
string = "Tag%s on %s: %s" % ("s" if ntags > 1 else "",
|
string = "Tag%s on %s: %s" % ("s" if ntags > 1 else "", obj,
|
||||||
obj,
|
", ".join("'%s'%s" % (tags[i], categories[i]) for i in range(ntags)))
|
||||||
", ".join("'%s'" % tag for tag in obj.tags.all()))
|
|
||||||
else:
|
else:
|
||||||
string = "No tags attached to %s." % obj
|
string = "No tags attached to %s." % obj
|
||||||
self.caller.msg(string)
|
self.caller.msg(string)
|
||||||
|
|
|
||||||
|
|
@ -555,10 +555,15 @@ class TagHandler(object):
|
||||||
_GA(self.obj, self._m2m_fieldname).remove(tag)
|
_GA(self.obj, self._m2m_fieldname).remove(tag)
|
||||||
self._recache()
|
self._recache()
|
||||||
|
|
||||||
def all(self):
|
def all(self, category=None):
|
||||||
"Get all tags in this handler"
|
"Get all tags in this handler"
|
||||||
if self._cache is None or not _TYPECLASS_AGGRESSIVE_CACHE:
|
if self._cache is None or not _TYPECLASS_AGGRESSIVE_CACHE:
|
||||||
self._recache()
|
self._recache()
|
||||||
|
if category:
|
||||||
|
category = "%s%s" % (self.prefix, category.strip().lower()
|
||||||
|
if category is not None else "")
|
||||||
|
return [to_str(p[0]) for p in _GA(self.obj, self._m2m_fieldname).filter(
|
||||||
|
db_category=category).values_list("db_key") if p[0]]
|
||||||
return self._cache.keys()
|
return self._cache.keys()
|
||||||
#return [to_str(p[0]) for p in _GA(self.obj, self._m2m_fieldname).filter(db_category__startswith=self.prefix).values_list("db_key") if p[0]]
|
#return [to_str(p[0]) for p in _GA(self.obj, self._m2m_fieldname).filter(db_category__startswith=self.prefix).values_list("db_key") if p[0]]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue