Added VisibleKey, allowing objects to be locked so they are not visible by normal look command.

Fixed bug in create_object that sometimes caused rooms to be created with a location !=None
Expanded @destroy to better handle names and not just dbrefs.
/Griatch
This commit is contained in:
Griatch 2009-10-22 19:44:16 +00:00
parent 557c4eb07b
commit 656ecd9f97
6 changed files with 163 additions and 42 deletions

View file

@ -133,21 +133,35 @@ class ObjectManager(models.Manager):
except IndexError:
return None
def global_object_name_search(self, ostring, exact_match=False, limit_types=[]):
def global_object_name_search(self, ostring, exact_match=True, limit_types=[]):
"""
Searches through all objects for a name match.
limit_types is a list of types as defined in defines_global.
"""
if self.is_dbref(ostring):
return [self.dbref_search(ostring, limit_types=limit_types)]
o_query = self.dbref_search(ostring, limit_types=limit_types)
if o_query:
return [o_query]
return None
# get rough match
o_query = self.filter(name__icontains=ostring)
o_query = o_query.exclude(type__in=[defines_global.OTYPE_GARBAGE,
defines_global.OTYPE_GOING])
if not o_query:
# use list-search to catch N-style queries. Note
# that we want to keep the original ostring since
# search_object_namestr does its own N-string treatment
# on this.
dum, test_ostring = self._parse_match_number(ostring)
o_query = self.filter(name__icontains=test_ostring)
o_query = o_query.exclude(type__in=[defines_global.OTYPE_GARBAGE,
defines_global.OTYPE_GOING])
match_type = "fuzzy"
if exact_match:
o_query = self.filter(name__iexact=ostring)
else:
o_query = self.filter(name__icontains=ostring)
if limit_types is not False:
for limiter in limit_types:
o_query.filter(type=limiter)
match_type = "exact"
return self.list_search_object_namestr(o_query, ostring,
limit_types=limit_types,
match_type=match_type)
return o_query.exclude(type__in=[defines_global.OTYPE_GARBAGE,
defines_global.OTYPE_GOING])
@ -196,16 +210,16 @@ class ObjectManager(models.Manager):
if prospect.dbref_match(ostring)]
#search by name - this may return multiple matches.
results = self._list_search_helper1(searchlist,ostring,dbref_only,
results = self._match_name_attribute(searchlist,ostring,dbref_only,
limit_types, match_type,
attribute_name=attribute_name)
match_number = None
if not results:
#if we have no match, check if we are dealing
#with a "N-keyword" query - if so, strip it and run again.
match_number, ostring = self._list_search_helper2(ostring)
match_number, ostring = self._parse_match_number(ostring)
if match_number != None and ostring:
results = self._list_search_helper1(searchlist,ostring,dbref_only,
results = self._match_name_attribute(searchlist,ostring,dbref_only,
limit_types, match_type,
attribute_name=attribute_name)
if match_type == "fuzzy":
@ -226,7 +240,7 @@ class ObjectManager(models.Manager):
pass
return results
def _list_search_helper1(self, searchlist, ostring, dbref_only,
def _match_name_attribute(self, searchlist, ostring, dbref_only,
limit_types, match_type,
attribute_name=None):
"""
@ -261,10 +275,10 @@ class ObjectManager(models.Manager):
return [prospect for prospect in searchlist
if prospect.name_match(ostring, match_type=match_type)]
def _list_search_helper2(self, ostring):
def _parse_match_number(self, ostring):
"""
Hhelper function for list_search_object_namestr -
strips eventual keyword-N endings from a search criterion
Helper function for list_search_object_namestr -
strips eventual N-keyword endings from a search criterion
"""
if not '-' in ostring:
return False, ostring
@ -426,6 +440,7 @@ class ObjectManager(models.Manager):
default_desc = defines_global.DESC_PLAYER
elif otype == defines_global.OTYPE_ROOM:
default_desc = defines_global.DESC_ROOM
location = None
elif otype == defines_global.OTYPE_EXIT:
default_desc = defines_global.DESC_EXIT
else:

View file

@ -221,23 +221,27 @@ class Object(models.Model):
else:
return results[0]
def search_for_object_global(self, ostring, exact_match=True, limit_types=[]):
def search_for_object_global(self, ostring, exact_match=True, limit_types=[],
emit_to_obj=None):
"""
Search for ostring in all objects, globally. Handle multiple-matches
and no matches gracefully. This is mainly intended to be used by
admin and build-type commands. It also accepts #dbref
search queries.
"""
if not emit_to_obj:
emit_to_obj = self
results = Object.objects.global_object_name_search(ostring, exact_match=exact_match,
limit_types=limit_types)
limit_types=limit_types)
if not results:
self.emit_to("No matches found for '%s'." % ostring)
emit_to_obj.emit_to("No matches found for '%s'." % ostring)
return
if len(results) > 1:
string = "More than one match for '%s' (please narrow target):" % ostring
for res in results:
string += "\n %s" % res.get_name()
self.emit_to(string)
emit_to_obj.emit_to(string)
return
return results[0]
@ -1157,7 +1161,10 @@ class Object(models.Model):
self.clear_all_attributes()
self.clear_all_flags()
self.clear_state()
self.home = None
self.owner = None
self.location = None
self.save()
# Deferred imports are poopy. This will require some thought to fix.
from src import cmdhandler