Fixed player.search() to also move here/me/self wrappers to typeclass.

This commit is contained in:
Griatch 2014-04-13 10:04:35 +02:00
parent 661eb0c23b
commit 59513e5c00
4 changed files with 36 additions and 28 deletions

View file

@ -427,7 +427,7 @@ class ObjectDB(TypedObject):
results = PlayerDB.objects.player_search(searchdata) results = PlayerDB.objects.player_search(searchdata)
if quiet: if quiet:
return results return results
return _AT_SEARCH_RESULT(self, searchdata, results, True) return _AT_SEARCH_RESULT(self, searchdata, results, global_search=True)
# #
# Execution/action methods # Execution/action methods

View file

@ -297,7 +297,7 @@ class Object(TypeClass):
# searchdata is a string; wrap some common self-references # searchdata is a string; wrap some common self-references
if searchdata.lower() in ("me", "self",): if searchdata.lower() in ("me", "self",):
return self.player return self.player
self.dbobj.search_player(searchdata, quiet=quiet) return self.dbobj.search_player(searchdata, quiet=quiet)
def execute_cmd(self, raw_string, sessid=None): def execute_cmd(self, raw_string, sessid=None):
""" """

View file

@ -35,8 +35,8 @@ from django.utils.translation import ugettext as _
__all__ = ("PlayerDB",) __all__ = ("PlayerDB",)
_ME = _("me") #_ME = _("me")
_SELF = _("self") #_SELF = _("self")
_SESSIONS = None _SESSIONS = None
_AT_SEARCH_RESULT = utils.variable_from_module(*settings.SEARCH_AT_RESULT.rsplit('.', 1)) _AT_SEARCH_RESULT = utils.variable_from_module(*settings.SEARCH_AT_RESULT.rsplit('.', 1))
@ -402,6 +402,7 @@ class PlayerDB(TypedObject, AbstractUser):
return puppets and puppets[0] or None return puppets and puppets[0] or None
return puppets return puppets
character = property(__get_single_puppet) character = property(__get_single_puppet)
puppet = property(__get_single_puppet)
# utility methods # utility methods
@ -442,34 +443,30 @@ class PlayerDB(TypedObject, AbstractUser):
return cmdhandler.cmdhandler(self.typeclass, raw_string, return cmdhandler.cmdhandler(self.typeclass, raw_string,
callertype="player", sessid=sessid) callertype="player", sessid=sessid)
def search(self, ostring, return_puppet=False, def search(self, searchdata, return_puppet=False, **kwargs):
return_character=False, **kwargs):
""" """
This is similar to the ObjectDB search method but will search for This is similar to the ObjectDB search method but will search for
Players only. Errors will be echoed, and None returned if no Player Players only. Errors will be echoed, and None returned if no Player
is found. is found.
searchdata - search criterion, the Player's key or dbref to search for
return_character - will try to return the character the player controls return_puppet - will try to return the object the player controls
instead of the Player object itself. If no instead of the Player object itself. If no
Character exists (since Player is OOC), None will puppeted object exists (since Player is OOC), None will
be returned. be returned.
Extra keywords are ignored, but are allowed in call in order to make Extra keywords are ignored, but are allowed in call in order to make
API more consistent with objects.models. API more consistent with objects.models.TypedObject.search.
TypedObject.search.
""" """
if return_character: #TODO deprecation
if "return_character" in kwargs:
logger.log_depmsg("Player.search's 'return_character' keyword is deprecated. Use the return_puppet keyword instead.") logger.log_depmsg("Player.search's 'return_character' keyword is deprecated. Use the return_puppet keyword instead.")
#return_puppet = return_character return_puppet = kwargs.get("return_character")
# handle me, self
if ostring in (_ME, _SELF, '*' + _ME, '*' + _SELF):
return self
matches = _GA(self, "__class__").objects.player_search(ostring) matches = _GA(self, "__class__").objects.player_search(searchdata)
matches = _AT_SEARCH_RESULT(self, ostring, matches, global_search=True) matches = _AT_SEARCH_RESULT(self, searchdata, matches, global_search=True)
if matches and return_character: if matches and return_puppet:
try: try:
return _GA(matches, "character") return _GA(matches, "puppet")
except: except AttributeError:
pass return None
return matches return matches

View file

@ -157,14 +157,25 @@ class Player(TypeClass):
""" """
return self.dbobj.execute_cmd(raw_string, sessid=sessid) return self.dbobj.execute_cmd(raw_string, sessid=sessid)
def search(self, ostring, return_character=False, **kwargs): def search(self, searchdata, return_puppet=False, **kwargs):
""" """
This method mimicks object.search if self.character is set. Otherwise only This is similar to the Object search method but will search for
other Players can be searched with this method. Players only. Errors will be echoed, and None returned if no Player
extra keywords are accepted but ignored to make API more consistent with is found.
TypedObject.search. searchdata - search criterion, the Player's key or dbref to search for
return_puppet - will try to return the object the player controls
instead of the Player object itself. If no
puppeted object exists (since Player is OOC), None will
be returned.
Extra keywords are ignored, but are allowed in call in order to make
API more consistent with objects.models.TypedObject.search.
""" """
return self.dbobj.search(ostring, return_character=return_character) # handle me, self and *me, *self
if isinstance(searchdata, basestring):
# handle wrapping of common terms
if searchdata.lower() in ("me", "*me", "self", "*self",):
return self
return self.dbobj.search(searchdata, return_puppet=return_puppet, **kwargs)
def is_typeclass(self, typeclass, exact=False): def is_typeclass(self, typeclass, exact=False):
""" """