Made several admin commands handle multi-word global searching; defined a new search function on objects.model for global name searching.

/Griatch
This commit is contained in:
Griatch 2009-10-21 18:42:52 +00:00
parent d8787bfc70
commit 9b6bd7125f
3 changed files with 40 additions and 31 deletions

View file

@ -145,8 +145,9 @@ class ObjectManager(models.Manager):
o_query = self.filter(name__iexact=ostring)
else:
o_query = self.filter(name__icontains=ostring)
if limit_types:
o_query = o_query.include(type__in=limit_types)
if limit_types is not False:
for limiter in limit_types:
o_query.filter(type=limiter)
return o_query.exclude(type__in=[defines_global.OTYPE_GARBAGE,
defines_global.OTYPE_GOING])

View file

@ -220,6 +220,27 @@ class Object(models.Model):
return False
else:
return results[0]
def search_for_object_global(self, ostring, exact_match=True, limit_types=[]):
"""
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.
"""
results = Object.objects.global_object_name_search(ostring, exact_match=exact_match,
limit_types=limit_types)
if not results:
self.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)
return
return results[0]
def get_sessions(self):
"""