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
Serialize Attribute views.
-
class
Meta
[source]¶ Bases:
object
-
model
¶
-
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
-
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
-
class
evennia.web.api.serializers.
SimpleObjectDBSerializer
(*args, **kwargs)[source]¶ Bases:
rest_framework.serializers.ModelSerializer
-
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.
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
-
class
evennia.web.api.serializers.
TypeclassListSerializerMixin
[source]¶ Bases:
object
Shortened serializer for list views.
-
class
evennia.web.api.serializers.
ObjectDBSerializer
(*args, **kwargs)[source]¶ Bases:
evennia.web.api.serializers.TypeclassSerializerMixin
,rest_framework.serializers.ModelSerializer
Serializing Objects.
-
class
Meta
[source]¶ Bases:
object
-
model
¶
-
fields
= ['db_location', 'db_home', 'contents', 'exits', 'nicks', 'id', 'db_key', 'attributes', 'db_typeclass_path', 'aliases', 'tags', 'permissions']¶
-
read_only_fields
= ['id']¶
-
-
class
-
class
evennia.web.api.serializers.
ObjectListSerializer
(*args, **kwargs)[source]¶ Bases:
evennia.web.api.serializers.TypeclassListSerializerMixin
,rest_framework.serializers.ModelSerializer
Shortened representation for listings.]
-
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
-
class
evennia.web.api.serializers.
AccountListSerializer
(*args, **kwargs)[source]¶ Bases:
evennia.web.api.serializers.TypeclassListSerializerMixin
,rest_framework.serializers.ModelSerializer
A shortened form for listing.
-
class
evennia.web.api.serializers.
ScriptDBSerializer
(*args, **kwargs)[source]¶ Bases:
evennia.web.api.serializers.TypeclassSerializerMixin
,rest_framework.serializers.ModelSerializer
Serializing Account.
-
class
evennia.web.api.serializers.
ScriptListSerializer
(*args, **kwargs)[source]¶ Bases:
evennia.web.api.serializers.TypeclassListSerializerMixin
,rest_framework.serializers.ModelSerializer
Shortened form for listing.
-
class
evennia.web.api.serializers.
HelpSerializer
(*args, **kwargs)[source]¶ Bases:
evennia.web.api.serializers.TypeclassSerializerMixin
,rest_framework.serializers.ModelSerializer
Serializers Help entries (not a typeclass).
-
class
evennia.web.api.serializers.
HelpListSerializer
(*args, **kwargs)[source]¶ Bases:
evennia.web.api.serializers.TypeclassListSerializerMixin
,rest_framework.serializers.ModelSerializer
Shortened form for listings.