Exemplo n.º 1
0
class Comment(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    comment = db.Column(db.Text(), nullable = False)
    date_time = db.Column(db.DateTime(), nullable = False)
    ip = db.Column(db.String(30), nullable=False)
    email = db.Column(db.String(60), nullable=False)
    def __unicode__(self):
        if self.email:
            return self.email + ' sent ' + self.comment
        else:
            return self.comment
Exemplo n.º 2
0
class HostConnection(db.Model):
    __tablename__ = 'host_connection'
    __table_args__ = {"extend_existing": True}
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(100), nullable=False, comment='连接会话名称')
    type = db.Column(db.String(100), nullable=True, comment='连接方式')
    start_time = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now, comment='执行开始时间')
    end_time = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now, comment='执行结束时间')
    elapsed_time = db.Column(db.BigInteger, nullable=False, default=0, comment='连接时长')
    reason = db.Column(db.String(100), nullable=True, comment='失败原因')
    create_time = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now, comment='数据创建时间')
class LoginLogging(db.Model):
    __tablename__ = 'logging_login'
    __table_args__ = {"extend_existing": True}
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    login_time = db.Column(db.DateTime,
                           nullable=True,
                           default=datetime.datetime.now,
                           comment='登录时间')
    position = db.Column(db.String(100), nullable=True, comment='登录地址')
    ip = db.Column(db.String(100), nullable=True, comment='登录IP')
    client = db.Column(db.String(100), nullable=True, comment='客户端')
    status = db.Column(db.Boolean, nullable=True, comment='登录状态')
    reason = db.Column(db.String(100), nullable=True, comment='失败原因')
Exemplo n.º 4
0
class Message(db.Model):
    """
    系统消息实体类
    """
    __tablename__ = 'message'
    __table_args__ = {"extend_existing": True}
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(100), nullable=False)
    code = db.Column(db.Integer, nullable=False)
    message = db.Column(db.Text, nullable=False)
    context = db.Column(db.Text, nullable=False)
    operation = db.Column(db.String(100), nullable=False)
    type = db.Column(db.String(100), nullable=False)
    parent = db.Column(db.String(100), nullable=False)
Exemplo n.º 5
0
class Course(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    subject = db.Column(db.Integer(), db.ForeignKey('subject.id'))
    number = db.Column(db.String(60), nullable=False)
    school = db.Column(db.Integer(), db.ForeignKey('school.id'))
    def __unicode__(self):
        return unicode(self.subject) + " " + self.number
Exemplo n.º 6
0
class TopicTree(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    subject = db.Column(db.Integer(), db.ForeignKey('subject.id'))
    #represents the json tree representation {'parent_topic' : {'child_topic' : {'grandchild_topic' : None, 'grandchild_topic2' : None}}}
    tree_representation = db.Column(db.String(1000), nullable=False)
    def __unicode__(self):
        return self.tree_representation
class CommandExecute(db.Model):
    __tablename__ = 'command_execute'
    __table_args__ = {"extend_existing": True}
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    command = db.Column(db.Text, nullable=True, comment='执行命令')
    final_state = db.Column(db.Boolean,
                            nullable=True,
                            default=False,
                            comment='最终执行状态')
    start_time = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.datetime.now,
                           comment='执行开始时间')
    end_time = db.Column(db.DateTime,
                         nullable=False,
                         default=datetime.datetime.now,
                         comment='执行结束时间')
    elapsed_time = db.Column(db.BigInteger,
                             nullable=False,
                             default=0,
                             comment='执行耗时')
    reason = db.Column(db.String(100), nullable=True, comment='失败原因')
    create_time = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.datetime.now,
                            comment='创建时间')
Exemplo n.º 8
0
class User(UserMixin, db.Model):
    """
    用户模型
    """
    __tablename__ = 'user'
    __table_args__ = {"extend_existing": True}
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(100), nullable=False, unique=False)
    email = db.Column(db.String(40), unique=True, nullable=False)
    password = db.Column(db.String(200),
                         primary_key=False,
                         unique=False,
                         nullable=False)
    website = db.Column(db.String(200),
                        primary_key=False,
                        unique=False,
                        nullable=True)
    description = db.Column(db.Text, nullable=True)
    position = db.Column(db.Text, nullable=True)
    avatar = db.Column(db.String(200),
                       primary_key=False,
                       unique=False,
                       nullable=True)
    create_time = db.Column(db.DateTime,
                            index=False,
                            unique=False,
                            nullable=True,
                            default=datetime.datetime.now)
    last_login_time = db.Column(db.DateTime,
                                index=False,
                                unique=False,
                                nullable=True)
    hosts = db.relationship('Host',
                            secondary='user_host_relation',
                            backref=db.backref('hosts', lazy='dynamic'),
                            lazy='dynamic',
                            passive_deletes=True)

    def set_password(self, password):
        self.password = generate_password_hash(password, method='sha256')

    def check_password(self, password):
        return check_password_hash(self.password, password)

    def __repr__(self):
        return '<User {}>'.format(self.name)
class MonitorCpu(db.Model):
    __tablename__ = 'monitor_cpu'
    __table_args__ = {"extend_existing": True}
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    cpu_time_1 = db.Column(db.BigInteger, nullable=False, comment='总CPU时间1')
    cpu_time_2 = db.Column(db.BigInteger, nullable=False, comment='总CPU时间2')
    idle = db.Column(db.String(20), nullable=False, comment='计算空闲时间')
    rate = db.Column(DOUBLE(10, 4), nullable=False, comment='利用率')
    create_time = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.datetime.now)
Exemplo n.º 10
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer(), primary_key=True)
    email = db.Column(db.String(120), index=True, unique=True, nullable=False)
    firstname = db.Column(db.String(30), index=True, nullable=False)
    lastname = db.Column(db.String(30), index=True, nullable=False)
    password = db.Column(db.String(255), nullable=False)
    active = db.Column(db.Boolean())
    website = db.Column(db.String(120))
    confirmed_at = db.Column(db.DateTime())
    roles = db.relationship('Role',
                            secondary=roles_users,
                            backref=db.backref('user', lazy='dynamic'))
    grades = db.relationship('Grade', lazy='dynamic', backref='user')
    programs = db.relationship('Program', lazy='dynamic', backref='user')
    code_revisions = db.relationship('CodeRevision',
                                     lazy='dynamic',
                                     backref='user')
    submissions = db.relationship('Submission', lazy='dynamic', backref='user')

    def is_admin(self):
        return self.has_role("admin")

    def add_grade(self, assignment, score):
        grade = Grade(score=score)
        self.grades.append(grade)
        assignment.grades.append(grade)
        db.session.add(grade)
        db.session.commit()

    def get_grade(self, assignment):
        grades = self.grades.filter_by(assignment_id=assignment.id).all()
        if len(grades) == 0:
            grade = self.grades.filter_by(assignment_id=assignment.id).all()[0]
            return grade
        else:
            return None
Exemplo n.º 11
0
class MonitorMemory(db.Model):
    __tablename__ = 'monitor_memory'
    __table_args__ = {"extend_existing": True}
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    total = db.Column(db.Integer, nullable=False, comment='总内存')
    free = db.Column(db.Integer, nullable=False, comment='空闲内存')
    buffers = db.Column(db.Integer, nullable=False, comment='缓冲大小')
    cached = db.Column(db.Integer, nullable=False, comment='缓冲存储器')
    swap_cached = db.Column(db.Integer, nullable=False, comment='交换空间缓冲存储器')
    swap_total = db.Column(db.Integer, nullable=False, comment='交换空间总大小')
    swap_free = db.Column(db.Integer, nullable=False, comment='交换空间空闲总大小')
    swap_rate = db.Column(db.String(100), nullable=False, comment='交换空间利用率')
    rate = db.Column(DOUBLE(10, 4), nullable=False, comment='内存利用率')
    create_time = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.datetime.now)
Exemplo n.º 12
0
class MonitorNetworkIO(db.Model):

    __tablename__ = 'monitor_network_io'
    __table_args__ = {"extend_existing": True}
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(100), nullable=False, comment='网卡名称')
    receive = db.Column(DOUBLE(10, 4), nullable=False, comment='接受速度(单位KB/s)')
    transmit = db.Column(DOUBLE(10, 4), nullable=False, comment='发送速度(单位KB/s)')
    create_time = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.datetime.now)

    def as_dict(obj):
        # return {c.name: getattr(self, c.name) for c in self.__table__.columns}
        # 上面的有缺陷,表字段和属性不一致会有问题
        return dict((col.name, getattr(obj, col.name))
                    for col in class_mapper(obj.__class__).mapped_table.c)
Exemplo n.º 13
0
class Host(db.Model):
    """
    主机实体类
    """
    __tablename__ = 'host'
    __table_args__ = {"extend_existing": True}
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    hostname = db.Column(db.String(100), nullable=False)
    ssh_port = db.Column(db.Integer, nullable=False)
    username = db.Column(db.String(100), nullable=False)
    password = db.Column(db.String(100), nullable=True)
    key = db.Column(db.Text, nullable=True)
    server_name = db.Column(db.String(100), nullable=False)
    server_type = db.Column(db.String(100), nullable=False)
    server = db.Column(db.String(100), nullable=False)
    command = db.Column(db.String(255), nullable=True)
    command_start = db.Column(db.String(255), nullable=True)
    command_stop = db.Column(db.String(255), nullable=True)
    command_restart = db.Column(db.String(255), nullable=True)
    message = db.Column(db.String(255), nullable=True)
    active = db.Column(db.Boolean, nullable=False, default=True)
    create_time = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.datetime.now)
    users = db.relationship('User',
                            secondary='user_host_relation',
                            backref=db.backref('users', lazy='dynamic'),
                            lazy='dynamic',
                            passive_deletes=True)
Exemplo n.º 14
0
class Subject(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String(200), nullable=False)
    def __unicode__(self):
        return self.name
Exemplo n.º 15
0
class Role(db.Model, RoleMixin):
    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String(80), unique=True)
    description = db.Column(db.String(255))
Exemplo n.º 16
0
class School(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String(100), index=True, nullable=False)
Exemplo n.º 17
0
class Topic(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    topic_name = db.Column(db.String(200), nullable=False)
    title = db.Column(db.String(200), nullable=False)
    def __unicode__(self):
        return self.topic_name