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)
if quiet:
return results
return _AT_SEARCH_RESULT(self, searchdata, results, True)
return _AT_SEARCH_RESULT(self, searchdata, results, global_search=True)
#
# Execution/action methods

View file

@ -297,7 +297,7 @@ class Object(TypeClass):
# searchdata is a string; wrap some common self-references
if searchdata.lower() in ("me", "self",):
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):
"""

View file

@ -35,8 +35,8 @@ from django.utils.translation import ugettext as _
__all__ = ("PlayerDB",)
_ME = _("me")
_SELF = _("self")
#_ME = _("me")
#_SELF = _("self")
_SESSIONS = None
_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
character = property(__get_single_puppet)
puppet = property(__get_single_puppet)
# utility methods
@ -442,34 +443,30 @@ class PlayerDB(TypedObject, AbstractUser):
return cmdhandler.cmdhandler(self.typeclass, raw_string,
callertype="player", sessid=sessid)
def search(self, ostring, return_puppet=False,
return_character=False, **kwargs):
def search(self, searchdata, return_puppet=False, **kwargs):
"""
This is similar to the ObjectDB search method but will search for
Players only. Errors will be echoed, and None returned if no Player
is found.
return_character - will try to return the character the player controls
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
Character exists (since Player is OOC), None will
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.
API more consistent with objects.models.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.")
#return_puppet = return_character
# handle me, self
if ostring in (_ME, _SELF, '*' + _ME, '*' + _SELF):
return self
return_puppet = kwargs.get("return_character")
matches = _GA(self, "__class__").objects.player_search(ostring)
matches = _AT_SEARCH_RESULT(self, ostring, matches, global_search=True)
if matches and return_character:
matches = _GA(self, "__class__").objects.player_search(searchdata)
matches = _AT_SEARCH_RESULT(self, searchdata, matches, global_search=True)
if matches and return_puppet:
try:
return _GA(matches, "character")
except:
pass
return _GA(matches, "puppet")
except AttributeError:
return None
return matches

View file

@ -157,14 +157,25 @@ class Player(TypeClass):
"""
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
other Players can be searched with this method.
extra keywords are accepted but ignored to make API more consistent with
TypedObject.search.
This is similar to the Object search method but will search for
Players only. Errors will be echoed, and None returned if no Player
is found.
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):
"""