Ejemplo n.º 1
0
class CategoryAttr(SurrogatePK, Model):
    """默认的三个类型选项
	用户无法更改,mark标记唯一,
	管理员更改,外键模板 模板可添加多个文章页等
	数据库读取mark标记
	"""

    __tablename__ = 'category_attrs'

    name = Column(db.String(80), nullable=False)
    summary = Column(db.String(80), nullable=False)
    mark = Column(db.String(80), nullable=False)
    #链接地址
    url = Column(db.String(80), nullable=False)
    #模板页
    templates = Column(db.String(80), nullable=False)

    #用户分类
    category = relationship('Category',
                            backref='categorys_attr',
                            lazy='select')
    #默认内容
    static_context = relationship('TemplatesDefault', backref='category_attrs')

    #模板
    usertemplate_id = reference_col('user_templates')

    #: 栏目页 ,(文章页,图集页,内容页 )

    def __repr__(self):
        return '<({name!r})>'.format(name=self.name)
Ejemplo n.º 2
0
class Grade(SurrogatePK, Model):

    __tablename__ = 'grade'
    __table_args__ = {'comment': '年级班级表'}

    name = Column(db.String(100), comment='班级名称')
    remark = Column(db.String(200), comment='描述')
    teacher_id = Column(db.Integer(), comment='教师ID')
    sort = Column(db.Integer(), default=100)

    @classmethod
    def insert_data(cls, form):
        teacher_id = form.get("teacher_id") if form.get("teacher_id") else 0
        sort = form.get("sort") if form.get("sort") else 100
        phone = form.get('phone')
        teacher = Teacher.query.filter_by(phone=phone).first()
        if not teacher:
            flash("该手机号不正确,没有对应的教师")
            return False
        cls.create(
            name=form.get("name"),
            remark=form.get("remark"),
            teacher_id=teacher.id,
            sort=sort,
        )
Ejemplo n.º 3
0
class Category(SurrogatePK,Model):
    """产品分类表:categorys  

    列表参数:
     - product_id:外键产品表 产品id
     - name:分类名称
     - ico:分类图标
     - sort:分类排序
     - active:是否激活 用户是否删除?
     - show:是否显示  
     
    """

    __tablename__ = 'categorys'

    name = Column(db.String(100))
    ico = Column(db.String(200))
    sort = Column(db.Integer())
    active = Column(db.Boolean(),default=True)
    show = Column(db.Boolean(),default=True)


    #:自身上级,引用自身无限级分类
    parent = reference_col('categorys')
    childrens = relationship("Category",lazy="joined",join_depth=2)
    
    product_id = relationship(Product, backref='products')
Ejemplo n.º 4
0
class Outsiders(SurrogatePK, Model):
    """其他人员 外来人员"""

    __tablename__ = "outsiders"

    name = Column(db.String(50), comment='姓名')
    user_id = Column(db.Integer())
    remark = Column(db.String(200), comment='描述')
Ejemplo n.º 5
0
class StaticContext(SurrogatePK,Model):
	__tablename__ = 'static_contexts'
	html = Column(db.UnicodeText)
	
	default_html = Column(db.UnicodeText)
	main_sort = Column(db.Integer,default=100)


	user = reference_col('users')
	category = reference_col('categorys')
Ejemplo n.º 6
0
class Order(SurrogatePK, Model):
    """订单表:orders  

    列表参数:
     - users_id:外键用户表 购买人
     - products_id:外键产品表 产品id
     - created_at:创建时间
     - consignee:收货人
     - consignee_phone:收货人电话
     - consignee_adress:收货人地址
     - count:购买总数量
     - price:总金额
     - pay_type:支付类型  注册激活、积分购买、等等
     - buy_type:购买类型  商城购买、注册购买
     - state:订单状态 默认0

    """

    __tablename__ = 'orders'

    users_id = reference_col('users')
    products_id = reference_col('products')

    consignee = Column(db.String(30))
    consignee_phone = Column(db.String(30))
    consignee_address = Column(db.String(200))
    count = Column(db.Integer())
    price = Column(db.Numeric(precision=10,scale=2,\
        asdecimal=True, decimal_return_scale=None),default=0)
    pay_type = Column(db.String(100))
    buy_type = Column(db.String(100))
    state = Column(db.Integer(), default=0)
    created_at = Column(db.DateTime,
                        nullable=False,
                        default=datetime.datetime.now)
Ejemplo n.º 7
0
class TemplatesDefault(SurrogatePK, Model):

    __tablename__ = 'template_defaults'

    main_sort = Column(db.Integer, nullable=False)
    html = Column(db.UnicodeText)

    #所属模板
    # user_template = reference_col('user_templates')
    #所属模板属性分类
    user_template_category = reference_col('category_attrs')
Ejemplo n.º 8
0
class UserUrlAndTemplate(SurrogatePK, Model):

    __tablename__ = 'user_url_and_templates'

    user_url = Column(db.String(100), nullable=False)

    user = reference_col('users')
    template = reference_col('user_templates')

    created_at = Column(db.DateTime, nullable=False, default=dt.datetime.now)
    end_time_at = Column(db.DateTime, nullable=False, default=dt.datetime.now)
Ejemplo n.º 9
0
class SystemVersion(SurrogatePK, Model):

    __tablename__ = 'system_versions'
    #版本号
    number = Column(db.String(20))
    #标题
    title = Column(db.String(100))
    #描述
    summary = Column(db.String(200))
    #内容
    context = Column(db.UnicodeText)

    created_at = Column(db.DateTime, nullable=False, default=dt.datetime.now)
Ejemplo n.º 10
0
class SystemMsg(SurrogatePK, Model):

    __tablename__ = 'system_msger'

    #标题
    title = Column(db.String(100))
    #内容
    context = Column(db.UnicodeText)
    #状态
    static = Column(db.Integer, default=0)

    created_at = Column(db.DateTime,
                        nullable=False,
                        default=dt.datetime.utcnow)
Ejemplo n.º 11
0
class Menu(SurrogatePK, Model):

    __tablename__ = "menu"
    __table_args__ = {'comment': '菜单权限表'}

    title = Column(db.String(100), nullable=False)
    pid = Column(db.Integer(), comment="上级")
    status = Column(db.Integer(), comment="状态", default=0)
    sort = Column(db.Integer(), comment="排序", default=100)
    is_url = Column(db.Boolean(), comment="是否路由地址", default=False)
    url = Column(db.String(200), comment="路由地址")
    blueprint = Column(db.String(50), comment="蓝图地址")
    icon = Column(db.String(50), comment="图标")

    @classmethod
    def insert_data(cls, form):
        status = True if form.get("status") else False
        is_url = True if form.get("is_url") else False
        cls.create(title=form.get("title"),
                   pid=form.get("pid"),
                   status=status,
                   sort=form.get("sort"),
                   is_url=is_url,
                   url=form.get("url"),
                   blueprint=form.get("blueprint"),
                   icon=form.get("icon"))
Ejemplo n.º 12
0
class SysConfig(SurrogatePK, Model):
    """系统配置表 """
    __tablename__ = 'sysconfig'
    #站点名称
    web_name = Column(db.String(80), nullable=False)
    #站点描述
    web_describe = Column(db.String(500))
    #开放注册
    user_register = Column(db.Boolean, default=True)
    #是否启用站点
    active_site = Column(db.Boolean, default=True)

    def init_insert():
        db.session.add(SysConfig(web_name='default'))
        db.session.commit()
Ejemplo n.º 13
0
class UserRole(SurrogatePK, Model):

    __tablename__ = "user_role"

    user_id = Column(db.Integer(), comment='用户ID')
    role_id = Column(db.Integer(), comment='角色ID')

    @classmethod
    def insert_data(cls, form):
        user_id = form.get("user_id")
        role_id = form.get("role_id")

        result = cls.query.filter_by(user_id=user_id, role_id=role_id).first()
        if not result:
            cls.create(role_id=role_id, user_id=user_id)
Ejemplo n.º 14
0
class AccessRecords(SurrogatePK,Model):
    
    __tablename__ = "access_records"
    
    user_id:int = Column(db.Integer(),comment='用户ID')
    created_at = Column(db.DateTime, nullable=False, default=dt.datetime.now,comment='创建时间')
    
    @classmethod
    def insert_data(cls,q_number)->dict:
        q_number:str = q_number
        print(q_number)
        # if not re.match('^S\d', q_number):
        #     return {'msg':'输入错误',"code":-1}
        # q_number = q_number.replace('S','').strip()	
        
        user = User.query.filter_by(q_number=q_number).first()
        if not user:
            return {"msg":"信息错误,没有该用户信息","code":-1}
        else:
            user_id = user.id
            
        cls.create(
            user_id = user_id
        )
            
        # 根据编号头位S为学生
        # 查询是否有请假状态
        if q_number[:1]=="S":
            ask_leave:AskLeave = AskLeave.query.filter_by(ask_user=user_id).filter(AskLeave.status.in_([0,1,2,3])).first()
            student = Student.query.with_entities(Student,Grade.name).join(Grade,Grade.id==Student.grade_id).filter(Student.user_id==user.id).first()
            
            if ask_leave:
                
                if ask_leave.status==0:
                    return {"msg":"该学生的请假信息等待审批中。",'code':-1}
                if ask_leave.status==1:
                    return {"msg":"该学生的请假信息正在审批中。",'code':-1}
                if ask_leave.status==2:
                    ask_leave.update(status=3)
                    return {"msg":"学生:"+user.name+"【"+student[1]+"】"+"请假已生效",'code':1,"avatar":user.avatar}
                if ask_leave.status==3:
                    ask_leave.update(status=4)
                    return {"msg":"学生:"+user.name+"【"+student[1]+"】"+"请假已归来",'code':1,"avatar":user.avatar}
                
                
            return {"msg":"【"+student[1]+"】"+user.name+"已扫描","code":1,"avatar":user.avatar}
                
        return {"msg":user.name+"已出入","code":1}
Ejemplo n.º 15
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
Ejemplo n.º 16
0
class SysParam(SurrogatePK, Model):
    """系统参数表

    表名称:sysparam

    列表参数
     - web_name:站点名称
     - web_describe:站点描述
     - user_register:开放注册
     - active_site:是否启用站点
     - close_website_message:关闭站点提示消息
     - close_register_user_message:关闭会员注册提示消息
     - withdraw_money:允许提现

    """
    __tablename__ = 'sysconfig'
    web_name = Column(db.String(80), nullable=False)
    web_describe = Column(db.String(500))
    user_register = Column(db.Boolean, default=True)
    active_site = Column(db.Boolean, default=True)
    close_website_message = Column(db.String(500))
    close_register_user_message = Column(db.String(500))
    withdraw_money = Column(db.Boolean(), default=True)

    def init_insert():
        db.session.add(SysConfig(web_name='default'))
        db.session.commit()
Ejemplo n.º 17
0
class Access(SurrogatePK, Model):

    __tablename____ = "access"
    __table_args__ = {'comment': '权限表'}

    url = Column(db.String(200), nullable=False, comment="路由正则匹配")
    name = Column(db.String(100), comment="节点名称")
    status = Column(db.Integer(), comment="状态", default=1)
    sort = Column(db.Integer(), comment="排序", default=100)
    is_del = Column(db.Boolean(), comment="是否删除", default=False)
    create_at = Column(db.DateTime(), default=dt.datetime.now, comment='创建时间')
    user_id = Column(db.Integer(), comment="创建用户")

    @classmethod
    def insert_data(cls, form):
        status = True if form.get("status") else False
        sort = form.get("sort") if form.get("sort") else 100
        is_del = True if form.get("is_del") else False
        is_url = form.get("is_url") if form.get("is_url") else ''
        pid = form.get("pid") if form.get("pid") else 0
        is_del = True if form.get("pid") else False
        cls.create(name=form.get("name"),
                   url=form.get("url"),
                   status=status,
                   sort=sort,
                   is_del=is_del,
                   user_id=current_user.id)
Ejemplo n.º 18
0
class Car(SurrogatePK, Model):

    __tablename__ = "car"

    number = Column(db.String(100), comment='车牌号')
    car_type = Column(db.String(100), comment='车辆类型')
    brand = Column(db.String(100), comment='品牌')
    colour = Column(db.String(100), comment='颜色')
    status = Column(db.Integer(), default=0, comment='状态默认')
    user_id = Column(db.Integer())
    created_at = Column(db.DateTime,
                        nullable=False,
                        default=dt.datetime.now,
                        comment='创建时间')

    @classmethod
    def insert_data(cls, form):
        status = True if form.get("status") else False
        cls.create(
            number=form.get("number"),
            car_type=form.get("car_type"),
            status=status,
            brand=form.get("brand"),
            colour=form.get("colour"),
            user_id=form.get("user_id"),
        )
Ejemplo n.º 19
0
class UserMarkType(SurrogatePK,Model):

	__tablename__ = 'user_mark_types'

	name = Column(db.String(80))

	user_mark = db.relationship('UserMark', backref='user_marks',uselist=False)	

	user = reference_col('users')
Ejemplo n.º 20
0
class BuysCar(SurrogatePK, Model):
    """购物车
	参数列表:
	 - add_price:添加时的价格
	 - product_id:产品id,不做外键
	 - count:数量

	"""

    __tablename__ = 'buys_car'

    add_price = Column(db.Numeric(precision=10,scale=2,\
           asdecimal=True, decimal_return_scale=None),default=0)

    product_id = Column(db.Integer())
    count = Column(db.Integer())

    users_id = reference_col('users')
Ejemplo n.º 21
0
class Store(SurrogatePK, Model):
    """店铺 stores

    列表参数:
     - users_id:外键用户表
     - name:店铺名称
     - created_at:创建时间
     - active:是否激活。默认false

    """
    __tablename__ = 'stores'

    users_id = reference_col('users')

    name = Column(db.String(100))
    created_at = Column(db.DateTime,
                        nullable=False,
                        default=datetime.datetime.now)
    active = Column(db.Boolean(), default=False)
Ejemplo n.º 22
0
class ContentAttr(SurrogatePK, Model):
	"""内容属性,
	默认的三个类型选项,mark标记唯一
	用户无法更改
	数据库 读取mark标记  #普通common 首页home  热门hot  推荐recd
	"""

	__tablename__ = 'content_attrs'

	name = Column(db.String(80), nullable=False)

	mark = Column(db.String(80),unique=True,nullable=False)
	#文章
	article = db.relationship('Article', backref='content_attrs',lazy='dynamic')
	#图集
	photo = db.relationship('Photo', backref='content_attrs',lazy='dynamic')
	
	def __repr__(self):
		return '<ArticeAttr({name!r})>'.format(name=self.name)
Ejemplo n.º 23
0
class OrderProduct(SurrogatePK, Model):
    """订单商品列表 快照

    列表参数:
     - name:名称
     - thumbnail:缩略图
     - 
     - 
     - 

    """

    __tablename__ = 'order_products'

    name = Column(db.String(100))
    thumbnail = Column(db.String(200))
    price = Column(db.Numeric(precision=10,scale=2,\
        asdecimal=True, decimal_return_scale=None),default=0)
    count = Column(db.Integer())
Ejemplo n.º 24
0
class StudentParentMap(SurrogatePK, Model):

    __tablename__ = "student_parent_map"

    parent_id = Column(db.Integer(), comment='家长ID')
    student_id = Column(db.Integer(), comment='学生ID')

    @classmethod
    def insert_data(cls, form):
        parent_id = form.get("parent_id")
        student_id = form.get("student_id")

        result = cls.query.filter_by(parent_id=parent_id,
                                     student_id=student_id).first()
        if not result:
            cls.create(
                parent_id=parent_id,
                student_id=student_id,
            )
Ejemplo n.º 25
0
class UserTemplate(SurrogatePK, Model):

    __tablename__ = 'user_templates'

    name = Column(db.String(80), nullable=False)
    #是否完结默认模板内容,完结列表不在显示,以后模板多了会有很多列表所以在此设置
    is_end = Column(db.Boolean, default=False)
    #模板容量,用户选择该模板注册后所拥有的容量
    memory_capacity = Column(db.Integer, default=0)

    #默认模板主页内容
    # template_default = relationship('TemplatesDefault', backref='template',lazy='select')

    categoryattr = relationship('CategoryAttr', backref='usertemplate')

    user_id = relationship('User', backref='usertemplate', uselist=False)
    #用户网址模板关联
    user_url_and_template = relationship('UserUrlAndTemplate',
                                         backref='usertemplate')
Ejemplo n.º 26
0
class Role(SurrogatePK, Model):
    """A role for a user."""

    __tablename__ = "roles"
    name = Column(db.String(80), nullable=False)
    pid = Column(db.Integer(),comment="上级")
    remark = Column(db.String(100),comment="描述")
    sort = Column(db.Integer(),server_default='100',comment='排序')
    create_at = Column(db.DateTime(),comment='创建时间',default=dt.datetime.now)
    is_del = Column(db.Boolean(),comment="是否删除",default=False)

    def __init__(self, name, **kwargs):
        """Create instance."""
        db.Model.__init__(self, name=name, **kwargs)

    def __repr__(self):
        """Represent instance as a unique string."""
        return f"<Role({self.name})>"
    
    @classmethod
    def insert_data(cls,form):
        sort =  form.get("is_url") if form.get("is_url") else 100
        is_url =  True if form.get("is_url") else ''
        pid =  True if form.get("pid") else 0
        is_del =  True if form.get("pid") else False
        cls.create(
            name = form.get("name"),
            pid = pid,
            remark =  form.get("remark"),
            sort = sort,
            is_del = is_del,
        )
Ejemplo n.º 27
0
class RoleAccess(SurrogatePK,Model):
    """
    权限暂定menu菜单表
    """
    
    __tablename__ = "role_access"
    
    role_id = Column(db.Integer(),comment='角色ID')   
    access_id = Column(db.Integer(),comment="权限ID") 
    
    @classmethod
    def insert_data(cls,form):
        access_id = form.getlist("access")
        role_id = form.get("role_id")
        role_access = cls.query.filter_by(role_id=role_id).all()
        for x in role_access:
            cls.delete(x)
            
        for x in access_id:
            cls.create(
                role_id = role_id,
                access_id = x
            )
            
    @classmethod
    def all_access_data(cls,role_id):
        all_access = Access.query.all()
        role_access = RoleAccess.query.with_entities(Access,RoleAccess).join(Access,Access.id==RoleAccess.access_id).filter(RoleAccess.role_id==role_id).all()
        access_data = {}
        for x in all_access:
            access_data[x.id] = [x.id,x.name,0]
        for x in role_access:
            if x[0].id in access_data.keys():
                access_data[x[0].id] = [access_data[x[0].id][0],access_data[x[0].id][1],1]
                
        return access_data
            
        
Ejemplo n.º 28
0
class Role(SurrogatePK, Model):
    """A role for a user."""

    __tablename__ = 'roles'
    name = Column(db.String(80), unique=True, nullable=False)
    user_id = reference_col('users', nullable=True)
    user = relationship('User', backref='roles')

    def __init__(self, name, **kwargs):
        """Create instance."""
        db.Model.__init__(self, name=name, **kwargs)

    def __repr__(self):
        """Represent instance as a unique string."""
        return '<Role({name})>'.format(name=self.name)
Ejemplo n.º 29
0
class Banner(SurrogatePK,Model):
	__tablename__ = 'banners'
	#:横幅标题
	title = Column(db.String(100))
	#:横幅描述
	summary = Column(db.String(200))
	image = Column(db.String(200))
	alt = Column(db.String(80))
	sort = Column(db.Integer())

	user = Column(db.Integer, db.ForeignKey('users.id'))
Ejemplo n.º 30
0
class AskLeave(SurrogatePK, Model):
    """请假列表"""

    __tablename__ = "ask_leave"

    reason = Column(db.String(100), comment='请假事由')
    start_at = Column(db.DateTime,
                      nullable=False,
                      default=dt.datetime.now,
                      comment='请假开始时间')
    end_at = Column(db.DateTime, nullable=False, comment='请假结束时间')
    status = Column(db.Integer(),
                    default=0,
                    comment='状态 0已发起 1审批中 2 完成审批 3已出校门 4请假完成  -1拒绝')
    send_user = Column(db.Integer(), comment='发起人')
    ask_user = Column(db.Integer(), comment='请假用户  谁要请假')
    created_at = Column(db.DateTime,
                        nullable=False,
                        default=dt.datetime.now,
                        comment='创建时间')

    @classmethod
    def insert_data(cls, form):

        user = User.query.filter(
            or_(User.name == form.get("ask_user"),
                User.q_number == form.get("ask_user"))).first()
        if not user:
            flash("没有该用户")
            return False
        result = cls.query.filter_by(ask_user=user.id).filter(
            AskLeave.status.in_([0, 1, 2])).first()
        if result:
            flash("该用户已经在请假中了,不能重复申请假期")
            return False
        reason = form.get("reason_check") + "|" + form.get("reason")

        ask_id = cls.create(
            reason=reason,
            start_at=form.get("start_at"),
            end_at=form.get("end_at"),
            send_user=current_user.id,
            ask_user=user.id,
        )
        AskApproved.insert_data(ask_id, user.id)
        # 此处应该发起通知 相关用户
        flash("添加完成")
        return {"msg": "已发起请假,请等待审批", 'state': 1}