Esempio n. 1
0
class User(CRUDMixin, db.Model):
    __tablename__ = 'user_is'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(30))
    password = db.Column(db.String(255))
    date_create = db.Column(db.DateTime(), default=datetime.now())

    @property
    def to_json(self):
        """Return object data in easily serializable format"""
        return {
            'id': self.id,
            'name': self.name,
            'date_create': self.date_create.strftime("%A, %d. %B %Y %I:%M%p"),
        }

    def check_encrypted_password(self, p):
        return pwd_context.verify(p + current_app.config['SALT'], self.password)

    @classmethod
    def encrypt_password(cls, password):
        return pwd_context.encrypt(password + current_app.config['SALT'])

    @classmethod
    def get_by_name(cls, name):
        return cls.query.filter_by(name=name).first()

    def __repr__(self):
        return f"<User-ID:{self.id} NAME: {self.name} >"
Esempio n. 2
0
class Pages(CRUDMixin, db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title= db.Column(db.String(264), index=True, unique=True)
    url = db.Column(db.String(64), index=True, unique=True)
    content = db.Column(db.Text)

    def __repr__(self):
        return '<Url Page {}>'.format(self.url)
Esempio n. 3
0
class Tag(CRUDMixin, db.Model):
    __tablename__ = 'tag'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, nullable=False)
    weight = db.Column(db.Integer, index=True, default=0)
    slug = db.Column(db.String, nullable=False)

    def __str__(self):
        return self.name
Esempio n. 4
0
class Inventory(db.Model):
    __tablename__ = "inventory"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    code = db.Column(db.String(200), index=True, unique=True)
    type = db.Column(db.String(100), index=True)
    created_date = db.Column(db.DateTime,
                             nullable=False,
                             default=db.func.now())
    assignee = db.Column(db.String(100), nullable=True)

    def __repr__(self) -> str:
        return f"<Iventory {self.id}:{self.code}>"
Esempio n. 5
0
class User(CRUDMixin, UserMixin, db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(64), index=True, unique=True)
    email = db.Column(db.String(120), index=True, unique=True)
    password_hash = db.Column(db.String(128))

    def __repr__(self):
        return '<User {}>'.format(self.username)

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

    def check_password(self, password):
        return check_password_hash(self.password_hash, password)
Esempio n. 6
0
class Role(SurrogatePK, Model, RoleMixin):
    """A role for a user."""

    __tablename__ = 'roles'

    name = db.Column(db.String(80))
    parents = db.relationship(
        'Role',
        secondary=roles_parents,
        primaryjoin=("Role.id == roles_parents.c.role_id"),
        secondaryjoin=("Role.id == roles_parents.c.parent_id"),
        backref=db.backref('children', lazy='dynamic'))

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

    def add_parent(self, parent):
        # You don't need to add this role to parent's children set,
        # relationship between roles would do this work automatically
        self.parents.append(parent)

    def add_parents(self, *parents):
        for parent in parents:
            self.add_parent(parent)

    @staticmethod
    def get_by_name(name):
        return Role.query.filter_by(name=name).first()
Esempio n. 7
0
class Img(CRUDMixin, db.Model):
    __tablename__ = 'img_is'
    id = db.Column(db.Integer, primary_key=True)
    path = db.Column(db.String())
    name = db.Column(db.String())
    old_size = db.Column(db.String())
    new_size = db.Column(db.String())
    id_user = db.Column(db.Integer,
                        db.ForeignKey('user_is.id', ondelete='CASCADE'))
    date_create = db.Column(db.DateTime(), default=datetime.now())

    @property
    def to_json(self):
        """Return object data in easily serializable format"""
        return {
            'id': self.id,
            'path': self.path.split("main")[-1],
            'name': self.name,
            'old_size': self.old_size,
            'new_size': self.new_size,
            "id_user": self.id_user,
            "date_create": self.date_create.strftime("%d.%m.%Y %H:%M:%S"),
        }

    def __repr__(self):
        return f"<Img-ID:{self.id} NAME: {self.name} >"
Esempio n. 8
0
class Articles(CRUDMixin, db.Model):
    __tablename__ = 'article_model'
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String, name="Название", nullable=False)
    url = db.Column(db.String, name="Url", nullable=False)
    anons = db.Column(db.Text, name="Анонс")
    date = db.Column(db.DateTime, default=datetime.datetime.now)
    tags = db.relationship(Tag, secondary=article_tags_meta)
    author = db.Column(db.String, name="Автор")
    text = db.Column(db.Text, name="Результат")
    image = db.Column(db.String, nullable=False)
Esempio n. 9
0
class User(UserMixin, SurrogatePK, Model):
    """A user of the app."""

    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    username = Column(db.String(80), unique=True, nullable=False)
    email = Column(db.String(80), unique=True, nullable=False)
    #: The hashed password
    password = Column(db.Binary(128), nullable=True)
    created_at = Column(db.DateTime, nullable=False, default=dt.datetime.utcnow)
    first_name = Column(db.String(30), nullable=True)
    last_name = Column(db.String(30), nullable=True)
    active = Column(db.Boolean(), default=False)
    is_admin = Column(db.Boolean(), default=False)

    # roles = db.relationship(
    #     'Role',
    #     secondary='users_roles',
    #     backref=db.backref('roles', lazy='dynamic')
    # )

    # def __init__(self, username, email, password=None, **kwargs):
    #     """Create instance."""
    #     db.Model.__init__(self, username=username, email=email, **kwargs)
    #     if password:
    #         self.set_password(password)
    #     else:
    #         self.password = None

    def set_password(self, password):
        """Set password."""
        self.password = bcrypt.generate_password_hash(password)

    def check_password(self, value):
        """Check password."""
        return bcrypt.check_password_hash(self.password, value)

    @property
    def full_name(self):
        """Full user name."""
        return '{0} {1}'.format(self.first_name, self.last_name)

    def __repr__(self):
        """Represent instance as a unique string."""
        return '<User({username!r})>'.format(username=self.username)

    def add_role(self, role):
        self.roles.append(role)

    def add_roles(self, roles):
        for role in roles:
            self.add_role(role)

    def get_roles(self):
        for role in self.roles:
            yield role
Esempio n. 10
0
class Role(SurrogatePK,Model):
    """A role for a user."""

    __tablename__ = 'roles'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80), unique=True, nullable=False)
    # user_id = reference_col('users', nullable=True)
    # user = relationship('User', backref='roles')
    # parents = db.relationship(
    #     'Role',
    #     secondary='roles_parents',
    #     primaryjoin=('id == roles_parents.c.role_id'),
    #     secondaryjoin=('id == roles_parents.c.parent_id'),
    #     backref=db.backref('children', lazy='dynamic'),
    # )

    def __init__(self, name, **kwargs):
        """Create instance."""
        db.Model.__init__(self, name=name, **kwargs)
Esempio n. 11
0
class ImgUserCongig(CRUDMixin, db.Model):
    __tablename__ = 'img_user_config_is'
    id = db.Column(db.Integer, primary_key=True)
    id_user = db.Column(db.Integer,
                        db.ForeignKey('user_is.id', ondelete='CASCADE'))
    count = db.Column(db.Integer, default=0)
    limit = db.Column(db.Integer, default=20)

    @property
    def to_json(self):
        """Return object data in easily serializable format"""
        return {
            'id': self.id,
            'id_user': self.id_user,
            'count': self.count,
            "limit": self.limit
        }

    def __repr__(self):
        return f"<Img-User-Config-ID:{self.id} id_user: {self.id_user} >"
Esempio n. 12
0
class Photo(SurrogatePK,Model):
	__tablename__ = 'photos'
	#:图集标题
	title = Column(db.String(80),nullable=False)
	#:图集描述
	summary = Column(db.String(500))
	#:关键字
	key =  Column(db.String(80))
	#:关键描述
	word = Column(db.String(500))
	#:拍摄时间
	photos_date = Column(db.DateTime(),default=dt.datetime.now)
	#:创建时间
	creation_date = Column(db.DateTime(),default=dt.datetime.now)
	#缩略图 #保存路径
	image = Column(db.String(200))
	image_alt = Column(db.String(80))
	#:浏览次数
	count = Column(db.Integer,default=100)
	#:是否显示
	is_enable = Column(db.Boolean,default=True)
	

	#图集属性
	attr_id = db.Column(db.Integer,db.ForeignKey('content_attrs.id'))
	#图集照片
	photo_image = db.relationship('PhotoImage', backref='photo_images',lazy='dynamic')	

	#附加字段,附加字段值
	attach_key = Column(db.String(200))
	attach_value = Column(db.String(500))

	#静态内容,用“|”号隔开
	static_context = Column(db.UnicodeText)

	user = reference_col('users')
	category = reference_col('categorys')
Esempio n. 13
0
#coding=utf-8
from main.database import Column, Model, SurrogatePK, db, reference_col, relationship
from main.extensions import bcrypt, rbac
from flask_rbac import RoleMixin


class Permission:
    ADMINISTER = 0x8000  #管理员权限


roles_parents = db.Table(
    'roles_parents', db.Column('role_id', db.Integer,
                               db.ForeignKey('roles.id')),
    db.Column('parent_id', db.Integer, db.ForeignKey('roles.id')))


@rbac.as_role_model
class Role(SurrogatePK, Model, RoleMixin):
    """A role for a user."""

    __tablename__ = 'roles'

    name = db.Column(db.String(80))
    parents = db.relationship(
        'Role',
        secondary=roles_parents,
        primaryjoin=("Role.id == roles_parents.c.role_id"),
        secondaryjoin=("Role.id == roles_parents.c.parent_id"),
        backref=db.backref('children', lazy='dynamic'))

    def __init__(self, name):
Esempio n. 14
0
class TaskModel(db.Model, TimestampMixin):
    __tablename__ = 'task'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    text = db.Column(db.String(100), nullable=False)
    completed = db.Column(db.Boolean, default=False)
Esempio n. 15
0
class TimestampMixin(object):
    created = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
    updated = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
Esempio n. 16
0
#coding=utf-8
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from flask import current_app
# from flask_login import UserMixin
from flask_rbac import UserMixin

from main.database import Column, Model, SurrogatePK, db, reference_col, relationship
from main.extensions import bcrypt, rbac

import datetime

from main.models.recommend import Recommend
from main.models.buys_car import BuysCar

users_roles = db.Table(
    'users_roles', db.Column('user_id', db.Integer, db.ForeignKey('users.id')),
    db.Column('role_id', db.Integer, db.ForeignKey('roles.id')))


@rbac.as_user_model
class User(SurrogatePK, Model, UserMixin):
    """用户表.

    表名称:users

    列名称:
     - username:用户名
     - password:密码 ,hashed password
     - created_at:创建时间
     - name:姓名
     - active:是否激活。默认false
Esempio n. 17
0
import datetime
from main.database import db, CRUDMixin
from main.tags.models import Tag

article_tags_meta = db.Table(
    'article_tags',
    db.Model.metadata,
    db.Column('article_id_2', db.Integer, db.ForeignKey('article_model.id')),
    db.Column('tag_id', db.Integer, db.ForeignKey('tag.id')),
    extend_existing=True
)


class Articles(CRUDMixin, db.Model):
    __tablename__ = 'article_model'
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String, name="Название", nullable=False)
    url = db.Column(db.String, name="Url", nullable=False)
    anons = db.Column(db.Text, name="Анонс")
    date = db.Column(db.DateTime, default=datetime.datetime.now)
    tags = db.relationship(Tag, secondary=article_tags_meta)
    author = db.Column(db.String, name="Автор")
    text = db.Column(db.Text, name="Результат")
    image = db.Column(db.String, nullable=False)