From ccf3d9080174873f4be8adfb0c2d4392e1e6d934 Mon Sep 17 00:00:00 2001 From: Greg Taylor Date: Sun, 3 Dec 2006 03:39:46 +0000 Subject: [PATCH] Some streamlining of our database search functions. --- evennia/trunk/apps/objects/models.py | 6 ++++++ evennia/trunk/commands_general.py | 4 +--- evennia/trunk/functions_db.py | 18 +++++++++++------- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/evennia/trunk/apps/objects/models.py b/evennia/trunk/apps/objects/models.py index b8312bae23..aeda491f4e 100755 --- a/evennia/trunk/apps/objects/models.py +++ b/evennia/trunk/apps/objects/models.py @@ -67,6 +67,12 @@ class Object(models.Model): # attribute's names. attrib_list = {} + def __cmp__(self, other): + """ + Used to figure out if one object is the same as another. + """ + return self.id == other.id + class Meta: permissions = ( ("can_examine", "Can examine objects"), diff --git a/evennia/trunk/commands_general.py b/evennia/trunk/commands_general.py index 5a482bd1db..cd81013457 100644 --- a/evennia/trunk/commands_general.py +++ b/evennia/trunk/commands_general.py @@ -13,9 +13,7 @@ def do_look(cdat): Handle looking at objects. """ session = cdat['session'] - server = cdat['server'] - player_loc = session.player_loc - player_loc_obj = server.object_list[player_loc] + player_loc_obj = session.pobject.location retval = "%s%s%s%s\n\r%s" % ( ansi["normal"], diff --git a/evennia/trunk/functions_db.py b/evennia/trunk/functions_db.py index 7430708efe..143bf8c6e3 100644 --- a/evennia/trunk/functions_db.py +++ b/evennia/trunk/functions_db.py @@ -1,3 +1,4 @@ +import sets from apps.objects.models import Object def list_search_object_namestr(searchlist, ostring, dbref_only=False): @@ -10,23 +11,26 @@ def list_search_object_namestr(searchlist, ostring, dbref_only=False): else: return [prospect for prospect in searchlist if prospect.name_match(ostring)] -def local_and_global_search(object, ostring): +def local_and_global_search(object, ostring, local_only=False): """ Searches an object's location then globally for a dbref or name match. + local_only: Only compare the objects in the player's location if True. """ search_query = ''.join(ostring) - + + if is_dbref(ostring) and not local_only: + search_num = search_query[1:] + dbref_match = list(Object.objects.filter(id=search_num)) + if len(dbref_match) > 0: + return dbref_match + local_matches = list_search_object_namestr(object.location.contents_list, search_query) # If the object the invoker is in matches, add it as well. if object.location.dbref_match(ostring) or ostring == 'here': local_matches.append(object.location) - global_matches = [] - if is_dbref(ostring): - global_matches = list(Object.objects.filter(id=search_query)) - - return local_matches + global_matches + return local_matches def is_dbref(dbstring): """