evennia.web.api.serializers

Serializers in the Django Rest Framework are similar to Forms in normal django. They’re used for transmitting and validating data, both going to clients and coming to the server. However, where forms often contained presentation logic, such as specifying widgets to use for selection, serializers typically leave those decisions in the hands of clients, and are more focused on converting data from the server to JSON (serialization) for a response, and validating and converting JSON data sent from clients to our enpoints into python objects, often django model instances, that we can use (deserialization).

class evennia.web.api.serializers.AttributeSerializer(*args, **kwargs)[source]

Bases: rest_framework.serializers.ModelSerializer

class Meta[source]

Bases: object

model

alias of evennia.typeclasses.attributes.Attribute

fields = ['db_key', 'db_category', 'db_attrtype', 'value_display', 'db_value']
static get_value_display(obj: evennia.typeclasses.attributes.Attribute) → str[source]

Gets the string display of an Attribute’s value for serialization :param obj: Attribute being serialized

Returns

The Attribute’s value in string format

class evennia.web.api.serializers.TagSerializer(*args, **kwargs)[source]

Bases: rest_framework.serializers.ModelSerializer

class Meta[source]

Bases: object

model

alias of evennia.typeclasses.tags.Tag

fields = ['db_key', 'db_category', 'db_data', 'db_tagtype']
class evennia.web.api.serializers.SimpleObjectDBSerializer(*args, **kwargs)[source]

Bases: rest_framework.serializers.ModelSerializer

class Meta[source]

Bases: object

model

alias of evennia.objects.objects.DefaultObject

fields = ['id', 'db_key']
class evennia.web.api.serializers.TypeclassSerializerMixin[source]

Bases: object

Mixin that contains types shared by typeclasses. A note about tags, aliases, and permissions. You might note that the methods and fields are defined here, but they’re included explicitly in each child class. What gives? It’s a DRF error: serializer method fields which are inherited do not resolve correctly in child classes, and as of this current version (3.11) you must have them in the child classes explicitly to avoid field errors. Similarly, the child classes must contain the attribute serializer explicitly to not have them render PK-related fields.

shared_fields = ['id', 'db_key', 'attributes', 'db_typeclass_path', 'aliases', 'tags', 'permissions']
static get_tags(obj)[source]

Serializes tags from the object’s Tagshandler :param obj: Typeclassed object being serialized

Returns

List of TagSerializer data

static get_aliases(obj)[source]

Serializes tags from the object’s Aliashandler :param obj: Typeclassed object being serialized

Returns

List of TagSerializer data

static get_permissions(obj)[source]

Serializes tags from the object’s Permissionshandler :param obj: Typeclassed object being serialized

Returns

List of TagSerializer data

static get_attributes(obj)[source]

Serializes attributes from the object’s AttributeHandler :param obj: Typeclassed object being serialized

Returns

List of AttributeSerializer data

static get_nicks(obj)[source]

Serializes attributes from the object’s NicksHandler :param obj: Typeclassed object being serialized

Returns

List of AttributeSerializer data

class evennia.web.api.serializers.ObjectDBSerializer(*args, **kwargs)[source]

Bases: evennia.web.api.serializers.TypeclassSerializerMixin, rest_framework.serializers.ModelSerializer

class Meta[source]

Bases: object

model

alias of evennia.objects.objects.DefaultObject

fields = ['db_location', 'db_home', 'contents', 'exits', 'nicks', 'id', 'db_key', 'attributes', 'db_typeclass_path', 'aliases', 'tags', 'permissions']
read_only_fields = ['id']
static get_exits(obj)[source]

Gets exits for the object :param obj: Object being serialized

Returns

List of data from SimpleObjectDBSerializer

static get_contents(obj)[source]

Gets non-exits for the object :param obj: Object being serialized

Returns

List of data from SimpleObjectDBSerializer

class evennia.web.api.serializers.AccountSerializer(*args, **kwargs)[source]

Bases: evennia.web.api.serializers.TypeclassSerializerMixin, rest_framework.serializers.ModelSerializer

This uses the DefaultAccount object to have access to the sessions property

static get_session_ids(obj)[source]

Gets a list of session IDs connected to this Account :param obj: Account we’re grabbing sessions from :type obj: DefaultAccount

Returns

List of session IDs

class Meta[source]

Bases: object

model

alias of evennia.accounts.accounts.DefaultAccount

fields = ['username', 'session_ids', 'nicks', 'id', 'db_key', 'attributes', 'db_typeclass_path', 'aliases', 'tags', 'permissions']
read_only_fields = ['id']
class evennia.web.api.serializers.ScriptDBSerializer(*args, **kwargs)[source]

Bases: evennia.web.api.serializers.TypeclassSerializerMixin, rest_framework.serializers.ModelSerializer

class Meta[source]

Bases: object

model

alias of evennia.scripts.models.ScriptDB

fields = ['db_interval', 'db_persistent', 'db_start_delay', 'db_is_active', 'db_repeats', 'id', 'db_key', 'attributes', 'db_typeclass_path', 'aliases', 'tags', 'permissions']
read_only_fields = ['id']