class UserSchema(Schema): id = fields.Integer(dump_only=True) email = fields.String(required=True) password = fields.String(required=True) enabled = fields.Boolean(dump_only=True) updated_at = fields.DateTime(dump_only=True) created_at = fields.DateTime(dump_only=True) @post_dump def make_object(self, data): return User(**data)
class CompanySchema(Schema): id = fields.Integer(dump_only=True) name = fields.String(required=True) country_code = fields.String(required=True) website = fields.String(allow_none=True) enabled = fields.Boolean(required=True) updated_at = fields.DateTime(dump_only=True) created_at = fields.DateTime(dump_only=True) @post_load def make_object(self, data): return Company(**data)
class UserSchema(Schema): username = fields.String(required=True, validate=validate.Length(5, 30)) first_name = fields.String(required=True, validate=validate.Length(1, 50)) last_name = fields.String(required=True, validate=validate.Length(1, 50)) email = fields.Email(required=True) enabled = fields.Boolean(required=True) created_at = fields.DateTime(dump_only=True) @post_load def make_object(self, data): return User(**data)
class ImageSchema(Schema): id = fields.Integer(dump_only=True) height = fields.Integer(required=True) width = fields.Integer(required=True) time = fields.Integer(required=True) timestamp = fields.DateTime(dump_only=True) pic_num = fields.Integer(required=True) filename = fields.String(dump_only=True) image_path = fields.String(required=True, load_only=True) @pre_dump def _pre_dump(self, obj): obj.timestamp = obj.time
class TesterSchema(Schema): id = fields.Integer(dump_only=True) test_id = fields.Integer(required=True) time = fields.DateTime(required=True) phone_manufacturer = fields.String(required=True) phone_model = fields.String(required=True) phone_screen_height = fields.String(required=True) phone_screen_width = fields.String(required=True) images_count = fields.Integer(dump_only=True) images = fields.Nested(ImageSchema, many=True, dump_only=True) @post_load def _make_object(self, data): return Tester(**data)
class ContactSchema(Schema): """ serialization-deserialization-validation class for Contacts. """ id = fields.UUID(dump_only=True) first_name = fields.String(50, required=True) surname = fields.String(50, required=True) username = fields.String(required=True, validator=validate_username, error_messages={'validator_failed': {'message': 'Username must be 6-52 characters length and' ' can only contain: a-zA-Z0-9.'}}) inserted = fields.DateTime(dump_only=True) emails = fields.Nested(EmailSchema, exlude=('contact_id',), many=True) @post_load def _post_load(self, data): if self.partial: return data return Contact(**data)
class VideoSchema(Schema): id = fields.Integer(dump_only=True) tester_id = fields.Integer(dump_only=True) duration = fields.Integer(dump_only=True) time = fields.DateTime(dump_only=True) filename = fields.String(dump_only=True)