From 904884d4edd6f0fc63de02d4986497cba57ed61d Mon Sep 17 00:00:00 2001 From: lagos Date: Mon, 22 Oct 2012 18:03:10 -0700 Subject: [PATCH] Fixes multiple issues with searching. * dbref now respect candidate lists. Previously a dbref match would ignore candidates which permitted you to drop any object from anywhere by specifying a dbref. * If candidates is [], we now return right away. Without this, a candidate list of [] would not filter out anything because short circuiting like: cand_restriction = candidates and Q(pk__in=candidates_id) or Q() will use Q() (what we really want is nothing to match). This would permit you to drop any object you can refer by nick or name if your inventory was empty. * Minor fix of 'ret_index' for typo'ed 'reg_index'. --- src/objects/manager.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/objects/manager.py b/src/objects/manager.py index 9303c9a06d..eb8257a365 100644 --- a/src/objects/manager.py +++ b/src/objects/manager.py @@ -206,7 +206,7 @@ class ObjectManager(TypedObjectManager): # fuzzy matching - first check with keys, then with aliases key_candidates = self.filter(Q(db_key__istartswith=ostring) | Q(alias__db_key__istartswith=ostring)).distinct() key_strings = key_candidates.values_list("db_key", flat=True) - matches = string_partial_matching(key_candidates, ostring, reg_index=False) + matches = string_partial_matching(key_candidates, ostring, ret_index=False) if matches: return matches alias_candidates = self.model.alias_set.related.model.objects.filter(db_obj__pk__in=candidates_id).values_list("db_key", flat=True) @@ -267,16 +267,23 @@ class ObjectManager(TypedObjectManager): if not ostring and ostring != 0: return [] + # Convenience check to make sure candidates are really dbobjs + if candidates: + candidates = [cand.dbobj for cand in make_iter(candidates) if hasattr(cand, "dbobj")] + + # If there are no candidates, don't go any further. + if candidates == []: + return [] + dbref = not attribute_name and self.dbref(ostring) if dbref or dbref == 0: # Easiest case - dbref matching (always exact) dbref_match = self.dbref_search(dbref) if dbref_match: - return [dbref_match] - - # Convenience check to make sure candidates are really dbobjs - if candidates: - candidates = [cand.dbobj for cand in make_iter(candidates) if hasattr(cand, "dbobj")] + if candidates == None or dbref_match.dbobj in candidates: + return [dbref_match] + else: + return [] # Search through all possibilities.