diff options
Diffstat (limited to 'inventory/schema.py')
-rw-r--r-- | inventory/schema.py | 40 |
1 files changed, 0 insertions, 40 deletions
diff --git a/inventory/schema.py b/inventory/schema.py deleted file mode 100644 index 0728aea..0000000 --- a/inventory/schema.py +++ /dev/null @@ -1,40 +0,0 @@ -import bson -from flask import url_for -from marshmallow import Schema, fields - -# Map ObjectId to String -Schema.TYPE_MAPPING[bson.ObjectId] = fields.String - - -class ObjectId(fields.Field): - def _serialize(self, value, attr, obj, **kwargs): - if value is None: - return value - return str(value) - - def _deserialize(self, value, attr, data, **kwargs): - if value is None: - return value - return bson.ObjectId(value) - - -class FieldSchema(Schema): - name = fields.String(required=True) - value = fields.String(required=True) - # type - - -class NodeSchema(Schema): - _id = ObjectId(dump_only=True, data_key='id') - name = fields.String(required=True) - parent_id = ObjectId(default=None, allow_none=True) - _fields = fields.List(fields.Nested(FieldSchema()), default=[], attribute='fields', data_key='fields') - - # These are not set by the caller, but by the API endpoint - created_at = fields.AwareDateTime(dump_only=True) - updated_at = fields.AwareDateTime(dump_only=True) - - # Not actual stored fields - parent = fields.Nested(lambda: NodeSchema(), dump_only=True) - children = fields.List(fields.Nested(lambda: NodeSchema()), dump_only=True) - url = fields.Function(lambda obj: url_for('.node', node_id=obj['_id']), dump_only=True) |