Exemplo n.º 1
0
class UserRoles(db.Model):
    """
        UserRoles 数据模型
    """
    # 表名
    __tablename__ = "user_roles"
    # 主键
    id = db.Column(db.Integer,
                   primary_key=True,
                   autoincrement=True,
                   nullable=False)
    # 用户ID
    user_id = db.Column(db.Integer, db.ForeignKey("users.id"), nullable=False)
    # 角色编码
    role_code = db.Column(db.String(32),
                          db.ForeignKey("roles.role_code"),
                          nullable=False)
    # 修改时间
    last_date = db.Column(db.DateTime, nullable=False)

    def __repr__(self):
        return "{} ({})".format(
            self.__class__.__name__,
            ", ".join("{}:{}".format(key, getattr(self, key))
                      for key in self.__dict__.keys()))
Exemplo n.º 2
0
class Menu(db.Model):
    """
        Menu 数据模型
    """
    # 表名
    __tablename__ = "menus"
    # 主键
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, nullable=False)
    # 上级菜单编码
    parent_code = db.Column(db.String(32))
    # 菜单编码
    menu_code = db.Column(db.String(32), unique=True, nullable=False)
    # 菜单名称
    menu_name = db.Column(db.String(64), index=True, nullable=False)
    # 菜单URL
    menu_url = db.Column(db.String(255))
    # 描述
    describe = db.Column(db.String(255))
    # 扩展信息
    ext = db.Column(db.String(255))
    # 修改时间
    last_date = db.Column(db.DateTime, nullable=False)
    # 版本号
    version = db.Column(db.Integer, nullable=False, default=1)

    menu_roles = db.relationship("Role", secondary="role_menus", backref="menus", lazy="dynamic")
    menu_users = db.relationship("User", secondary="user_menus", backref="menus", lazy="dynamic")

    def __repr__(self):
        return "{} ({})".format(self.__class__.__name__,
                                ", ".join("{}:{}".format(key, getattr(self, key)) for key in self.__dict__.keys()))
Exemplo n.º 3
0
class TaskListModel(db.Model):
    """ Definição de modelo de task list """

    __tablename__ = 'tasklist'

    uuid = db.Column(db.String(), primary_key=True, default=generate_uuid)
    name = db.Column(db.String(100), nullable=False)
    create_on = db.Column(db.DateTime, default=datetime.utcnow)
    isActive = db.Column(db.Boolean, default=True)
    task = db.relationship('TaskModel', lazy=True)

    def __init__(self, name):
        self.name = name
Exemplo n.º 4
0
class TagModel(db.Model):
    """ Definição de modelo de tag """

    __tablename__ = 'tag'

    uuid = db.Column(db.String(), primary_key=True, default=generate_uuid)
    name = db.Column(db.String(100), nullable=False)
    count = db.Column(db.Integer, nullable=False, default=0)
    create_on = db.Column(db.DateTime, default=datetime.utcnow)
    isActive = db.Column(db.Boolean, default=True)

    def __init__(self, name, count=None):
        self.name = name
        self.count = count
Exemplo n.º 5
0
class MsgTemplate(db.Model):
    __tablename__ = "messages"
    id = db.Column(db.Integer,
                   primary_key=True,
                   autoincrement=True,
                   nullable=False)
    content = db.Column(db.String(255), nullable=False)
    version = db.Column(db.Integer, default=1)
    ext = db.Column(db.String(255), nullable=True)

    def __repr__(self):
        return "{} ({})".format(
            self.__class__.__name__,
            ", ".join("{}:{}".format(key, getattr(self, key))
                      for key in self.__dict__.keys()))
Exemplo n.º 6
0
class Resource(db.Model):
    """
        Resource 数据模型
    """
    # 表名
    __tablename__ = "resources"
    # 主键
    id = db.Column(db.Integer,
                   primary_key=True,
                   autoincrement=True,
                   nullable=False)
    # 上级资源编码
    parent_code = db.Column(db.String(32))
    # 资源编码
    resource_code = db.Column(db.String(32), unique=True, nullable=False)
    # 资源级别 0, 1, 2, 3
    resource_level = db.Column(db.Integer, nullable=False, default=0)
    # 资源名称
    resource_name = db.Column(db.String(64), index=True, nullable=False)
    # 资源URL
    resource_url = db.Column(db.String(255))
    # 描述
    describe = db.Column(db.String(255))
    # 扩展信息
    ext = db.Column(db.String(255))
    # 修改时间
    last_date = db.Column(db.DateTime, nullable=False)
    # 版本号
    version = db.Column(db.Integer, nullable=False, default=1)

    resource_roles = db.relationship("Role",
                                     secondary="role_resources",
                                     backref="resources",
                                     lazy="dynamic")
    resource_users = db.relationship("User",
                                     secondary="user_resources",
                                     backref="resources",
                                     lazy="dynamic")

    def __repr__(self):
        return "{} ({})".format(
            self.__class__.__name__,
            ", ".join("{}:{}".format(key, getattr(self, key))
                      for key in self.__dict__.keys()))
Exemplo n.º 7
0
class TaskModel(db.Model):
    """ Definição de modelo de task """

    __tablename__ = 'task'

    uuid = db.Column(db.String(), primary_key=True, default=generate_uuid)
    title = db.Column(db.String(200), unique=True, nullable=False)
    notes = db.Column(db.String(), nullable=False)
    priority = db.Column(db.Enum('high', 'medium', 'low', name='priority'),
                         nullable=False)
    remindMeOn = db.Column(db.DateTime)
    activityType = db.Column(db.Enum('indoors',
                                     'outdoors',
                                     name='activityType'),
                             nullable=False)
    status = db.Column(db.Enum('open', 'done', name='status'), nullable=False)
    taskList = db.Column(db.String(),
                         db.ForeignKey('tasklist.uuid'),
                         nullable=False)
    tags = db.relationship("TagModel",
                           secondary=tagship,
                           backref=db.backref('tasks', lazy='dynamic'))
    create_on = db.Column(db.DateTime, default=datetime.utcnow)
    isActive = db.Column(db.Boolean, default=True)

    def __init__(self,
                 title,
                 notes,
                 priority,
                 remindMeOn,
                 activityType,
                 status,
                 taskList,
                 tags=None):
        self.title = title
        self.notes = notes
        self.priority = priority
        self.remindMeOn = remindMeOn
        self.activityType = activityType
        self.status = status
        self.taskList = taskList
        self.tags = tags
Exemplo n.º 8
0
class Role(db.Model):
    """
        Role 数据模型
    """
    # 表名
    __tablename__ = "roles"
    # 主键
    id = db.Column(db.Integer,
                   primary_key=True,
                   autoincrement=True,
                   nullable=False)
    # 角色编码
    role_code = db.Column(db.String(32), unique=True, nullable=False)
    # 角色名称
    role_name = db.Column(db.String(64), index=True, nullable=False)
    # 描述
    describe = db.Column(db.String(255))
    # 扩展信息
    ext = db.Column(db.String(255))
    # 修改时间
    last_date = db.Column(db.DateTime, nullable=False)
    # 版本号
    version = db.Column(db.Integer, nullable=False, default=1)

    role_menus = db.relationship("Menu",
                                 secondary="role_menus",
                                 backref="roles",
                                 lazy="dynamic",
                                 order_by=lambda: Menu.menu_code)
    role_resources = db.relationship("Resource",
                                     secondary="role_resources",
                                     backref="roles",
                                     lazy="dynamic")
    role_users = db.relationship("User",
                                 secondary="user_roles",
                                 backref="roles",
                                 lazy="dynamic")

    def __repr__(self):
        return "{} ({})".format(
            self.__class__.__name__,
            ", ".join("{}:{}".format(key, getattr(self, key))
                      for key in self.__dict__.keys()))
Exemplo n.º 9
0
class UserModel(db.Model):
    """ Definição de modelo de usuário """

    __tablename__ = 'user'

    uuid = db.Column(db.String(), primary_key=True, default=generate_uuid)
    avatar = db.Column(db.String(), nullable=False)
    username = db.Column(db.String(20), unique=True, nullable=False)
    password = db.Column(db.String(), nullable=False)
    name = db.Column(db.String(100), nullable=False)
    email = db.Column(db.String(100), unique=True, nullable=False)
    address = db.Column(db.String(100), nullable=False)
    city = db.Column(db.String(100), nullable=False)
    country = db.Column(db.String(100), nullable=False)
    create_on = db.Column(db.DateTime(timezone=True), default=datetime.now)
    isActive = db.Column(db.Boolean, default=True)

    def __init__(self,
                 username,
                 password,
                 name,
                 email,
                 address,
                 city,
                 country,
                 avatar=None):
        self.username = username
        self.password = password
        self.name = name
        self.email = email
        self.address = address
        self.city = city
        self.country = country
        self.avatar = generate_avatar(self.email)
Exemplo n.º 10
0
class User(db.Model):
    """
        User 数据模型

        primary_key 如果设为True这列就是表的主键\n
        unique      如果设为True这列不允许出现重复的值\n
        index       如果设为True为这列创建索引,提升查询效率\n
        nullable    如果设为True这列允许使用空值;如果设为False这列不允许使用空值\n
        default     为这列定义默认值
    """
    # 表名
    __tablename__ = 'users'
    # 主键
    id = db.Column(db.Integer,
                   primary_key=True,
                   autoincrement=True,
                   nullable=False)
    # 昵称
    nickname = db.Column(db.String(64),
                         index=True,
                         unique=True,
                         nullable=False)
    # 密码
    password = db.Column(db.String(64), nullable=False)
    # 邮箱
    email = db.Column(db.String(64), index=True, nullable=False)
    # 性别: 0. 未知 1. 男 2. 女
    sex = db.Column(db.Integer)
    # QQ
    qq = db.Column(db.String(20))
    # 图标
    icon = db.Column(db.String(255))
    # 是否可用(默认: 1): 0. 不可用 1. 可用
    is_available = db.Column(db.Integer, nullable=False, default=1)
    # 扩展信息
    ext = db.Column(db.String(255))
    # 修改时间
    last_date = db.Column(db.DateTime, nullable=False)
    # 版本号
    version = db.Column(db.Integer, nullable=False, default=1)
    # 用户权限
    #
    # 第一个参数为对应参照的类"UserResources";
    # 第二个参数secondary为多对多关系;
    # 第三个参数backref为类UserResources申明新属性的方法;
    # 第四个参数lazy决定了什么时候SQLALchemy从数据库中加载数据。
    user_menus = db.relationship("Menu",
                                 secondary="user_menus",
                                 backref="users",
                                 lazy="dynamic",
                                 order_by=lambda: Menu.menu_code)
    user_resources = db.relationship("Resource",
                                     secondary="user_resources",
                                     backref="users",
                                     lazy="dynamic")
    user_roles = db.relationship("Role",
                                 secondary="user_roles",
                                 backref="users",
                                 lazy="dynamic")

    def is_authenticated(self):
        """
            is_authenticated 方法是一个误导性的名字的方法,通常这个方法应该返回True,除非对象代表一个由于某种原因没有被认证的用户。

            :return:
        """
        return True

    def is_active(self):
        """
            is_active 方法应该为用户返回True除非用户不是激活的,例如,他们已经被禁了。

            :return:
        """
        return True

    def is_anonymous(self):
        """
            is_anonymous 方法应该为那些不被获准登录的用户返回True。

            :return:
        """
        return False

    def get_id(self):
        """
            get_id 方法为用户返回唯一的unicode标识符。我们用数据库层生成唯一的id。

            :return:
        """
        try:
            return unicode(self.id)  # python 2
        except NameError:
            return str(self.id)  # python 3

    def __repr__(self):
        return "{} ({})".format(
            self.__class__.__name__,
            ", ".join("{}:{}".format(key, getattr(self, key))
                      for key in self.__dict__.keys()))
Exemplo n.º 11
0
# -*- coding: utf-8 -*-
from core.app import db
from datetime import datetime
from core.utils.generate_uuid import generate_uuid

tagship = db.Table(
    'tagship',
    db.Column('task_uuid',
              db.String(),
              db.ForeignKey('task.uuid'),
              primary_key=True),
    db.Column('tag_uuid',
              db.String(),
              db.ForeignKey('tag.uuid'),
              primary_key=True))


class TaskModel(db.Model):
    """ Definição de modelo de task """

    __tablename__ = 'task'

    uuid = db.Column(db.String(), primary_key=True, default=generate_uuid)
    title = db.Column(db.String(200), unique=True, nullable=False)
    notes = db.Column(db.String(), nullable=False)
    priority = db.Column(db.Enum('high', 'medium', 'low', name='priority'),
                         nullable=False)
    remindMeOn = db.Column(db.DateTime)
    activityType = db.Column(db.Enum('indoors',
                                     'outdoors',
                                     name='activityType'),