evennia.typeclasses.managers

This implements the common managers that are used by the abstract models in dbobjects.py (and which are thus shared by all Attributes and TypedObjects).

class evennia.typeclasses.managers.TypedObjectManager(*args, **kwargs)[source]

Bases: SharedMemoryManager

Common ObjectManager for all dbobjects.

get_attribute(key=None, category=None, value=None, strvalue=None, obj=None, attrtype=None, **kwargs)[source]

Return Attribute objects by key, by category, by value, by strvalue, by object (it is stored on) or with a combination of those criteria.

Parameters:
  • key (str, optional) – The attribute’s key to search for

  • category (str, optional) – The category of the attribute(s) to search for.

  • value (str, optional) – The attribute value to search for. Note that this is not a very efficient operation since it will query for a pickled entity. Mutually exclusive to strvalue.

  • strvalue (str, optional) – The str-value to search for. Most Attributes will not have strvalue set. This is mutually exclusive to the value keyword and will take precedence if given.

  • obj (Object, optional) – On which object the Attribute to search for is.

  • attrype (str, optional) – An attribute-type to search for. By default this is either None (normal Attributes) or “nick”.

  • **kwargs (any) – Currently unused. Reserved for future use.

Returns:

list – The matching Attributes.

get_nick(key=None, category=None, value=None, strvalue=None, obj=None)[source]

Get a nick, in parallel to get_attribute.

Parameters:
  • key (str, optional) – The nicks’s key to search for

  • category (str, optional) – The category of the nicks(s) to search for.

  • value (str, optional) – The attribute value to search for. Note that this is not a very efficient operation since it will query for a pickled entity. Mutually exclusive to strvalue.

  • strvalue (str, optional) – The str-value to search for. Most Attributes will not have strvalue set. This is mutually exclusive to the value keyword and will take precedence if given.

  • obj (Object, optional) – On which object the Attribute to search for is.

Returns:

nicks (list) – The matching Nicks.

get_by_attribute(key=None, category=None, value=None, strvalue=None, attrtype=None, **kwargs)[source]

Return objects having attributes with the given key, category, value, strvalue or combination of those criteria.

Parameters:
  • key (str, optional) – The attribute’s key to search for

  • category (str, optional) – The category of the attribute to search for.

  • value (str, optional) – The attribute value to search for. Note that this is not a very efficient operation since it will query for a pickled entity. Mutually exclusive to strvalue.

  • strvalue (str, optional) – The str-value to search for. Most Attributes will not have strvalue set. This is mutually exclusive to the value keyword and will take precedence if given.

  • attrype (str, optional) – An attribute-type to search for. By default this is either None (normal Attributes) or “nick”.

  • kwargs (any) – Currently unused. Reserved for future use.

Returns:

obj (list) – Objects having the matching Attributes.

get_by_nick(key=None, nick=None, category='inputline')[source]

Get object based on its key or nick.

Parameters:
  • key (str, optional) – The attribute’s key to search for

  • nick (str, optional) – The nickname to search for

  • category (str, optional) – The category of the nick to search for.

Returns:

obj (list) – Objects having the matching Nicks.

get_tag(key=None, category=None, obj=None, tagtype=None, global_search=False)[source]

Return Tag objects by key, by category, by object (it is stored on) or with a combination of those criteria.

Parameters:
  • key (str, optional) – The Tag’s key to search for

  • category (str, optional) – The Tag of the attribute(s) to search for.

  • obj (Object, optional) – On which object the Tag to search for is.

  • tagtype (str, optional) – One of None (normal tags), “alias” or “permission”

  • global_search (bool, optional) – Include all possible tags, not just tags on this object

Returns:

tag (list) – The matching Tags.

get_permission(key=None, category=None, obj=None)[source]

Get a permission from the database.

Parameters:
  • key (str, optional) – The permission’s identifier.

  • category (str, optional) – The permission’s category.

  • obj (object, optional) – The object on which this Tag is set.

Returns:

permission (list) – Permission objects.

get_alias(key=None, category=None, obj=None)[source]

Get an alias from the database.

Parameters:
  • key (str, optional) – The permission’s identifier.

  • category (str, optional) – The permission’s category.

  • obj (object, optional) – The object on which this Tag is set.

Returns:

alias (list) – Alias objects.

get_by_tag(key=None, category=None, tagtype=None, **kwargs)[source]

Return objects having tags with a given key or category or combination of the two. Also accepts multiple tags/category/tagtype

Parameters:
  • key (str or list, optional) – Tag key or list of keys. Not case sensitive.

  • category (str or list, optional) – Tag category. Not case sensitive. If key is a list, a single category can either apply to all keys in that list or this must be a list matching the key list element by element. If no key is given, all objects with tags of this category are returned.

  • tagtype (str, optional) – ‘type’ of Tag, by default this is either None (a normal Tag), alias or permission. This always apply to all queried tags.

Keyword Arguments:

match (str) – “all” (default) or “any”; determines whether the target object must be tagged with ALL of the provided tags/categories or ANY single one. ANY will perform a weighted sort, so objects with more tag matches will outrank those with fewer tag matches.

Returns:

objects (list) – Objects with matching tag.

Raises:

IndexError – If key and category are both lists and category is shorter than key.

get_by_permission(key=None, category=None)[source]

Return objects having permissions with a given key or category or combination of the two.

Parameters:
  • key (str, optional) – Permissions key. Not case sensitive.

  • category (str, optional) – Permission category. Not case sensitive.

Returns:

objects (list) – Objects with matching permission.

get_by_alias(key=None, category=None)[source]

Return objects having aliases with a given key or category or combination of the two.

Parameters:
  • key (str, optional) – Alias key. Not case sensitive.

  • category (str, optional) – Alias category. Not case sensitive.

Returns:

objects (list) – Objects with matching alias.

create_tag(key=None, category=None, data=None, tagtype=None)[source]

Create a new Tag of the base type associated with this object. This makes sure to create case-insensitive tags. If the exact same tag configuration (key+category+tagtype+dbmodel) exists on the model, a new tag will not be created, but an old one returned.

Parameters:
  • key (str, optional) – Tag key. Not case sensitive.

  • category (str, optional) – Tag category. Not case sensitive.

  • data (str, optional) – Extra information about the tag.

  • tagtype (str or None, optional) – ‘type’ of Tag, by default this is either None (a normal Tag), alias or permission.

Notes

The data field is not part of the uniqueness of the tag: Setting data on an existing tag will overwrite the old data field. It is intended only as a way to carry information about the tag (like a help text), not to carry any information about the tagged objects themselves.

dbref(dbref, reqhash=True)[source]

Determing if input is a valid dbref.

Parameters:
  • dbref (str or int) – A possible dbref.

  • reqhash (bool, optional) – If the “#” is required for this to be considered a valid hash.

Returns:

dbref (int or None) – The integer part of the dbref.

Notes

Valid forms of dbref (database reference number) are either a string ‘#N’ or an integer N.

get_id(dbref)[source]

Find object with given dbref.

Parameters:

dbref (str or int) – The id to search for.

Returns:

object (TypedObject) – The matched object.

Alias to get_id.

Parameters:

dbref (str or int) – The id to search for.

Returns:

Queryset – Queryset with 0 or 1 match.

search_dbref(dbref)

Alias to get_id.

Parameters:

dbref (str or int) – The id to search for.

Returns:

Queryset – Queryset with 0 or 1 match.

get_dbref_range(min_dbref=None, max_dbref=None)[source]

Get objects within a certain range of dbrefs.

Parameters:
  • min_dbref (int) – Start of dbref range.

  • max_dbref (int) – End of dbref range (inclusive)

Returns:

objects (list)

TypedObjects with dbrefs within

the given dbref ranges.

get_typeclass_totals(*args, **kwargs) object[source]

Returns a queryset of typeclass composition statistics.

Returns:

qs (Queryset)

A queryset of dicts containing the typeclass (name),

the count of objects with that typeclass and a float representing the percentage of objects associated with the typeclass.

object_totals()[source]

Get info about database statistics.

Returns:

census (dict)

A dictionary {typeclass_path: number, …} with

all the typeclasses active in-game as well as the number of such objects defined (i.e. the number of database object having that typeclass set on themselves).

Searches through all objects returning those which are of the specified typeclass.

Parameters:
  • typeclass (str or class) – A typeclass class or a python path to a typeclass.

  • include_children (bool, optional) – Return objects with given typeclass and all children inheriting from this typeclass. Mutually exclusive to include_parents.

  • include_parents (bool, optional) – Return objects with given typeclass and all parents to this typeclass. Mutually exclusive to include_children.

Returns:

objects (list) – The objects found with the given typeclasses.

Raises:

ImportError – If the provided typeclass is not a valid typeclass or the path to an existing typeclass.

class evennia.typeclasses.managers.Attribute(*args, **kwargs)[source]

Bases: IAttribute, SharedMemoryModel

This attribute is stored via Django. Most Attributes will be using this class.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

accountdb_set

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

**Pizza.toppings** and **Topping.pizzas** are **ManyToManyDescriptor** instances.

Most of the implementation is delegated to a dynamically defined manager class built by **create_forward_many_to_many_manager()** defined below.

property attrtype

A wrapper for getting database field db_attrtype.

property category

A wrapper for getting database field db_category.

channeldb_set

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

**Pizza.toppings** and **Topping.pizzas** are **ManyToManyDescriptor** instances.

Most of the implementation is delegated to a dynamically defined manager class built by **create_forward_many_to_many_manager()** defined below.

property date_created

A wrapper for getting database field db_date_created.

db_attrtype

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

db_category

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

db_date_created

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

db_key

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

db_lock_storage

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

db_model

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

db_strvalue

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

db_value

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_next_by_db_date_created(*, field=<django.db.models.fields.DateTimeField: db_date_created>, is_next=True, **kwargs)
get_previous_by_db_date_created(*, field=<django.db.models.fields.DateTimeField: db_date_created>, is_next=False, **kwargs)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

property key

A wrapper for getting database field db_key.

property lock_storage
property model

A wrapper for getting database field db_model.

objectdb_set

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

**Pizza.toppings** and **Topping.pizzas** are **ManyToManyDescriptor** instances.

Most of the implementation is delegated to a dynamically defined manager class built by **create_forward_many_to_many_manager()** defined below.

path = 'evennia.typeclasses.attributes.Attribute'
scriptdb_set

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

**Pizza.toppings** and **Topping.pizzas** are **ManyToManyDescriptor** instances.

Most of the implementation is delegated to a dynamically defined manager class built by **create_forward_many_to_many_manager()** defined below.

property strvalue

A wrapper for getting database field db_strvalue.

typename = 'SharedMemoryModelBase'
property value

Getter. Allows for value = self.value. We cannot cache here since it makes certain cases (such as storing a dbobj which is then deleted elsewhere) out-of-sync. The overhead of unpickling seems hard to avoid.

class evennia.typeclasses.managers.Cast(*args, **kwargs)[source]

Bases: Func

Coerce an expression to a new field type.

__init__(expression, output_field)[source]
as_mysql(compiler, connection, **extra_context)[source]
as_oracle(compiler, connection, **extra_context)[source]
as_postgresql(compiler, connection, **extra_context)[source]
as_sql(compiler, connection, **extra_context)[source]

Responsible for returning a (sql, [params]) tuple to be included in the current query.

Different backends can provide their own implementation, by providing an as_{vendor} method and patching the Expression:

def override_as_sql(self, compiler, connection):

# custom logic return super().as_sql(compiler, connection)

setattr(Expression, ‘as_’ + connection.vendor, override_as_sql)

Parameters:
  • compiler (*) – the query compiler responsible for generating the query. Must have a compile method, returning a (sql, [params]) tuple. Calling compiler(value) will return a quoted value.

  • connection (*) – the database connection used for the current query.

Return: (sql, params)

Where sql is a string containing ordered sql parameters to be replaced with the elements of the list params.

as_sqlite(compiler, connection, **extra_context)[source]
function = 'CAST'
template = '%(function)s(%(expressions)s AS %(db_type)s)'
class evennia.typeclasses.managers.Count(*args, **kwargs)[source]

Bases: Aggregate

__init__(expression, filter=None, **extra)[source]
allow_distinct = True
allows_composite_expressions = True
arity = 1
empty_result_set_value = 0
function = 'COUNT'
name = 'Count'
output_field = <django.db.models.fields.IntegerField>
resolve_expression(*args, **kwargs)[source]

Provide the chance to do any preprocessing or validation before being added to the query.

Parameters:
  • query (*) – the backend query implementation

  • allow_joins (*) – boolean allowing or denying use of joins in this query

  • reuse (*) – a set of reusable joins for multijoins

  • summarize (*) – a terminal aggregate clause

  • for_save (*) – whether this expression about to be used in a save or update

Return: an Expression to be added to the query.

class evennia.typeclasses.managers.ExpressionWrapper(*args, **kwargs)[source]

Bases: SQLiteNumericMixin, Expression

An expression that can wrap another expression so that it can provide extra context to the inner expression, such as the output_field.

__init__(expression, output_field)[source]
property allowed_default

Returns True when the argument is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.

as_sql(compiler, connection)[source]

Responsible for returning a (sql, [params]) tuple to be included in the current query.

Different backends can provide their own implementation, by providing an as_{vendor} method and patching the Expression:

def override_as_sql(self, compiler, connection):

# custom logic return super().as_sql(compiler, connection)

setattr(Expression, ‘as_’ + connection.vendor, override_as_sql)

Parameters:
  • compiler (*) – the query compiler responsible for generating the query. Must have a compile method, returning a (sql, [params]) tuple. Calling compiler(value) will return a quoted value.

  • connection (*) – the database connection used for the current query.

Return: (sql, params)

Where sql is a string containing ordered sql parameters to be replaced with the elements of the list params.

deconstruct()

Return a 3-tuple of class import path, positional arguments, and keyword arguments.

get_group_by_cols()[source]
get_source_expressions()[source]
set_source_expressions(exprs)[source]
class evennia.typeclasses.managers.F(*args, **kwargs)[source]

Bases: Combinable

An object capable of resolving references to existing query objects.

__init__(name)[source]
Parameters:

name (*) – the name of the field this expression references

allowed_default = False
asc(**kwargs)[source]
copy()[source]
deconstruct()

Return a 3-tuple of class import path, positional arguments, and keyword arguments.

desc(**kwargs)[source]
replace_expressions(replacements)[source]
resolve_expression(query=None, allow_joins=True, reuse=None, summarize=False, for_save=False)[source]
class evennia.typeclasses.managers.FloatField(verbose_name=None, name=None, primary_key=False, max_length=None, unique=False, blank=False, null=False, db_index=False, rel=None, default=<class 'django.db.models.fields.NOT_PROVIDED'>, editable=True, serialize=True, unique_for_date=None, unique_for_month=None, unique_for_year=None, choices=None, help_text='', db_column=None, db_tablespace=None, auto_created=False, validators=(), error_messages=None, db_comment=None, db_default=<class 'django.db.models.fields.NOT_PROVIDED'>)[source]

Bases: Field

default_error_messages = {'invalid': '“%(value)s” value must be a float.'}
description = 'Floating point number'
empty_strings_allowed = False
formfield(**kwargs)[source]

Return a django.forms.Field instance for this field.

get_internal_type()[source]
get_prep_value(value)[source]

Perform preliminary non-db specific value checks and conversions.

to_python(value)[source]

Convert the input value into the expected Python data type, raising django.core.exceptions.ValidationError if the data can’t be converted. Return the converted value. Subclasses should override this.

class evennia.typeclasses.managers.Q(*args, _connector=None, _negated=False, **kwargs)[source]

Bases: Node

Encapsulate filters as objects that can then be combined logically (using & and |).

AND = 'AND'
OR = 'OR'
XOR = 'XOR'
__init__(*args, _connector=None, _negated=False, **kwargs)[source]

Construct a new Node. If no connector is given, use the default.

check(against, using='default')[source]

Do a database query to check if the expressions of the Q instance matches against the expressions.

conditional = True
deconstruct()[source]
default = 'AND'
flatten()[source]

Recursively yield this Q object and all subexpressions, in depth-first order.

identity
referenced_base_fields

Retrieve all base fields referenced directly or through F expressions excluding any fields referenced through joins.

replace_expressions(replacements)[source]
resolve_expression(query=None, allow_joins=True, reuse=None, summarize=False, for_save=False)[source]
class evennia.typeclasses.managers.Tag(*args, **kwargs)[source]

Bases: Model

Tags are quick markers for objects in-game. An typeobject can have any number of tags, stored via its db_tags property. Tagging similar objects will make it easier to quickly locate the group later (such as when implementing zones). The main advantage of tagging as opposed to using tags is speed; a tag is very limited in what data it can hold, and the tag key+category is indexed for efficient lookup in the database. Tags are shared between objects - a new tag is only created if the key+category combination did not previously exist, making them unsuitable for storing object-related data (for this a regular Attribute should be used).

The ‘db_data’ field is intended as a documentation field for the tag itself, such as to document what this tag+category stands for and display that in a web interface or similar.

The main default use for Tags is to implement Aliases for objects. this uses the ‘aliases’ tag category, which is also checked by the default search functions of Evennia to allow quick searches by alias.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

accountdb_set

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

**Pizza.toppings** and **Topping.pizzas** are **ManyToManyDescriptor** instances.

Most of the implementation is delegated to a dynamically defined manager class built by **create_forward_many_to_many_manager()** defined below.

channeldb_set

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

**Pizza.toppings** and **Topping.pizzas** are **ManyToManyDescriptor** instances.

Most of the implementation is delegated to a dynamically defined manager class built by **create_forward_many_to_many_manager()** defined below.

db_category

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

db_data

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

db_key

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

db_model

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

db_tagtype

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

helpentry_set

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

**Pizza.toppings** and **Topping.pizzas** are **ManyToManyDescriptor** instances.

Most of the implementation is delegated to a dynamically defined manager class built by **create_forward_many_to_many_manager()** defined below.

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

msg_set

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

**Pizza.toppings** and **Topping.pizzas** are **ManyToManyDescriptor** instances.

Most of the implementation is delegated to a dynamically defined manager class built by **create_forward_many_to_many_manager()** defined below.

objectdb_set

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

**Pizza.toppings** and **Topping.pizzas** are **ManyToManyDescriptor** instances.

Most of the implementation is delegated to a dynamically defined manager class built by **create_forward_many_to_many_manager()** defined below.

objects = <django.db.models.manager.Manager object>
scriptdb_set

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

**Pizza.toppings** and **Topping.pizzas** are **ManyToManyDescriptor** instances.

Most of the implementation is delegated to a dynamically defined manager class built by **create_forward_many_to_many_manager()** defined below.

class evennia.typeclasses.managers.TypeclassManager(*args, **kwargs)[source]

Bases: TypedObjectManager

Manager for the typeclasses. The main purpose of this manager is to limit database queries to the given typeclass despite all typeclasses technically being defined in the same core database model.

Search by supplying a string with optional extra search criteria to aid the query.

Parameters:
  • query (All three can be combined in the same) – A search criteria that accepts extra search criteria on the following

  • forms – [key|alias|#dbref…] [tag==<tagstr>[:category]…] [attr==<key>:<value>:category…]

  • query

  • spaces. (separated by)

Returns:

matches (queryset)

A queryset result matching all queries exactly. If wanting to use

spaces or ==, != in tags or attributes, enclose them in quotes.

Example

house = smart_search(“key=foo alias=bar tag=house:building tag=magic attr=color:red”)

Note

The flexibility of this method is limited by the input line format. Tag/attribute matching only works for matching primitives. For even more complex queries, such as ‘in’ operations or object field matching, use the full django query language.

get(*args, **kwargs)[source]

Overload the standard get. This will limit itself to only return the current typeclass.

Parameters:

args (any) – These are passed on as arguments to the default django get method.

Keyword Arguments:

kwargs (any) – These are passed on as normal arguments to the default django get method

Returns:

object (object) – The object found.

Raises:

ObjectNotFound – The exact name of this exception depends on the model base used.

filter(*args, **kwargs)[source]

Overload of the standard filter function. This filter will limit itself to only the current typeclass.

Parameters:

args (any) – These are passed on as arguments to the default django filter method.

Keyword Arguments:

kwargs (any) – These are passed on as normal arguments to the default django filter method.

Returns:

objects (queryset) – The objects found.

all()[source]

Overload method to return all matches, filtering for typeclass.

Returns:

objects (queryset) – The objects found.

first()[source]

Overload method to return first match, filtering for typeclass.

Returns:

object (object) – The object found.

Raises:

ObjectNotFound – The exact name of this exception depends on the model base used.

last()[source]

Overload method to return last match, filtering for typeclass.

Returns:

object (object) – The object found.

Raises:

ObjectNotFound – The exact name of this exception depends on the model base used.

count()[source]

Overload method to return number of matches, filtering for typeclass.

Returns:

integer – Number of objects found.

annotate(*args, **kwargs)[source]

Overload annotate method to filter on typeclass before annotating. :param *args: Positional arguments passed along to queryset annotate method. :type *args: any :param **kwargs: Keyword arguments passed along to queryset annotate method. :type **kwargs: any

Returns:

Annotated queryset.

values(*args, **kwargs)[source]

Overload values method to filter on typeclass first. :param *args: Positional arguments passed along to values method. :type *args: any :param **kwargs: Keyword arguments passed along to values method. :type **kwargs: any

Returns:

Queryset of values dictionaries, just filtered by typeclass first.

values_list(*args, **kwargs)[source]

Overload values method to filter on typeclass first. :param *args: Positional arguments passed along to values_list method. :type *args: any :param **kwargs: Keyword arguments passed along to values_list method. :type **kwargs: any

Returns:

Queryset of value_list tuples, just filtered by typeclass first.

get_family(*args, **kwargs)[source]

Variation of get that not only returns the current typeclass but also all subclasses of that typeclass.

Keyword Arguments:

kwargs (any) – These are passed on as normal arguments to the default django get method.

Returns:

objects (list) – The objects found.

Raises:

ObjectNotFound – The exact name of this exception depends on the model base used.

filter_family(*args, **kwargs)[source]

Variation of filter that allows results both from typeclass and from subclasses of typeclass

Parameters:

args (any) – These are passed on as arguments to the default django filter method.

Keyword Arguments:

kwargs (any) – These are passed on as normal arguments to the default django filter method.

Returns:

objects (list) – The objects found.

all_family()[source]

Return all matches, allowing matches from all subclasses of the typeclass.

Returns:

objects (list) – The objects found.

evennia.typeclasses.managers.class_from_module(path, defaultpaths=None, fallback=None)[source]

Return a class from a module, given the class’ full python path. This is primarily used to convert db_typeclass_path:s to classes.

Parameters:
  • path (str) – Full Python dot-path to module.

  • defaultpaths (iterable, optional) – If a direct import from path fails, try subsequent imports by prepending those paths to path.

  • fallback (str) – If all other attempts fail, use this path as a fallback. This is intended as a last-resort. In the example of Evennia loading, this would be a path to a default parent class in the evennia repo itself.

Returns:

class (Class) – An uninstantiated class recovered from path.

Raises:

ImportError – If all loading failed.

evennia.typeclasses.managers.make_iter(obj)[source]

Makes sure that the object is always iterable.

Parameters:

obj (any) – Object to make iterable.

Returns:

iterable (list or iterable)

The same object

passed-through or made iterable.

evennia.typeclasses.managers.variable_from_module(module, variable=None, default=None)[source]

Retrieve a variable or list of variables from a module. The variable(s) must be defined globally in the module. If no variable is given (or a list entry is None), all global variables are extracted from the module.

Parameters:
  • module (string or module) – Python path, absolute path or a module.

  • variable (string or iterable, optional) – Single variable name or iterable of variable names to extract. If not given, all variables in the module will be returned.

  • default (string, optional) – Default value to use if a variable fails to be extracted. Ignored if variable is not given.

Returns:

variables (value or list) – A single value or a list of values depending on if variable is given or not. Errors in lists are replaced by the default argument.