From efdb9544917ec0d83379a447d328f681e7c30dea Mon Sep 17 00:00:00 2001 From: Griatch Date: Tue, 21 May 2013 14:29:50 +0200 Subject: [PATCH] Fixed a logical error in obj.manager causing it to fail to find arbitrary db_>fieldname>. Resolves Issue 373. --- src/commands/default/player.py | 2 +- src/objects/manager.py | 9 ++++++--- src/objects/models.py | 5 ++++- src/utils/create.py | 4 ++-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/commands/default/player.py b/src/commands/default/player.py index 58e95b2d33..7f16e200e9 100644 --- a/src/commands/default/player.py +++ b/src/commands/default/player.py @@ -109,7 +109,7 @@ class CmdOOCLook(MuxPlayerCommand): # character is already puppeted sess = player.get_session(csessid) sid = sess in sessions and sessions.index(sess) + 1 - if sess: + if sess and sid: string += "\n - {G%s{n [%s] (played by you in session %i)" % (char.key, ", ".join(char.permissions), sid) else: string += "\n - {R%s{n [%s] (played by someone else)" % (char.key, ", ".join(char.permissions)) diff --git a/src/objects/manager.py b/src/objects/manager.py index cc90a1ccc0..4e71f3d887 100644 --- a/src/objects/manager.py +++ b/src/objects/manager.py @@ -153,8 +153,9 @@ class ObjectManager(TypedObjectManager): """ property_name = "db_%s" % property_name.lstrip('db_') cand_restriction = candidates and Q(pk__in=[_GA(obj, "id") for obj in make_iter(candidates) if obj]) or Q() + querykwargs = {property_name:None} try: - return list(self.filter(cand_restriction).exclude(Q(property_name=None))) + return list(self.filter(cand_restriction).exclude(Q(**querykwargs))) except exceptions.FieldError: return [] @@ -169,10 +170,11 @@ class ObjectManager(TypedObjectManager): property_value = to_unicode(property_value) if isinstance(property_name, basestring): property_name = "db_%s" % property_name.lstrip('db_') + querykwargs = {property_name:property_value} cand_restriction = candidates and Q(pk__in=[_GA(obj, "id") for obj in make_iter(candidates) if obj]) or Q() type_restriction = typeclasses and Q(db_typeclass_path__in=make_iter(typeclasses)) or Q() try: - return list(self.filter(cand_restriction & type_restriction & Q(property_name=property_value))) + return list(self.filter(cand_restriction & type_restriction & Q(**querykwargs))) except exceptions.FieldError: return [] @@ -310,7 +312,8 @@ class ObjectManager(TypedObjectManager): # no matches found - check if we are dealing with N-keyword query - if so, strip it. match_number, searchdata = _AT_MULTIMATCH_INPUT(searchdata) # run search again, with the exactness set by call - matches = _searcher(searchdata, candidates, typeclass, exact=exact) + if match_number != None or not exact: + matches = _searcher(searchdata, candidates, typeclass, exact=exact) # deal with result if len(matches) > 1 and match_number != None: diff --git a/src/objects/models.py b/src/objects/models.py index 93b859f37c..a063b256ec 100644 --- a/src/objects/models.py +++ b/src/objects/models.py @@ -575,7 +575,10 @@ class ObjectDB(TypedObject): be a list of typeclasses for a broader search. location (Object): Specify a location to search, if different from the self's given location plus its contents. This can also be a list of locations. - attribute_name (str): Use this named Attribute to match searchdata against, instead of object.key. + attribute_name (str): Define which property to search. If set, no key+alias search will be performed. This can be used to + search database fields (db_ will be automatically appended), and if that fails, it will try to + return objects having Attributes with this name and value equal to searchdata. A special + use is to search for "key" here if you want to do a key-search without including aliases. quiet (bool) - don't display default error messages - return multiple matches as a list and no matches as None. If not set (default), will echo error messages and return None. exact (bool) - if unset (default) - prefers to match to beginning of string rather than not matching diff --git a/src/utils/create.py b/src/utils/create.py index 07400fe040..0eae842304 100644 --- a/src/utils/create.py +++ b/src/utils/create.py @@ -446,7 +446,7 @@ def create_player(name, email, password, if user: conflict_check = User.objects.filter(username__iexact=user.username) - conflict_check = len(conflict_check) > 1 + conflict_check = len(conflict_check) > 1 else: conflict_check = User.objects.filter(username__iexact=name) @@ -525,7 +525,7 @@ def create_player(name, email, password, except Exception: pass try: - del new_character + del new_player except Exception: pass raise