mirror of
https://github.com/evennia/evennia.git
synced 2026-04-01 05:27:17 +02:00
Merged. Still need to update some migrations.
This commit is contained in:
commit
c676c9965f
29 changed files with 821 additions and 401 deletions
|
|
@ -34,7 +34,6 @@ class ObjectManager(TypedObjectManager):
|
|||
get_dbref_range
|
||||
object_totals
|
||||
typeclass_search
|
||||
get_object_with_user
|
||||
get_object_with_player
|
||||
get_objs_with_key_and_typeclass
|
||||
get_objs_with_attr
|
||||
|
|
@ -52,29 +51,8 @@ class ObjectManager(TypedObjectManager):
|
|||
# ObjectManager Get methods
|
||||
#
|
||||
|
||||
# user/player related
|
||||
# player related
|
||||
|
||||
@returns_typeclass
|
||||
def get_object_with_user(self, user):
|
||||
"""
|
||||
Matches objects with obj.player.user matching the argument.
|
||||
A player<->user is a one-to-relationship, so this always
|
||||
returns just one result or None.
|
||||
|
||||
user - may be a user object or user id.
|
||||
"""
|
||||
dbref = self.dbref(user)
|
||||
if dbref:
|
||||
try:
|
||||
return self.get(db_player__user__id=dbref)
|
||||
except self.model.DoesNotExist:
|
||||
pass
|
||||
try:
|
||||
return self.get(db_player__user=user)
|
||||
except self.model.DoesNotExist:
|
||||
return None
|
||||
|
||||
# This returns typeclass since get_object_with_user and get_dbref does.
|
||||
@returns_typeclass
|
||||
def get_object_with_player(self, ostring, exact=True, candidates=None):
|
||||
"""
|
||||
|
|
@ -92,9 +70,9 @@ class ObjectManager(TypedObjectManager):
|
|||
# not a dbref. Search by name.
|
||||
cand_restriction = candidates and Q(pk__in=[_GA(obj, "id") for obj in make_iter(candidates) if obj]) or Q()
|
||||
if exact:
|
||||
return self.filter(cand_restriction & Q(db_player__user__username__iexact=ostring))
|
||||
return self.filter(cand_restriction & Q(db_player__username__iexact=ostring))
|
||||
else: # fuzzy matching
|
||||
ply_cands = self.filter(cand_restriction & Q(playerdb__user__username__istartswith=ostring)).values_list("db_key", flat=True)
|
||||
ply_cands = self.filter(cand_restriction & Q(playerdb__username__istartswith=ostring)).values_list("db_key", flat=True)
|
||||
if candidates:
|
||||
index_matches = string_partial_matching(ply_cands, ostring, ret_index=True)
|
||||
return [obj for ind, obj in enumerate(make_iter(candidates)) if ind in index_matches]
|
||||
|
|
@ -175,7 +153,8 @@ class ObjectManager(TypedObjectManager):
|
|||
if isinstance(property_value, basestring):
|
||||
property_value = to_unicode(property_value)
|
||||
if isinstance(property_name, basestring):
|
||||
property_name = "db_%s" % property_name.lstrip('db_')
|
||||
if not property_name.startswith('db_'):
|
||||
property_name = "db_%s" % property_name
|
||||
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()
|
||||
|
|
@ -183,6 +162,10 @@ class ObjectManager(TypedObjectManager):
|
|||
return list(self.filter(cand_restriction & type_restriction & Q(**querykwargs)))
|
||||
except exceptions.FieldError:
|
||||
return []
|
||||
except ValueError:
|
||||
from src.utils import logger
|
||||
logger.log_errmsg("The property '%s' does not support search criteria of the type %s." % (property_name, type(property_value)))
|
||||
return []
|
||||
|
||||
@returns_typeclass_list
|
||||
def get_contents(self, location, excludeobj=None):
|
||||
|
|
@ -253,7 +236,8 @@ class ObjectManager(TypedObjectManager):
|
|||
By default (if not attribute_name is set), this will search object.key and object.aliases in order. Can also
|
||||
be on the form #dbref, which will, if exact=True be matched against primary key.
|
||||
attribute_name: (str): Use this named ObjectAttribute to match searchdata against, instead
|
||||
of the defaults.
|
||||
of the defaults. If this is the name of a database field (with or without the db_ prefix), that
|
||||
will be matched too.
|
||||
typeclass (str or TypeClass): restrict matches to objects having this typeclass. This will help
|
||||
speed up global searches.
|
||||
candidates (list obj ObjectDBs): If supplied, search will only be performed among the candidates
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue