Cleaned up and fixed problems in searching by attribute-value. Resolves Issue 267.
This commit is contained in:
parent
3c87b66624
commit
4944a589cc
1 changed files with 6 additions and 8 deletions
|
|
@ -131,7 +131,7 @@ class ObjectManager(TypedObjectManager):
|
||||||
cand_restriction = candidates and Q(db_obj__pk__in=[_GA(obj, "id") for obj in make_iter(candidates) if obj]) or Q()
|
cand_restriction = candidates and Q(db_obj__pk__in=[_GA(obj, "id") for obj in make_iter(candidates) if obj]) or Q()
|
||||||
if type(attribute_value) in (basestring, int, float):
|
if type(attribute_value) in (basestring, int, float):
|
||||||
# simple attribute_value - do direct lookup
|
# simple attribute_value - do direct lookup
|
||||||
return self.model.objattribute_set.related.model.objects.select_related("db_obj").filter(cand_restriction & Q(db_key=attribute_name) & Q(db_value=_DUMPS(("simple", attribute_value))))
|
return self.filter(cand_restriction & Q(objattribute__db_key=attribute_name, objattribute__db_value=_DUMPS(("simple", attribute_value))))
|
||||||
else:
|
else:
|
||||||
# go via attribute conversion
|
# go via attribute conversion
|
||||||
attrs= self.model.objattribute_set.related.model.objects.select_related("db_obj").filter(cand_restriction & Q(db_key=attribute_name))
|
attrs= self.model.objattribute_set.related.model.objects.select_related("db_obj").filter(cand_restriction & Q(db_key=attribute_name))
|
||||||
|
|
@ -251,8 +251,9 @@ class ObjectManager(TypedObjectManager):
|
||||||
if attribute_name:
|
if attribute_name:
|
||||||
# attribute/property search (always exact).
|
# attribute/property search (always exact).
|
||||||
matches = self.get_objs_with_db_property_value(attribute_name, ostring, candidates=candidates)
|
matches = self.get_objs_with_db_property_value(attribute_name, ostring, candidates=candidates)
|
||||||
if not matches:
|
if matches:
|
||||||
return self.get_objs_with_attr_value(attribute_name, ostring, candidates=candidates)
|
return matches
|
||||||
|
return self.get_objs_with_attr_value(attribute_name, ostring, candidates=candidates)
|
||||||
if ostring.startswith("*"):
|
if ostring.startswith("*"):
|
||||||
# Player search - try to find obj by its player's name
|
# Player search - try to find obj by its player's name
|
||||||
player_match = self.get_object_with_player(ostring, candidates=candidates)
|
player_match = self.get_object_with_player(ostring, candidates=candidates)
|
||||||
|
|
@ -262,15 +263,12 @@ class ObjectManager(TypedObjectManager):
|
||||||
# normal key/alias search
|
# normal key/alias search
|
||||||
return self.get_objs_with_key_or_alias(ostring, exact=exact, candidates=candidates)
|
return self.get_objs_with_key_or_alias(ostring, exact=exact, candidates=candidates)
|
||||||
|
|
||||||
|
|
||||||
ostring = to_unicode(ostring, force_string=True)
|
|
||||||
|
|
||||||
if not ostring and ostring != 0:
|
if not ostring and ostring != 0:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
# Easiest case - dbref matching (always exact)
|
dbref = not attribute_name and self.dbref(ostring)
|
||||||
dbref = self.dbref(ostring)
|
|
||||||
if dbref:
|
if dbref:
|
||||||
|
# Easiest case - dbref matching (always exact)
|
||||||
dbref_match = self.dbref_search(dbref)
|
dbref_match = self.dbref_search(dbref)
|
||||||
if dbref_match:
|
if dbref_match:
|
||||||
return [dbref_match]
|
return [dbref_match]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue