Changed how Objects are searched, using proper Django Q objects instead of hack-y evals to build queries. This has lead to a number of changes to the ObjectDB manager search. Notably there is now no way to supply a "location" to either of the manager search methods anymore. Instead you can now supply the keyword "candidates", a list of objects which should be used to limit the search. This is much more generic than giving location. The higher-level search (like caller.search, reached from commands) have not changed its API, so commands should work the same unless you are using the manager backbone directly. This search function is now using location to create the "candidates" list. Some other things, like matching for "me" and "here" have also been moved up to a level were it can be easily overloaded. "me" and "here" etc were also moved under i18n.

As part of this overhaul I implemented the partial_matching algorithm originally asked for by user "Adam_ASE" over IRC. This will allow for (local-only) partial matching of objects. So "big black sword" will now be matched by "bi", "sword", "bi bla" and so on. The partial matcher sits in src.utils.utils.py if one wants to use it for something else.
This commit is contained in:
Griatch 2012-09-17 15:31:50 +02:00
parent cc6fa079b6
commit c53a9b5770
7 changed files with 236 additions and 193 deletions

View file

@ -34,7 +34,7 @@ class AttributeManager(models.Manager):
def returns_typeclass_list(method):
"""
Decorator: Chantes return of the decorated method (which are
Decorator: Changes return of the decorated method (which are
TypeClassed objects) into object_classes(s) instead. Will always
return a list (may be empty).
"""
@ -52,11 +52,11 @@ def returns_typeclass(method):
def func(self, *args, **kwargs):
"decorator. Returns result or None."
self.__doc__ = method.__doc__
rfunc = returns_typeclass_list(method)
try:
return rfunc(self, *args, **kwargs)[0]
except IndexError:
return None
matches = method(self, *args, **kwargs)
dbobj = matches and make_iter(matches)[0] or None
if dbobj:
return (hasattr(dbobj, "typeclass") and dbobj.typeclass) or dbobj
return None
return update_wrapper(func, method)