mirror of
https://github.com/evennia/evennia.git
synced 2026-04-01 05:27:17 +02:00
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:
parent
d8787bfc70
commit
9b6bd7125f
3 changed files with 40 additions and 31 deletions
|
|
@ -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])
|
||||
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue