Пример #1
0
class DeviceTaskSchema(Schema):
    model = DeviceTask

    id = fields.Integer()

    task = fields.Raw(required=True)
    created_at = ArrowField()

    device_uuid = fields.UUID(
        required=True,
        validate=[lambda dev_id: Device.query.get(dev_id) is not None])
Пример #2
0
class DeviceSchema(Schema):
    model = Device

    uuid = fields.UUID(required=True)

    name = fields.String(required=True,
                         validate=[
                             validate.Length(min=4, max=32),
                             validate.Regexp(r'(^|,)[\w]+(,|$)', 0)
                         ])

    registered_at = ArrowField()
Пример #3
0
class ScriptSchema(Schema):
    model = Script

    id = fields.Integer()

    name = fields.String(required=True,
                         validate=[
                             validate.Length(min=4, max=64),
                             validate.Regexp(r'(^|,)[\w]+(,|$)', 0)
                         ])

    tag = fields.String(required=True,
                        validate=[
                            validate.Length(min=4, max=64),
                            validate.Regexp(r'(^|,)[\w]+(,|$)', 0)
                        ])

    @staticmethod
    def validate_code(code):
        try:
            ast.parse(code)
        except SyntaxError:
            raise ValidationError('Not a valid Python code.')

    code = fields.Raw(required=True,
                      validate=[
                          validate.Length(min=0, max=2048),
                          lambda code: ScriptSchema.validate_code(code)
                      ])

    calls = fields.Integer()

    runtime = fields.Integer()

    created_at = ArrowField()

    updated_at = ArrowField()

    owner_id = fields.Nested('UserSchema', many=False)
Пример #4
0
class DeviceLogSchema(Schema):

    model = DeviceLog

    id = fields.Integer()

    log = fields.Raw(required=True)

    tag = fields.String(required=True)

    created_at = ArrowField()

    # FIXME: remove
    device_id = fields.UUID(required=False)
Пример #5
0
class DeviceTaskSchema(Schema):
    model = DeviceTask

    id = fields.Integer()

    task = fields.Raw(
        required=True
    )
    created_at = ArrowField()

    # FIXME: remove
    device_id = fields.UUID(
        required=False
    )
Пример #6
0
class DeviceSchema(Schema):
    model = Device

    uuid = fields.UUID(missing=None)

    name = fields.String(required=True,
                         validate=[
                             validate.Length(min=4, max=32),
                             validate.Regexp(r'(^|,)[\w]+(,|$)', 0)
                         ])

    registered_at = ArrowField()

    owner_id = fields.Nested('UserSchema', many=False)
Пример #7
0
class UserSchema(Schema):

    model = User

    id = fields.Integer()

    username = fields.String(
        required=True,
        validate=[
            validate.Length(min=8, max=32),
            validate.Regexp(r'(^|,)[\w]+(,|$)', 0)
        ]
    )

    email = fields.Email(
        required=True,
        validate=[
            validate.Length(min=8, max=64)
        ]
    )

    password = fields.String(
        required=True,
        validate=[
            validate.Length(min=8, max=32),
            validate.Regexp(r'[\w]+')
        ]
    )

    created_at = ArrowField()

    devices = fields.Nested(
        DeviceSchema,
        many=True
    )

    scripts = fields.Nested(
        ScriptSchema,
        many=True
    )
Пример #8
0
class CalendarEventSchema(Schema):
    name = fields.Str()
    start_datetime = ArrowField(required=False)