class drive(MysqlDB.Model): __tablename__ = 'cuteone_drive' id = MysqlDB.Column(MysqlDB.INT, primary_key=True) title = MysqlDB.Column(MysqlDB.String(255), unique=False) description = MysqlDB.Column(MysqlDB.String(255), unique=False) update_time = MysqlDB.Column(MysqlDB.DateTime(255), default=time.strftime('%Y-%m-%d %H:%M:%S'), onupdate=time.strftime('%Y-%m-%d %H:%M:%S')) create_time = MysqlDB.Column(MysqlDB.DateTime(255), default=time.strftime('%Y-%m-%d %H:%M:%S')) """ all """ @classmethod def all(cls): data = MysqlDB.session.query(cls).all() MysqlDB.session.close() return data # 根据ID查询出结果 @classmethod def find_by_id(cls, id): data = MysqlDB.session.query(cls).filter(cls.id == id).first() MysqlDB.session.close() return data # 获取设定主页的驱动 @classmethod def find_activate(cls): data = MysqlDB.session.query(cls).filter(cls.activate == "1").first() MysqlDB.session.close() return data @classmethod def update(cls, data): MysqlDB.session.query(cls).filter(cls.id == data['id']).update(data) MysqlDB.session.flush() MysqlDB.session.commit() MysqlDB.session.close() return @classmethod def deldata(cls, id): data = MysqlDB.session.query(cls).filter(cls.id == id).first() MysqlDB.session.delete(data) MysqlDB.session.flush() MysqlDB.session.commit() MysqlDB.session.close() return
class model(MysqlDB.Model): __tablename__ = 'cuteone_model' id = MysqlDB.Column(MysqlDB.INT, primary_key=True) name = MysqlDB.Column(MysqlDB.String(255), unique=False) title = MysqlDB.Column(MysqlDB.String(255), unique=False) config = MysqlDB.Column(MysqlDB.String(255), unique=False) status = MysqlDB.Column(MysqlDB.String(255), unique=False, default=1) update_time = MysqlDB.Column(MysqlDB.DateTime(255), default=time.strftime('%Y-%m-%d %H:%M:%S'), onupdate=time.strftime('%Y-%m-%d %H:%M:%S')) create_time = MysqlDB.Column(MysqlDB.DateTime(255), default=time.strftime('%Y-%m-%d %H:%M:%S')) @classmethod def all(cls): data = MysqlDB.session.query(cls).all() MysqlDB.session.close() return data # 根据ID查询出结果 @classmethod def find_by_id(cls, id): data = MysqlDB.session.query(cls).filter(cls.id == id).first() MysqlDB.session.close() return data @classmethod def find_by_name(cls, name): data = MysqlDB.session.query(cls).filter(cls.name == name).first() MysqlDB.session.close() return data @classmethod def update_by_name(cls, data): MysqlDB.session.query(cls).filter( cls.name == data['name']).update(data) MysqlDB.session.flush() MysqlDB.session.commit() return @classmethod def deldata(cls, id): data = MysqlDB.session.query(cls).filter(cls.id == id).first() MysqlDB.session.delete(data) MysqlDB.session.flush() MysqlDB.session.commit() MysqlDB.session.close() return @classmethod def deldata_by_name(cls, name): data = MysqlDB.session.query(cls).filter(cls.name == name).first() MysqlDB.session.delete(data) MysqlDB.session.flush() MysqlDB.session.commit() MysqlDB.session.close() return @classmethod def update(cls, data): MysqlDB.session.query(cls).filter(cls.id == data['id']).update(data) MysqlDB.session.flush() MysqlDB.session.commit() return
class config(MysqlDB.Model): __tablename__ = 'cuteone_config' id = MysqlDB.Column(MysqlDB.INT, primary_key=True) name = MysqlDB.Column(MysqlDB.String(255), unique=False) title = MysqlDB.Column(MysqlDB.String(255), unique=False) value = MysqlDB.Column(MysqlDB.String(255), unique=False) update_time = MysqlDB.Column(MysqlDB.DateTime(255), default=time.strftime('%Y-%m-%d %H:%M:%S'), onupdate=time.strftime('%Y-%m-%d %H:%M:%S')) create_time = MysqlDB.Column(MysqlDB.DateTime(255), default=time.strftime('%Y-%m-%d %H:%M:%S')) @classmethod def all(cls): data = {} for i in cls.query.all(): data[i.name] = i.value MysqlDB.session.close() return data # 校正账号密码是否正确 @classmethod def checkpassword(cls, username, password): userdata = MysqlDB.session.query(cls).filter( cls.name == "username").one() passdata = MysqlDB.session.query(cls).filter( cls.name == "password").one() MysqlDB.session.close() if username == userdata.value: if password == passdata.value: return {"code": True, "msg": ""} else: return {"code": False, "msg": "密码错误!"} else: return {"code": False, "msg": "账号错误!"} @classmethod def get_config(cls, table): data = MysqlDB.session.query(cls).filter(cls.name == table).one() MysqlDB.session.close() return data.value @classmethod def update(cls, data): MysqlDB.session.query(cls).filter( cls.name == data['name']).update(data) MysqlDB.session.flush() MysqlDB.session.commit() return
class authrule(MysqlDB.Model): __tablename__ = 'cuteone_auth_rule' id = MysqlDB.Column(MysqlDB.INT, primary_key=True) title = MysqlDB.Column(MysqlDB.String(255), unique=False) drive_id = MysqlDB.Column(MysqlDB.String(255), unique=False) path = MysqlDB.Column(MysqlDB.String(255), unique=False) password = MysqlDB.Column(MysqlDB.String(255), unique=False) status = MysqlDB.Column(MysqlDB.String(255), unique=False, default=1) update_time = MysqlDB.Column(MysqlDB.DateTime(255), default=time.strftime('%Y-%m-%d %H:%M:%S'), onupdate=time.strftime('%Y-%m-%d %H:%M:%S')) create_time = MysqlDB.Column(MysqlDB.DateTime(255), default=time.strftime('%Y-%m-%d %H:%M:%S')) @classmethod def all(cls): data = MysqlDB.session.query(cls).all() MysqlDB.session.close() return data # 根据ID查询出结果 @classmethod def find_by_id(cls, id): data = MysqlDB.session.query(cls).filter(cls.id == id).first() MysqlDB.session.close() return data @classmethod def deldata(cls, id): data = MysqlDB.session.query(cls).filter(cls.id == id).first() MysqlDB.session.delete(data) MysqlDB.session.flush() MysqlDB.session.commit() MysqlDB.session.close() return # 根据驱动ID获取规则列表 @classmethod def find_by_drive_id(cls, drive_id, path): data = MysqlDB.session.query(cls).filter( and_(cls.drive_id == drive_id, or_(cls.path == '', cls.path == path))).first() MysqlDB.session.close() return data # 根据驱动ID获取规则列表 @classmethod def find_by_drive_id_all(cls, drive_id): data = MysqlDB.session.query(cls).filter( cls.drive_id == drive_id).all() MysqlDB.session.close() return data @classmethod def update(cls, data): MysqlDB.session.query(cls).filter(cls.id == data['id']).update(data) MysqlDB.session.flush() MysqlDB.session.commit() return
class users(MysqlDB.Model): __tablename__ = 'cuteone_users' id = MysqlDB.Column(MysqlDB.INT, primary_key=True) username = MysqlDB.Column(MysqlDB.String(255), unique=False) password = MysqlDB.Column(MysqlDB.String(255), unique=False) nickname = MysqlDB.Column(MysqlDB.String(255), unique=False) email = MysqlDB.Column(MysqlDB.String(255), unique=False) mobile = MysqlDB.Column(MysqlDB.String(255), unique=False) avatar = MysqlDB.Column(MysqlDB.String(255), unique=False) sex = MysqlDB.Column(MysqlDB.String(255), unique=False) birthday = MysqlDB.Column(MysqlDB.String(255), unique=False) description = MysqlDB.Column(MysqlDB.String(255), unique=False) register_ip = MysqlDB.Column(MysqlDB.String(255), unique=False) login_num = MysqlDB.Column(MysqlDB.String(255), unique=False) last_login_ip = MysqlDB.Column(MysqlDB.String(255), unique=False) last_login_time = MysqlDB.Column(MysqlDB.String(255), unique=False) score = MysqlDB.Column(MysqlDB.String(255), unique=False) group = MysqlDB.Column(MysqlDB.String(255), unique=False) status = MysqlDB.Column(MysqlDB.String(255), unique=False) reg_time = MysqlDB.Column(MysqlDB.DateTime(255), default=time.strftime('%Y-%m-%d %H:%M:%S')) update_time = MysqlDB.Column(MysqlDB.DateTime(255), default=time.strftime('%Y-%m-%d %H:%M:%S'), onupdate=time.strftime('%Y-%m-%d %H:%M:%S')) """ """ @classmethod def all(cls): data = MysqlDB.session.query(cls).all() MysqlDB.session.close() return data # 根据ID查询出结果 @classmethod def find_by_id(cls, id): data = MysqlDB.session.query(cls).filter(cls.id == id).first() MysqlDB.session.close() return data @classmethod def check_username(cls, name): data = MysqlDB.session.query(cls).filter(cls.username == name).first() MysqlDB.session.close() return data @classmethod def update(cls, data): MysqlDB.session.query(cls).filter(cls.id == data['id']).update(data) MysqlDB.session.flush() MysqlDB.session.commit() MysqlDB.session.close() return @classmethod def deldata(cls, id): data = MysqlDB.session.query(cls).filter(cls.id == id).first() MysqlDB.session.delete(data) MysqlDB.session.flush() MysqlDB.session.commit() MysqlDB.session.close() return # 校正账号密码是否正确 @classmethod def checkpassword(cls, username, password, ip): result = MysqlDB.session.query(cls).filter(cls.username == username).first() MysqlDB.session.close() if result: if result.password == password: if result.status == 0: return {"code": False, "msg": "帐号被禁止"} else: cls.update({ "id": result.id, "login_num": int(result.login_num)+1, "last_login_time": time.strftime('%Y-%m-%d %H:%M:%S'), "last_login_ip": ip }) return {"code": True, "msg": result} else: return {"code": False, "msg": "密码错误"} else: return {"code": False, "msg": "账号错误"} # 分页 @classmethod def get_pages(cls, page_index, page_size): page_index = int(page_index) page_size = int(page_size) data = MysqlDB.session.query(cls).limit(page_size).offset((page_index - 1) * page_size).all() MysqlDB.session.close() return data # 下面这4个方法是flask_login需要的4个验证方式 def is_authenticated(cls): return True def is_active(cls): return True def is_anonymous(cls): return False def get_id(cls): return cls.id
class menu(MysqlDB.Model): __tablename__ = 'cuteone_menu' id = MysqlDB.Column(MysqlDB.INT, primary_key=True) pid = MysqlDB.Column(MysqlDB.String(255), unique=False) postion = MysqlDB.Column(MysqlDB.String(255), unique=False) title = MysqlDB.Column(MysqlDB.String(255), unique=False) url = MysqlDB.Column(MysqlDB.String(255), unique=False) icon = MysqlDB.Column(MysqlDB.String(255), unique=False) top_nav = MysqlDB.Column(MysqlDB.String(255), unique=False) activity_nav = MysqlDB.Column(MysqlDB.String(255), unique=False) type = MysqlDB.Column(MysqlDB.String(255), unique=False, default=0) type_name = MysqlDB.Column(MysqlDB.String(255), unique=False) activate = MysqlDB.Column(MysqlDB.String(255), unique=False) sort = MysqlDB.Column(MysqlDB.String(255), unique=False) status = MysqlDB.Column(MysqlDB.String(255), unique=False) update_time = MysqlDB.Column(MysqlDB.DateTime(255), default=time.strftime('%Y-%m-%d %H:%M:%S'), onupdate=time.strftime('%Y-%m-%d %H:%M:%S')) create_time = MysqlDB.Column(MysqlDB.DateTime(255), default=time.strftime('%Y-%m-%d %H:%M:%S')) """ postion: postion sort: 1是降序,2是升序 status: """ @classmethod def all(cls, postion=0, sort=1, status=1): if sort == 1: order_by = menu.sort.desc() else: order_by = menu.sort.asc() if status == 0: status = cls.status == 0 elif status == 1: status = cls.status == 1 else: status = or_(cls.status == 0, cls.status == 1) data = MysqlDB.session.query(cls).filter( and_(cls.postion == postion, status)).order_by(order_by).all() MysqlDB.session.close() return data # 根据ID查询出结果 @classmethod def find_by_id(cls, id): data = cls.query.filter(cls.id == id).first() MysqlDB.session.close() return data @classmethod def find_by_index(cls): data = cls.query.filter(cls.activate == 1).first() MysqlDB.session.close() return data @classmethod def deldata_by_title_type(cls, title, type): data = MysqlDB.session.query(cls).filter( and_(cls.title == title, cls.type == type)).first() MysqlDB.session.delete(data) MysqlDB.session.commit() MysqlDB.session.flush() MysqlDB.session.close() return @classmethod def deldata_by_type_name(cls, type_name): MysqlDB.session.query(cls).filter(cls.type_name == type_name).delete() MysqlDB.session.commit() MysqlDB.session.flush() MysqlDB.session.close() return @classmethod def deldata(cls, id): data = MysqlDB.session.query(cls).filter(cls.id == id).first() MysqlDB.session.delete(data) MysqlDB.session.commit() MysqlDB.session.flush() MysqlDB.session.close() return @classmethod def update(cls, data): MysqlDB.session.query(cls).filter(cls.id == data['id']).update(data) MysqlDB.session.flush() MysqlDB.session.commit() return
class drive_list(MysqlDB.Model): __tablename__ = 'cuteone_drive_list' id = MysqlDB.Column(MysqlDB.INT, primary_key=True) drive_id = MysqlDB.Column(MysqlDB.String(255), unique=False) title = MysqlDB.Column(MysqlDB.String(255), unique=False) client_id = MysqlDB.Column(MysqlDB.String(255), unique=False) client_secret = MysqlDB.Column(MysqlDB.String(255), unique=False) token = MysqlDB.Column(MysqlDB.String(255), unique=False) chief = MysqlDB.Column(MysqlDB.String(255), unique=False) status = MysqlDB.Column(MysqlDB.String(255), unique=False) update_time = MysqlDB.Column(MysqlDB.DateTime(255), default=time.strftime('%Y-%m-%d %H:%M:%S'), onupdate=time.strftime('%Y-%m-%d %H:%M:%S')) create_time = MysqlDB.Column(MysqlDB.DateTime(255), default=time.strftime('%Y-%m-%d %H:%M:%S')) @classmethod def all(cls, drive_id): data = MysqlDB.session.query(cls).filter( cls.drive_id == drive_id).order_by(cls.create_time.desc()).all() MysqlDB.session.close() return data # 根据ID查询出结果 @classmethod def find_by_id(cls, id): data = MysqlDB.session.query(cls).filter(cls.id == id).first() MysqlDB.session.close() return data # 根据drive_id查询列表 @classmethod def find_by_drive_id(cls, drive_id): data = MysqlDB.session.query(cls).filter( cls.drive_id == drive_id).all() MysqlDB.session.close() return data # 根据drive_id查询主盘 @classmethod def find_by_chief(cls, drive_id): data = MysqlDB.session.query(cls).filter( and_(cls.drive_id == drive_id, cls.chief == 1)).first() MysqlDB.session.close() return data @classmethod def update(cls, data): MysqlDB.session.query(cls).filter(cls.id == data['id']).update(data) MysqlDB.session.flush() MysqlDB.session.commit() MysqlDB.session.close() return @classmethod def deldata_by_id(cls, id): data = MysqlDB.session.query(cls).filter(cls.id == id).first() mongodb_del_drive(data.id) MysqlDB.session.delete(data) MysqlDB.session.flush() MysqlDB.session.commit() MysqlDB.session.close() return @classmethod def deldata_by_drive_id(cls, drive_id): data = MysqlDB.session.query(cls).filter( cls.drive_id == drive_id).all() for item in data: mongodb_del_drive(item.id) MysqlDB.session.delete(item) MysqlDB.session.flush() MysqlDB.session.commit() MysqlDB.session.close() return