Ejemplo n.º 1
0
class Role(db.Model, RoleMixin):
    __tablename__ = f'{table_prefix}_roles'

    id = db.Column(db.Integer,
                   db.Sequence(f'{table_prefix}_roles_id_seq',
                               start=10000,
                               increment=1),
                   primary_key=True)
    name = db.Column(db.String(80), unique=True)
    description = db.Column(db.String(255))
    parent_id = db.Column(db.Integer, db.ForeignKey(f'{__tablename__}.id'))
    parent = db.relationship("Role", remote_side=[id])
    users = db.relationship(
        'User',
        secondary=f'{table_prefix}_users_roles_rel',
        backref=db.backref(f'{table_prefix}_roles.role_id'),
        lazy='dynamic')

    def __str__(self):
        return self.name

    @staticmethod
    def get_parent_default(role: 'Role', roles_list: List['Role']):
        """Recursive function for obtaining parent roles"""
        parent_roles: Optional[List['Role']] = Role.query.filter(
            Role.id == role.parent_id).all()
        # If deputies run recursion for each deputy
        if parent_roles:
            roles_list.extend(parent_roles)
            for parent_role in parent_roles:
                Role.get_parent_default(parent_role, roles_list)

        return roles_list

    @property
    def get_parents(self) -> Optional[List['Role']]:
        """Get all parent roles for current role"""
        parent_roles: Optional[List['Role']] = self.get_parent_default(
            self, [])
        parent_roles.append(self)

        return parent_roles

    @property
    def get_functions(self) -> List[str]:
        return [f'{function.hash}' for function in self.application_functions]
Ejemplo n.º 2
0
class Category(db.Model):


    __tablename__ = 'category'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(50))
    is_current = db.Column(db.Boolean, default=False)
    expire_time = db.Column(db.DateTime, nullable=False)
Ejemplo n.º 3
0
class Content(db.Model):
    id = db.Column(db.Integer, primary_key = True)
    title = db.Column(db.String(200))
    created_date = db.Column(db.DateTime)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))

    def __repr__(self):
        return '<Content %r>' % (self.title)
Ejemplo n.º 4
0
class Music(db.Model):
    __tablename__ = 'music'
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(255), nullable=False)
    singer = db.Column(db.String(255), nullable=False)
    coverfile = db.Column(db.String(255), default='')
    audiofile = db.Column(db.String(255), default='')
    lrcfile = db.Column(db.String(255), default='')
    privacy = db.Column(db.String(20), default='guest')
    recommed = db.Column(db.Integer, default=0)
    clicknum = db.Column(db.Integer, default=0)
    favornum = db.Column(db.Integer, default=0)
    commtnum = db.Column(db.Integer, default=0)
    uuid = db.Column(db.String(255), unique=True, nullable=False)
    addtime = db.Column(db.DATETIME, index=True, default=datetime.now)
    lang_id = db.Column(db.Integer, db.ForeignKey('music_lang_tag.id'))  # 音乐语种
    style_id = db.Column(db.Integer,
                         db.ForeignKey('music_style_tag.id'))  # 音乐流派
    theme_id = db.Column(db.Integer,
                         db.ForeignKey('music_theme_tag.id'))  # 音乐主题
    emotion_id = db.Column(db.Integer,
                           db.ForeignKey('music_emotion_tag.id'))  # 音乐心情
    scene_id = db.Column(db.Integer,
                         db.ForeignKey('music_scene_tag.id'))  # 音乐场景
    admin_id = db.Column(db.Integer, db.ForeignKey('admin.id'))
    favors = db.relationship('MusicFavor', backref='music')
    comments = db.relationship('MusicComment', backref='music')

    def __repr__(self):
        return '<Music %r>' % self.title
Ejemplo n.º 5
0
class Userdata(db.Model):
    __tablename__ = 'userdata'

    id = db.Column(db.Integer, primary_key=True)
    openid = db.Column(db.String(255))  # openid
    username = db.Column(db.String(255))  # username
    avatar = db.Column(db.String(255))  # avatarUrl
    gender = db.Column(db.String(255))  # gender

    country = db.Column(db.String(255))  # country
    province = db.Column(db.String(255))  # province
    city = db.Column(db.String(255))  # city

    # 定义对象
    def __init__(self,
                 openid=None,
                 username=None,
                 avatar=None,
                 gender=None,
                 country=None,
                 province=None,
                 city=None):
        self.openid = openid
        self.username = username
        self.avatar = avatar
        self.gender = gender
        self.country = country
        self.province = province
        self.city = city
        self.update()  # 提交数据

    # 提交数据函数
    def update(self):
        db.session.add(self)
        db.session.commit()
Ejemplo n.º 6
0
class Member(UserMixin, db.Model):
    __tablename__ = 'cmf_member'
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(50))
    nickname = db.Column(db.String(50))
    nation = db.Column(db.String(50))
    birth_day = db.Column(db.String(50))
    motto = db.Column(db.String(50))
    mobile = db.Column(db.String(12))
    address = db.Column(db.String(50))
    resume = db.Column(db.Text(5000))
    userpass = db.Column(db.String, default="123456")
    add_time = db.Column(db.Integer, default=int(time.time()))

    @property
    def password(self):
        return self.userpass

    # 定义一个赋值的方法
    @password.setter
    def password(self, pwd):
        self.userpass = generate_password_hash(pwd)

    def check_password(self, pwd):

        return check_password_hash(self.userpass, pwd)

    def __init__(self, **kwargs):
        super(Member, self).__init__(**kwargs)

    def __repr__(self):
        return '<Member: %r>' % self.username
Ejemplo n.º 7
0
class AlbumTag(db.Model):
    __tablename__ = 'album_tag'
    id = db.Column(db.Integer,primary_key=True,autoincrement=True)
    name = db.Column(db.String(20),nullable=False,unique=True)

    albums = db.relationship('Album',backref='album_tag')

    def __repr__(self):
        return '<AlbumTag %r>'%self.name
Ejemplo n.º 8
0
class User(UserMixin, db.Model):
    __tablename__ = 'user'

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(12),
                         index=True,
                         unique=True,
                         nullable=False)
    password = db.Column(db.String(128))

    def set_password(self, password):
        self.password = generate_password_hash(password)

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

    def __repr__(self):
        return '<User %r>' % self.username
Ejemplo n.º 9
0
class Tag(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    keyword = db.Column(db.String(50))

    # def __init__(self,name):
    # self.name = name

    def __repr__(self):
        return '<Category %r>' % self.keyword
Ejemplo n.º 10
0
class ArticleTag(db.Model):
    __tablename__ = 'article_tag'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(20), unique=True, nullable=False)
    articles = db.relationship('Article', backref='article_tag')
    addtime = db.Column(db.DATETIME, index=True, default=datetime.now)

    def __repr__(self):
        return '<ArticleTag %r>' % self.name
Ejemplo n.º 11
0
class Album(db.Model):
    __tablename__ = 'album'
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(80), nullable=False)
    desc = db.Column(db.TEXT)
    photonum = db.Column(db.Integer, default=0)
    privacy = db.Column(db.String(20), default='public')
    clicknum = db.Column(db.Integer, default=0)
    favornum = db.Column(db.Integer, default=0)
    uuid = db.Column(db.String(255), unique=True, nullable=False)
    addtime = db.Column(db.DATETIME, index=True, default=datetime.now)
    tag_id = db.Column(db.Integer, db.ForeignKey('album_tag.id'))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    favors = db.relationship('AlbumFavor', backref='album')
    photos = db.relationship('Photo', backref='album')

    def __repr__(self):
        return '<Album %r>' % self.title
Ejemplo n.º 12
0
class User(db.Model):
    __tablename__ = "User"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64), index=True, unique=True)
    passwd = db.Column(db.String(120), index=True, unique=True)
    authenticated = db.Column(db.Boolean, default=False)

    def get_id(self):
        return self.id

    def is_active(self):
        return True

    def is_authenticated(self):
        return self.authenticated

    def is_anonymous(self):
        return False
Ejemplo n.º 13
0
class Message(db.Model):
    """留言表"""
    __tablename__ = 'message'
    id = db.Column(db.Integer, primary_key=True)
    user = db.Column(db.Integer, db.ForeignKey('user.id'))
    activity = db.Column(db.Integer, db.ForeignKey('activity.id'))
    message = db.Column(db.String(200), default='')
    status = db.Column(db.Boolean, default=True)
    create_time = db.Column(db.DateTime, nullable=False)
Ejemplo n.º 14
0
class Tenant(db.Model):
    __tablename__ = 'tenant'

    id = db.Column(db.Integer, primary_key=True)
    nama = db.Column(db.String(35), index=True, unique=True, nullable=False)
    slug = db.Column(db.String(12), index=True, unique=True, nullable=False)
    telegram_alert_id = db.Column(db.Integer)
    telegram_alert_group = db.Column(db.Text)
    telegram_info_id = db.Column(db.Integer)
    telegram_info_group = db.Column(db.Text)
    timezone = db.Column(db.String(50))

    locations = relationship('Location', backref='location_tenant')
    loggers = relationship('Logger', backref='logger_tenant')
    periodiks = relationship('Periodik', backref='periodik_tenant')

    created_at = db.Column(db.DateTime)
    modified_at = db.Column(db.DateTime)
Ejemplo n.º 15
0
class ShippingRegion(db.Model):
    shipping_region_id = db.Column(db.Integer, primary_key=True)
    shipping_region = db.Column(db.String(100))

    def __init__(self, shipping_region):
        self.shipping_region = shipping_region

    def __repr__(self):
        return 'Shipping region is {}'.format(self.shipping_region)
Ejemplo n.º 16
0
class NewsCategory(BaseModel, db.Model):
    """文章分类"""
    __tablename__ = "mogu_news_category"
    id = db.Column(db.Integer, primary_key=True, comment="ID")
    name = db.Column(db.String(64), nullable=True, comment="分类名称")
    news_list = db.relationship('News', backref='category', lazy='dynamic')

    def __repr__(self):
        return "%s" % (self.name)
Ejemplo n.º 17
0
class Users(db.Model):
    __tablename__ = 'user'

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(100),unique=True)
    password = db.Column(db.String(100), nullable=False)
    sex = db.Column(db.Integer)
    age = db.Column(db.SmallInteger)
    phone = db.Column(db.String(11))
    email = db.Column(db.String(100))
    role = db.Column(db.Integer)
    date = db.Column(db.DateTime)

    def is_active(self):
        return True

    def get_id(self):
        return self.id
Ejemplo n.º 18
0
class Attribute(db.Model):
    attribute_id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100))

    def __init__(self, name):
        self.name = name

    def __repr__(self):
        return 'Attribute {}'.format(self.name)
Ejemplo n.º 19
0
class MusicEmotionTag(db.Model):
    __tablename__ = 'music_emotion_tag'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(20), unique=True, nullable=False)
    musics = db.relationship('Music', backref='music_emotion_tag')
    addtime = db.Column(db.DATETIME, index=True, default=datetime.now)

    def __repr__(self):
        return '<MusicEmotionTag %r>' % self.name
Ejemplo n.º 20
0
class Nav(BaseModel, db.Model):
    """导航菜单"""
    __tablename__ = "mogu_nav"
    id = db.Column(db.Integer, primary_key=True, comment="ID")
    name = db.Column(db.String(80), comment="导航名称")
    link = db.Column(db.String(164), nullable=True, comment="导航链接")
    parent_id = db.Column(db.Integer,
                          db.ForeignKey('mogu_nav.id'),
                          comment="父导航ID")
    # 自关联
    parent = db.relationship('Nav',
                             uselist=False,
                             remote_side=[id],
                             backref=db.backref('children',
                                                uselist=True))  # 父导航

    def __repr__(self):
        return "%s" % (self.name)
Ejemplo n.º 21
0
class UserDao(db.Model):
    __tablename__ = 'app_user'

    id = db.Column(db.String(10), primary_key=True)
    name = db.Column(db.String(30), nullable=False)
    password = db.Column(db.String(30), nullable=False)
    salt = db.Column(db.String(20), nullable=False)
    # status状态,0-停用,1-启用
    status = db.Column(db.Integer, nullable=False)
    # 错误登录次数
    errLoginNum = db.Column(db.Integer, nullable=True)
    # 最后一次错误登录时间
    errLoginTime = db.Column(db.DateTime, nullable=True)

    def __init__(self, user_id, user_name, user_password):
        self.id = user_id
        self.name = user_name
        self.salt = Common.genSalt(10)
        self.password = Common.encryptedPsw(user_password, self.salt)
        self.status = 1
        self.errLoginNum = 0

    def __str__(self):
        return "Users(id='%s')" % self.id

    def getAll(self):
        return self.query.all()

    def get_byId(self, id):
        return self.query.filter_by(id=id).first()

    def get_byName(self, name):
        return self.query.filter_by(name=name).all()

    def add(self, user):
        db.session.add(user)
        return session_commit()

    def update(self):
        return session_commit()

    def delete(self, id):
        # deleteRow = self.query.filter_by(id=id).delete()
        return session_commit()
Ejemplo n.º 22
0
class Event(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(255))
    title_cal = db.Column(db.String(255))
    content = db.Column(db.Text())
    host = db.Column(db.String(255))
    category_char = db.Column(db.String(255))
    category_host = db.Column(db.String(255))
    date_created = db.Column(db.DateTime(), default=db.func.now())
    date_start = db.Column(db.DateTime(), default=db.func.now())
    date_end = db.Column(db.DateTime(), default=db.func.now())
    location = db.Column(db.String(255))
    link = db.Column(db.String(255))
    poster = db.Column(db.String(255))
    contact = db.Column(db.String(255))
Ejemplo n.º 23
0
class Comment(db.Model):
    __tablename__ = 'comment'
    query_class = CommentQuery
    id = db.Column(db.Integer, primary_key=True)
    post_id = db.Column(db.Integer, db.ForeignKey('post.id'))
    posts = db.relationship('Post', backref=db.backref('comments', lazy='dynamic'))
    author_name = db.Column(db.String(50))
    author_email = db.Column(db.String(100))
    author_url = db.Column(db.String(1024))
    author_ip = db.Column(db.String(20))
    comment_create_time = db.Column(db.DateTime, default=datetime.utcnow)
    content = db.Column(db.Text)
    isvisible = db.Column(db.Integer, default=0)

    def __init__(self, *args, **kwargs):
        super(Comment, self).__init__(*args, **kwargs)

    def __repr__(self):
        return '<comment %r>' % self.content
Ejemplo n.º 24
0
class Certifications(db.Model):
    """Class for storing information about certifications table

    Attributes:
        __tablename__: a string of table name
        id: an integer of certification's id
        name: a string of certification's name
        issuer: a string of issuer who issued the certification.
        details: a string that explains the certification.
        created_at: a datetime that indicates when the certification created
        updated_at: a datetime that indicates when the certification last updated
        response_field: a dictionary that will be used to be a guide when extracting data from database's field
    """
    __tablename__ = "certifications"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(50), nullable=False)
    issuer = db.Column(db.String(50), nullable=False)
    details = db.Column(db.String(100), nullable=True)
    created_at = db.Column(db.DateTime, default=db.func.current_timestamp())
    updated_at = db.Column(db.DateTime,
                           default=db.func.current_timestamp(),
                           onupdate=db.func.current_timestamp())

    response_fields = {
        'id': fields.Integer,
        'name': fields.String,
        'issuer': fields.String,
        'details': fields.String,
    }

    def __init__(self, data):
        """Inits Certifications with data that user inputted

        The data already validated on the resources function

        Args:
            name: a string of certification's name
            issuer: a string of issuer who issued the certification.
            details: a string that explains the certification.
        """
        self.name = data['name']
        self.issuer = data['issuer']
        self.details = data['details']
Ejemplo n.º 25
0
class MusicTag(db.Model):
    __tablename__ = 'music_tag'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(20), unique=True, nullable=False)
    category_id = db.Column(db.Integer, db.ForeignKey('music_category.id'))
    # musics = db.relationship('Music', backref='music_tag')
    addtime = db.Column(db.DATETIME, index=True, default=datetime.now)

    def __repr__(self):
        return '<MusicTag %r,%r>' % (self.category_id, self.name)
Ejemplo n.º 26
0
class User(db.Model):
    __tablename__ = 'user'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80), unique=True, nullable=False)
    pwd = db.Column(db.String(120), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    face = db.Column(db.String(255), unique=True, nullable=False)
    intro = db.Column(db.TEXT)
    uuid = db.Column(db.String(255), unique=True, nullable=False)
    addtime = db.Column(db.DATETIME, index=True, default=datetime.now)
    albums = db.relationship('Album', backref='user')
    favors = db.relationship('AlbumFavor', backref='user')

    # def __repr__(self):
    #     return '<User %r, 密码 %r>' % (self.name, self.pwd)

    def check_pwd(self, pwd):
        from werkzeug.security import check_password_hash
        return check_password_hash(self.pwd, pwd)
Ejemplo n.º 27
0
class SeePower(db.Model):
    __tablename__ = 'see_power'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(20), unique=True, nullable=False)

    # albums = db.relationship('Album', backref='see_power')

    def __repr__(self):
        return '<SeePower %r>' % self.name
Ejemplo n.º 28
0
class Project(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    project = db.Column(db.String(255))
    bugs = db.relationship(lambda: Bug, backref='bugs', lazy='dynamic')

    def __repr__(self):
        return '<Project: %r>' % self.project

    def to_dict(self):
        return {'id': self.id, 'project': self.project}
Ejemplo n.º 29
0
class DampakDesa(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    kejadian_id = db.Column(db.Integer, db.ForeignKey('kejadian.id'))
    desa_id = db.Column(db.Integer, db.ForeignKey('desa.id'))
    str_wilayah = db.Column(db.String(100))
    rumah = db.Column(db.Integer)
    sekolah = db.Column(db.Integer)
    t_ibadah = db.Column(db.Integer)
    md = db.Column(db.Integer)
    luka = db.Column(db.Integer)
    hilang = db.Column(db.Integer)
    pengungsi = db.Column(db.Integer)
    geom = db.Column(db.String(1000))
    cdate = db.Column(db.DateTime, default=datetime.now)
    mdate = db.Column(db.DateTime)
    cuser = db.Column(db.String(15))
    muser = db.Column(db.String(15))

    __tablename__ = 'dampak_desa'
Ejemplo n.º 30
0
class AdminLoginlog(db.Model):
    __tablename__ = "admin_loginlog"
    id = db.Column(db.Integer, primary_key=True)
    admin_id = db.Column(db.Integer,
                         db.ForeignKey('admin.id'))  # 指明某条登录日志记录是属于哪个管理员的
    ip = db.Column(db.String(100))  # 登录IP地址
    addtime = db.Column(db.DateTime, index=True, default=datetime.now)  # 登陆时间

    def __repr__(self):
        return "<AdminLoginlog %r>" % self.id