evennia.objects.manager¶
Custom manager for Objects.
-
class
evennia.objects.manager.
ObjectManager
(*args, **kwargs)[source]¶ Bases:
evennia.objects.manager.ObjectDBManager
,evennia.typeclasses.managers.TypeclassManager
-
class
evennia.objects.manager.
ObjectDBManager
(*args, **kwargs)[source]¶ Bases:
evennia.typeclasses.managers.TypedObjectManager
This ObjectManager implements methods for searching and manipulating Objects directly from the database.
Evennia-specific search methods (will return Typeclasses or lists of Typeclasses, whereas Django-general methods will return Querysets or database objects).
dbref (converter) get_id (alias: dbref_search) get_dbref_range object_totals typeclass_search get_object_with_account get_objs_with_key_and_typeclass get_objs_with_attr get_objs_with_attr_match get_objs_with_db_property get_objs_with_db_property_match get_objs_with_key_or_alias get_contents object_search (interface to many of the above methods,
equivalent to evennia.search_object)
copy_object
-
get_object_with_account
(ostring, exact=True, candidates=None)[source]¶ Search for an object based on its account’s name or dbref.
- Parameters
ostring (str or int) – Search criterion or dbref. Searching for an account is sometimes initiated by appending an * to the beginning of the search criterion (e.g. in local_and_global_search). This is stripped here.
exact (bool, optional) – Require an exact account match.
candidates (list, optional) – Only search among this list of possible object candidates.
- Returns
match (query) – Matching query.
-
get_objs_with_key_and_typeclass
(oname, otypeclass_path, candidates=None)[source]¶ Returns objects based on simultaneous key and typeclass match.
- Parameters
oname (str) – Object key to search for
otypeclass_path (str) – Full Python path to tyepclass to search for
candidates (list, optional) – Only match among the given list of candidates.
- Returns
matches (query) – The matching objects.
-
get_objs_with_attr
(attribute_name, candidates=None)[source]¶ Get objects based on having a certain Attribute defined.
- Parameters
attribute_name (str) – Attribute name to search for.
candidates (list, optional) – Only match among the given list of object candidates.
- Returns
matches (query) – All objects having the given attribute_name defined at all.
-
get_objs_with_attr_value
(attribute_name, attribute_value, candidates=None, typeclasses=None)[source]¶ Get all objects having the given attrname set to the given value.
- Parameters
attribute_name (str) – Attribute key to search for.
attribute_value (any) – Attribute value to search for. This can also be database objects.
candidates (list, optional) – Candidate objects to limit search to.
typeclasses (list, optional) – Python pats to restrict matches with.
- Returns
matches (query) – Objects fullfilling both the attribute_name and attribute_value criterions.
Notes
This uses the Attribute’s PickledField to transparently search the database by matching the internal representation. This is reasonably effective but since Attribute values cannot be indexed, searching by Attribute key is to be preferred whenever possible.
-
get_objs_with_db_property
(property_name, candidates=None)[source]¶ Get all objects having a given db field property.
- Parameters
property_name (str) – The name of the field to match for.
candidates (list, optional) – Only search among th egiven candidates.
- Returns
matches (list) – The found matches.
-
get_objs_with_db_property_value
(property_name, property_value, candidates=None, typeclasses=None)[source]¶ Get objects with a specific field name and value.
- Parameters
property_name (str) – Field name to search for.
property_value (any) – Value required for field with property_name to have.
candidates (list, optional) – List of objects to limit search to.
typeclasses (list, optional) – List of typeclass-path strings to restrict matches with
-
get_contents
(location, excludeobj=None)[source]¶ Get all objects that has a location set to this one.
- Parameters
location (Object) – Where to get contents from.
excludeobj (Object or list, optional) – One or more objects to exclude from the match.
- Returns
contents (query) – Matching contents, without excludeobj, if given.
-
get_objs_with_key_or_alias
(ostring, exact=True, candidates=None, typeclasses=None)[source]¶ - Parameters
ostring (str) – A search criterion.
exact (bool, optional) – Require exact match of ostring (still case-insensitive). If False, will do fuzzy matching using evennia.utils.utils.string_partial_matching algorithm.
candidates (list) – Only match among these candidates.
typeclasses (list) – Only match objects with typeclasses having thess path strings.
- Returns
matches (query) – A list of matches of length 0, 1 or more.
-
search_object
(searchdata, attribute_name=None, typeclass=None, candidates=None, exact=True, use_dbref=True)[source]¶ Search as an object globally or in a list of candidates and return results. The result is always an Object. Always returns a list.
- Parameters
searchdata (str or Object) – The entity to match for. This is usually a key string but may also be an object itself. By default (if no 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 Attribute to match searchdata against, instead 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) – If supplied, search will only be performed among the candidates in this list. A common list of candidates is the contents of the current location searched.
exact (bool) – Match names/aliases exactly or partially. Partial matching matches the beginning of words in the names/aliases, using a matching routine to separate multiple matches in names with multiple components (so “bi sw” will match “Big sword”). Since this is more expensive than exact matching, it is recommended to be used together with the candidates keyword to limit the number of possibilities. This value has no meaning if searching for attributes/properties.
use_dbref (bool) – If False, bypass direct lookup of a string on the form #dbref and treat it like any string.
- Returns
matches (list) – Matching objects
-
object_search
(searchdata, attribute_name=None, typeclass=None, candidates=None, exact=True, use_dbref=True)¶ Search as an object globally or in a list of candidates and return results. The result is always an Object. Always returns a list.
- Parameters
searchdata (str or Object) – The entity to match for. This is usually a key string but may also be an object itself. By default (if no 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 Attribute to match searchdata against, instead 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) – If supplied, search will only be performed among the candidates in this list. A common list of candidates is the contents of the current location searched.
exact (bool) – Match names/aliases exactly or partially. Partial matching matches the beginning of words in the names/aliases, using a matching routine to separate multiple matches in names with multiple components (so “bi sw” will match “Big sword”). Since this is more expensive than exact matching, it is recommended to be used together with the candidates keyword to limit the number of possibilities. This value has no meaning if searching for attributes/properties.
use_dbref (bool) – If False, bypass direct lookup of a string on the form #dbref and treat it like any string.
- Returns
matches (list) – Matching objects
-
search
(searchdata, attribute_name=None, typeclass=None, candidates=None, exact=True, use_dbref=True)¶ Search as an object globally or in a list of candidates and return results. The result is always an Object. Always returns a list.
- Parameters
searchdata (str or Object) – The entity to match for. This is usually a key string but may also be an object itself. By default (if no 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 Attribute to match searchdata against, instead 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) – If supplied, search will only be performed among the candidates in this list. A common list of candidates is the contents of the current location searched.
exact (bool) – Match names/aliases exactly or partially. Partial matching matches the beginning of words in the names/aliases, using a matching routine to separate multiple matches in names with multiple components (so “bi sw” will match “Big sword”). Since this is more expensive than exact matching, it is recommended to be used together with the candidates keyword to limit the number of possibilities. This value has no meaning if searching for attributes/properties.
use_dbref (bool) – If False, bypass direct lookup of a string on the form #dbref and treat it like any string.
- Returns
matches (list) – Matching objects
-
copy_object
(original_object, new_key=None, new_location=None, new_home=None, new_permissions=None, new_locks=None, new_aliases=None, new_destination=None)[source]¶ Create and return a new object as a copy of the original object. All will be identical to the original except for the arguments given specifically to this method. Object contents will not be copied.
- Parameters
original_object (Object) – The object to make a copy from.
new_key (str, optional) – Name of the copy, if different from the original.
new_location (Object, optional) – Alternate location.
new_home (Object, optional) – Change the home location
new_aliases (list, optional) – Give alternate object aliases as a list of strings.
new_destination (Object, optional) – Used only by exits.
- Returns
copy (Object or None) –
- The copy of original_object,
optionally modified as per the ingoing keyword arguments. None if an error was encountered.
-