monitorImage.py 2.19 KB
Newer Older
1 2
#!/usr/bin/env python
# -*- coding: utf_8 -*-
wanli's avatar
wanli committed
3 4 5 6 7 8

from application.app import db, ma
from .base import PrimaryModel 
from marshmallow import Schema, fields, INCLUDE, EXCLUDE

class MonitorImageModel(PrimaryModel):
9
    __tablename__ = 'evm_monitor_image'
wanli's avatar
wanli committed
10 11

    watch = db.Column(db.Integer, nullable = False)
12 13 14 15
    length = db.Column(db.Integer, nullable = True, default = 0)
    png_uncompressed_size = db.Column(db.Integer, nullable = False, default = 0)
    png_total_count = db.Column(db.Integer, nullable = True, default = 0)
    png_file_size = db.Column(db.Integer, nullable = True, default = 0)
wanli's avatar
wanli committed
16 17 18 19 20 21
    uri = db.Column(db.String(20), index = True, nullable = False, default = '')

    # __table_args__ = (
    #     db.Index('idx_xxx', 'xxx', mysql_using='btree'),
    # )

22
    def __init__(self, watch, length=0, png_uncompressed_size=0, png_total_count=0, png_file_size=0, uri=''):
wanli's avatar
wanli committed
23 24 25 26 27 28 29 30 31 32
        self.watch = watch
        self.length = length
        self.png_uncompressed_size = png_uncompressed_size
        self.png_total_count = png_total_count
        self.png_file_size = png_file_size
        self.uri = uri

    def __repr__(self):
        return '<MonitorImageModel %r>' % (self.watch)

33
    def to_dict(self):
wanli's avatar
wanli committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
        return {
            'watch': self.watch,
            'length': self.length,
            'png_uncompressed_size': self.png_uncompressed_size,
            'png_total_count': self.png_total_count,
            'png_file_size': self.png_file_size,
            'uri': self.uri,
        }


class GetListMonitorImageSchema(ma.SQLAlchemySchema):
    class Meta:
        # unknown = INCLUDE # 未知字段默认包含
        unknown = EXCLUDE # 未知字段默认排除
        model = MonitorImageModel

    page = fields.Integer(required=False)
    pageSize = fields.Integer(required=False)
    watch = ma.auto_field()

getListMonitorImageSchema = GetListMonitorImageSchema()
getListMonitorImagesSchema = GetListMonitorImageSchema(many=True)

class GetMonitorImageSchema(ma.SQLAlchemySchema):
    class Meta:
        # unknown = INCLUDE # 未知字段默认包含
        unknown = EXCLUDE # 未知字段默认排除
        model = MonitorImageModel

    watch = ma.auto_field()

getMonitorImageSchema = GetMonitorImageSchema()