Some streamlining of our database search functions.
This commit is contained in:
parent
6f3f150442
commit
ccf3d90801
3 changed files with 18 additions and 10 deletions
|
|
@ -67,6 +67,12 @@ class Object(models.Model):
|
||||||
# attribute's names.
|
# attribute's names.
|
||||||
attrib_list = {}
|
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:
|
class Meta:
|
||||||
permissions = (
|
permissions = (
|
||||||
("can_examine", "Can examine objects"),
|
("can_examine", "Can examine objects"),
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,7 @@ def do_look(cdat):
|
||||||
Handle looking at objects.
|
Handle looking at objects.
|
||||||
"""
|
"""
|
||||||
session = cdat['session']
|
session = cdat['session']
|
||||||
server = cdat['server']
|
player_loc_obj = session.pobject.location
|
||||||
player_loc = session.player_loc
|
|
||||||
player_loc_obj = server.object_list[player_loc]
|
|
||||||
|
|
||||||
retval = "%s%s%s%s\n\r%s" % (
|
retval = "%s%s%s%s\n\r%s" % (
|
||||||
ansi["normal"],
|
ansi["normal"],
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import sets
|
||||||
from apps.objects.models import Object
|
from apps.objects.models import Object
|
||||||
|
|
||||||
def list_search_object_namestr(searchlist, ostring, dbref_only=False):
|
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:
|
else:
|
||||||
return [prospect for prospect in searchlist if prospect.name_match(ostring)]
|
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.
|
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)
|
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)
|
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 the object the invoker is in matches, add it as well.
|
||||||
if object.location.dbref_match(ostring) or ostring == 'here':
|
if object.location.dbref_match(ostring) or ostring == 'here':
|
||||||
local_matches.append(object.location)
|
local_matches.append(object.location)
|
||||||
|
|
||||||
global_matches = []
|
return local_matches
|
||||||
if is_dbref(ostring):
|
|
||||||
global_matches = list(Object.objects.filter(id=search_query))
|
|
||||||
|
|
||||||
return local_matches + global_matches
|
|
||||||
|
|
||||||
def is_dbref(dbstring):
|
def is_dbref(dbstring):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue