Continuing to clean up and fix bugs around Attribute/Tag
This commit is contained in:
parent
bad24513e0
commit
b1e08c7da6
5 changed files with 53 additions and 44 deletions
|
|
@ -1676,15 +1676,19 @@ class CmdExamine(ObjManipCommand):
|
||||||
perms_string += " [Superuser]"
|
perms_string += " [Superuser]"
|
||||||
|
|
||||||
string += "\n{wPermissions{n: %s" % perms_string
|
string += "\n{wPermissions{n: %s" % perms_string
|
||||||
|
|
||||||
|
tags_string = utils.fill(", ".join(tag for tag in obj.tags.all()), indent=5)
|
||||||
|
if tags_string:
|
||||||
|
string += "\n{wTags{n: %s" % tags_string
|
||||||
|
|
||||||
locks = str(obj.locks)
|
locks = str(obj.locks)
|
||||||
if locks:
|
if locks:
|
||||||
locks_string = utils.fill("; ".join([lock for lock in locks.split(';')]), indent=6)
|
locks_string = utils.fill("; ".join([lock for lock in locks.split(';')]), indent=6)
|
||||||
else:
|
else:
|
||||||
locks_string = " Default"
|
locks_string = " Default"
|
||||||
|
|
||||||
|
|
||||||
string += "\n{wLocks{n:%s" % locks_string
|
string += "\n{wLocks{n:%s" % locks_string
|
||||||
|
|
||||||
|
|
||||||
if not (len(obj.cmdset.all()) == 1 and obj.cmdset.current.key == "_EMPTY_CMDSET"):
|
if not (len(obj.cmdset.all()) == 1 and obj.cmdset.current.key == "_EMPTY_CMDSET"):
|
||||||
stored_cmdsets = obj.cmdset.all()
|
stored_cmdsets = obj.cmdset.all()
|
||||||
stored_cmdsets.sort(key=lambda x: x.priority, reverse=True)
|
stored_cmdsets.sort(key=lambda x: x.priority, reverse=True)
|
||||||
|
|
@ -2148,7 +2152,7 @@ class CmdTag(MuxCommand):
|
||||||
"Implement the @tag functionality"
|
"Implement the @tag functionality"
|
||||||
|
|
||||||
if not self.args:
|
if not self.args:
|
||||||
self.caller.msg("Usage: @tag[/switches] [<tag>|<obj>[=<tag>[<category>]]")
|
self.caller.msg("Usage: @tag[/switches] <obj> [= <tag>[:<category>]]")
|
||||||
return
|
return
|
||||||
if "search" in self.switches:
|
if "search" in self.switches:
|
||||||
# search by tag
|
# search by tag
|
||||||
|
|
|
||||||
|
|
@ -375,9 +375,9 @@ class ObjectDB(TypedObject):
|
||||||
|
|
||||||
if use_nicks:
|
if use_nicks:
|
||||||
# get all valid nicks to search
|
# get all valid nicks to search
|
||||||
nicks = self.nicks.all(category="object")
|
nicks = self.nicks.get(category="object")
|
||||||
if self.has_player:
|
if self.has_player:
|
||||||
pnicks = self.nicks.all(category="player")
|
pnicks = self.nicks.get(category="player")
|
||||||
nicks = nicks + pnicks
|
nicks = nicks + pnicks
|
||||||
for nick in nicks:
|
for nick in nicks:
|
||||||
if searchdata == nick.db_key:
|
if searchdata == nick.db_key:
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,39 @@ __all__ = ("AttributeManager", "TypedObjectManager")
|
||||||
_GA = object.__getattribute__
|
_GA = object.__getattribute__
|
||||||
_ObjectDB = None
|
_ObjectDB = None
|
||||||
|
|
||||||
|
#
|
||||||
|
# helper functions for the TypedObjectManager.
|
||||||
|
#
|
||||||
|
|
||||||
|
def returns_typeclass_list(method):
|
||||||
|
"""
|
||||||
|
Decorator: Changes return of the decorated method (which are
|
||||||
|
TypeClassed objects) into object_classes(s) instead. Will always
|
||||||
|
return a list (may be empty).
|
||||||
|
"""
|
||||||
|
def func(self, *args, **kwargs):
|
||||||
|
"decorator. Returns a list."
|
||||||
|
self.__doc__ = method.__doc__
|
||||||
|
matches = make_iter(method(self, *args, **kwargs))
|
||||||
|
return [(hasattr(dbobj, "typeclass") and dbobj.typeclass) or dbobj
|
||||||
|
for dbobj in make_iter(matches)]
|
||||||
|
return update_wrapper(func, method)
|
||||||
|
|
||||||
|
|
||||||
|
def returns_typeclass(method):
|
||||||
|
"""
|
||||||
|
Decorator: Will always return a single typeclassed result or None.
|
||||||
|
"""
|
||||||
|
def func(self, *args, **kwargs):
|
||||||
|
"decorator. Returns result or None."
|
||||||
|
self.__doc__ = method.__doc__
|
||||||
|
matches = method(self, *args, **kwargs)
|
||||||
|
dbobj = matches and make_iter(matches)[0] or None
|
||||||
|
if dbobj:
|
||||||
|
return (hasattr(dbobj, "typeclass") and dbobj.typeclass) or dbobj
|
||||||
|
return None
|
||||||
|
return update_wrapper(func, method)
|
||||||
|
|
||||||
# Managers
|
# Managers
|
||||||
|
|
||||||
def _attr_pickled(method):
|
def _attr_pickled(method):
|
||||||
|
|
@ -134,6 +167,7 @@ class TagManager(models.Manager):
|
||||||
else:
|
else:
|
||||||
return list(tags)
|
return list(tags)
|
||||||
|
|
||||||
|
@returns_typeclass_list
|
||||||
def get_objs_with_tag(self, key=None, category=None, model="objects.objectdb", tagtype=None):
|
def get_objs_with_tag(self, key=None, category=None, model="objects.objectdb", tagtype=None):
|
||||||
"""
|
"""
|
||||||
Search and return all objects of objclass that has tags matching
|
Search and return all objects of objclass that has tags matching
|
||||||
|
|
@ -173,38 +207,6 @@ class TagManager(models.Manager):
|
||||||
return make_iter(tag)[0]
|
return make_iter(tag)[0]
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# helper functions for the TypedObjectManager.
|
|
||||||
#
|
|
||||||
|
|
||||||
def returns_typeclass_list(method):
|
|
||||||
"""
|
|
||||||
Decorator: Changes return of the decorated method (which are
|
|
||||||
TypeClassed objects) into object_classes(s) instead. Will always
|
|
||||||
return a list (may be empty).
|
|
||||||
"""
|
|
||||||
def func(self, *args, **kwargs):
|
|
||||||
"decorator. Returns a list."
|
|
||||||
self.__doc__ = method.__doc__
|
|
||||||
matches = make_iter(method(self, *args, **kwargs))
|
|
||||||
return [(hasattr(dbobj, "typeclass") and dbobj.typeclass) or dbobj
|
|
||||||
for dbobj in make_iter(matches)]
|
|
||||||
return update_wrapper(func, method)
|
|
||||||
|
|
||||||
|
|
||||||
def returns_typeclass(method):
|
|
||||||
"""
|
|
||||||
Decorator: Will always return a single typeclassed result or None.
|
|
||||||
"""
|
|
||||||
def func(self, *args, **kwargs):
|
|
||||||
"decorator. Returns result or None."
|
|
||||||
self.__doc__ = method.__doc__
|
|
||||||
matches = method(self, *args, **kwargs)
|
|
||||||
dbobj = matches and make_iter(matches)[0] or None
|
|
||||||
if dbobj:
|
|
||||||
return (hasattr(dbobj, "typeclass") and dbobj.typeclass) or dbobj
|
|
||||||
return None
|
|
||||||
return update_wrapper(func, method)
|
|
||||||
|
|
||||||
|
|
||||||
#class TypedObjectManager(idmap.CachingManager):
|
#class TypedObjectManager(idmap.CachingManager):
|
||||||
|
|
|
||||||
|
|
@ -533,8 +533,10 @@ class TagHandler(object):
|
||||||
def add(self, tag, category=None, data=None):
|
def add(self, tag, category=None, data=None):
|
||||||
"Add a new tag to the handler. Tag is a string or a list of strings."
|
"Add a new tag to the handler. Tag is a string or a list of strings."
|
||||||
for tagstr in make_iter(tag):
|
for tagstr in make_iter(tag):
|
||||||
tagstr = tagstr.strip().lower() if tagstr is not None else None
|
if not tagstr:
|
||||||
category = category().lower() if category is not None else None
|
continue
|
||||||
|
tagstr = tagstr.strip().lower()
|
||||||
|
category = category.strip().lower() if category is not None else None
|
||||||
data = str(data) if data is not None else None
|
data = str(data) if data is not None else None
|
||||||
# this will only create tag if no matches existed beforehand (it
|
# this will only create tag if no matches existed beforehand (it
|
||||||
# will overload data on an existing tag since that is not
|
# will overload data on an existing tag since that is not
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,8 @@ from django.contrib.contenttypes.models import ContentType
|
||||||
# limit symbol import from API
|
# limit symbol import from API
|
||||||
__all__ = ("search_object", "search_player", "search_script",
|
__all__ = ("search_object", "search_player", "search_script",
|
||||||
"search_message", "search_channel", "search_help_entry",
|
"search_message", "search_channel", "search_help_entry",
|
||||||
"search_tag")
|
"search_object_tag", "search_script_tag", "search_player_tag",
|
||||||
|
"search_channel_tag")
|
||||||
|
|
||||||
|
|
||||||
# import objects this way to avoid circular import problems
|
# import objects this way to avoid circular import problems
|
||||||
|
|
@ -189,10 +190,10 @@ help_entries = search_help_entries
|
||||||
# Note that this returns the object attached to the tag, not the tag itself
|
# Note that this returns the object attached to the tag, not the tag itself
|
||||||
# (this is usually what you want)
|
# (this is usually what you want)
|
||||||
search_tag = Tag.objects.get_objs_with_tag
|
search_tag = Tag.objects.get_objs_with_tag
|
||||||
search_player_tag = lambda key, category: Tag.objects.get_objs_with_tag(key, category, model="objects.objectdb")
|
def search_object_tag(key, category=None): return Tag.objects.get_objs_with_tag(key, category, model="objects.objectdb")
|
||||||
search_player_tag = lambda key, category: Tag.objects.get_objs_with_tag(key, category, model="players.playerdb")
|
def search_player_tag(key, category=None): return Tag.objects.get_objs_with_tag(key, category, model="players.playerdb")
|
||||||
search_script_tag = lambda key, category: Tag.objects.get_objs_with_tag(key, category, model="scripts.scriptdb")
|
def search_script_tag(key, category=None): return Tag.objects.get_objs_with_tag(key, category, model="scripts.scriptdb")
|
||||||
search_channel_tag = lambda key, category: Tag.objects.get_objs_with_tag(key, category, model="comms.channeldb")
|
def search_channel_tag(key, category=None): return Tag.objects.get_objs_with_tag(key, category, model="comms.channeldb")
|
||||||
|
|
||||||
# """
|
# """
|
||||||
# Search and return all tags matching any combination of
|
# Search and return all tags matching any combination of
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue