def wizlistdata(): pageIndex = int(getargs("pageIndex", 0)) pageSize = int(getargs("pageSize", 0)) total = select(count(p.guid) for p in invite_list).first() data = select(p for p in invite_list).order_by(desc(invite_list.opdate)).limit(pageSize, pageSize * pageIndex) return getGridData(invite_list, total, data)
def getGridData(entity = None, total = 0, data = None) : ''' 获得miniui显示需要的表格json,自动获取排序,分页信息 多表联合查询时必须要把排序放在方法外实现 entity单表时可以不指定total,方法自动count(*)计算 多表联合必须指定total,目前使用len(data)后就不能正确执行分页,不知道原因 e.g data= select((p.title,x.sguid,p.guid,p.nextexec) for p in sqllist for x in sqlresult if p.guid==x.sguid) total = select(count( p.guid) for p in sqllist for x in sqlresult if p.guid == x.sguid).first() :param entity: pony实体 :param total:总数 :param data:数据集 ''' pageIndex = int(getargs("pageIndex", 0)) pageSize = int(getargs("pageSize", 0)) sortField = getargs('sortField') sortOrder = getargs('sortOrder') if entity : # single entity #取主键count 性能更好,如果没有指定就count(*) total = data.count() if not total else total #带排序字段 if sortField : if str(sortOrder).lower() == "asc" : data = data.order_by(getattr(entity, sortField)) else : data = data.order_by(desc(getattr(entity, sortField))) #带分页 if pageIndex or pageSize : data = data.limit(pageSize, pageSize * pageIndex) _columns_ = entity.__dict__['_columns_'] data = [{ x : getattr(row, x) for x in _columns_ } for row in data] else : # muiltpe table # 带排序字段,多表形式用order by 1,2 排序 #此处必须使用深度copy copy.deepcopy(data),避免操作原对象 # if sortField : sortindex = [x.split('.')[1] for x in copy.deepcopy(data)._col_names].index(sortField) + 1 if str(sortOrder).lower() == "asc" : data = data.order_by(sortindex) else : data = data.order_by(desc(sortindex)) #带分页 if pageIndex or pageSize : # 转换为QueryObject 获得_col_names data = data.limit(pageSize, pageSize * pageIndex) data = [Row(itertools.izip([x.split('.')[1] for x in data._col_names], row)) for row in data] data = { "total" : total, 'data' : data } return json.dumps(data, cls = CJsonEncoder)
def wizstart(): ''' 开始 ''' invite_code = getargs("invite_code") counts = getargs("counts") if invite_code and count: startmain(invite_code, counts) return "请稍后" else: return "输入有误"
def wizresult(): ''' 获取sqlresult数据 ''' pageIndex = int(getargs("pageIndex", 0)) pageSize = int(getargs("pageSize", 0)) invite_code = getargs("invite_code") total = select(count(p.guid) for p in wiz_user if p.invite_code == invite_code).first() data = select(p for p in wiz_user if p.invite_code == invite_code).order_by(desc(wiz_user.opdate)).limit(pageSize, pageSize * pageIndex) return getGridData(wiz_user, total, data)
def proxyresult(): ''' 获取proxyresult数据 ''' pageIndex = int(getargs("pageIndex", 0)) pageSize = int(getargs("pageSize", 0)) total = select(count(p.guid) for p in proxy_list).first() data = select(p for p in proxy_list ) \ .order_by(desc(proxy_list.state))\ .order_by(desc(proxy_list.opdate))\ .limit(pageSize, pageIndex) return getGridData(proxy_list, total, data)
def proxyresult(): ''' 获取proxyresult数据 ''' pageIndex = int(getargs("pageIndex", 0)) pageSize = int(getargs("pageSize", 0)) total = select(count(p.guid) for p in proxy_list ).first() data = select(p for p in proxy_list ) \ .order_by(desc(proxy_list.state))\ .order_by(desc(proxy_list.opdate))\ .limit(pageSize, pageIndex) return getGridData(proxy_list, total, data)
def index() : ''' 运维闲置资源管理 :return: ''' # 此模块的管理员角色名称 isadmin = IsAdmin(['系统管理员', '运维闲置资产管理市分']) #print(isadmin) if isGetMethod() : return render_template("yunwei/xianzhi.html", isadmin = isadmin) from autodb.models.yunwei import xianzhi zcbh = getargs('zcbh') #按资产编号进行查询 vsql = "p for p in xianzhi if True " if zcbh : vsql += " and p.zcbh=='{0}'".format(zcbh) if not isadmin: #不是管理员加限制 vsql+=" and p.creatorid=='{0}'".format(g.user.get_id()) data = select(vsql).order_by(desc(xianzhi.guid)) return getGridData(entity = xianzhi, data = data)
def index(): ''' 运维闲置资源管理 :return: ''' # 此模块的管理员角色名称 isadmin = IsAdmin(['系统管理员', '运维闲置资产管理市分']) #print(isadmin) if isGetMethod(): return render_template("yunwei/xianzhi.html", isadmin=isadmin) from autodb.models.yunwei import xianzhi zcbh = getargs('zcbh') #按资产编号进行查询 vsql = "p for p in xianzhi if True " if zcbh: vsql += " and p.zcbh=='{0}'".format(zcbh) if not isadmin: #不是管理员加限制 vsql += " and p.creatorid=='{0}'".format(g.user.get_id()) data = select(vsql).order_by(desc(xianzhi.guid)) return getGridData(entity=xianzhi, data=data)
def getproxy(): ''' 开始 ''' from wiz.Logic.getproxy import getPageList from Library.flaskhelper import getargs file = getargs('key', '2120') getPageList(file=file) return "ok"
def getproxy(): ''' 开始 ''' from wiz.Logic.getproxy import getPageList from Library.flaskhelper import getargs file=getargs('key','2120') getPageList(file=file) return "ok"
def sqlresult(): ''' 获取sqlresult数据 ''' sguid = getargs("sguid") from autodb.models.sqlresult import sqlresult data = select(p for p in sqlresult if p.sguid == sguid).order_by(desc(sqlresult.guid)) return getGridData(sqlresult, data=data)
def sell(): ''' 销售 ''' data = flaskhelper.getargs2json("data") price = flaskhelper.getargs('price') for item in data: invite_code = item['invite_code'] il=select(p for p in invite_list if p.invite_code==invite_code).first() wu=select(p for p in wiz_user if p.regcode==invite_code).first() wiz_sell(invite_code=invite_code,price=price,realcount=il.realcount,reguser=wu.reguser,regpsw=wu.regpsw) il.delete() wu.delete() return "ok"
def pagesso(): ''' 通过页面做sso登录,接收加密后的用户名时间 :return: ''' from autodb.config import IK,IV import binascii data= getargs("data") k = des(IK, CBC, IV, pad = None, padmode = PAD_PKCS5) hd=binascii.unhexlify(data) userdata= k.decrypt(hd) print('get:',userdata) #得到userdata,目前只存放加密后的4A工号,日后加验证逻辑 if sso(userdata): return userdata+"over" else: return "error"
def pagesso(): ''' 通过页面做sso登录,接收加密后的用户名时间 :return: ''' from autodb.config import IK, IV import binascii data = getargs("data") k = des(IK, CBC, IV, pad=None, padmode=PAD_PKCS5) hd = binascii.unhexlify(data) userdata = k.decrypt(hd) print('get:', userdata) #得到userdata,目前只存放加密后的4A工号,日后加验证逻辑 if sso(userdata): return userdata + "over" else: return "error"
def save(): data = flaskhelper.getargs("data") data = json.loads(data) saveData(proxy_list, data) return "ok"
def getGridData(entity=None, total=0, data=None): ''' 获得miniui显示需要的表格json,自动获取排序,分页信息 多表联合查询时必须要把排序放在方法外实现 entity单表时可以不指定total,方法自动count(*)计算 多表联合必须指定total,目前使用len(data)后就不能正确执行分页,不知道原因 e.g data= select((p.title,x.sguid,p.guid,p.nextexec) for p in sqllist for x in sqlresult if p.guid==x.sguid) total = select(count( p.guid) for p in sqllist for x in sqlresult if p.guid == x.sguid).first() :param entity: pony实体 :param total:总数 :param data:数据集 ''' pageIndex = int(getargs("pageIndex", 0)) pageSize = int(getargs("pageSize", 0)) sortField = getargs('sortField') sortOrder = getargs('sortOrder') if entity: # single entity #取主键count 性能更好,如果没有指定就count(*) total = data.count() if not total else total #带排序字段 if sortField: if str(sortOrder).lower() == "asc": data = data.order_by(getattr(entity, sortField)) else: data = data.order_by(desc(getattr(entity, sortField))) #带分页 if pageIndex or pageSize: data = data.limit(pageSize, pageSize * pageIndex) _columns_ = entity.__dict__['_columns_'] data = [{x: getattr(row, x) for x in _columns_} for row in data] else: # muiltpe table # 带排序字段,多表形式用order by 1,2 排序 #此处必须使用深度copy copy.deepcopy(data),避免操作原对象 # if sortField: sortindex = [ x.split('.')[1] for x in copy.deepcopy(data)._col_names ].index(sortField) + 1 if str(sortOrder).lower() == "asc": data = data.order_by(sortindex) else: data = data.order_by(desc(sortindex)) #带分页 if pageIndex or pageSize: # 转换为QueryObject 获得_col_names data = data.limit(pageSize, pageSize * pageIndex) data = [ Row(itertools.izip([x.split('.')[1] for x in data._col_names], row)) for row in data ] data = {"total": total, 'data': data} return json.dumps(data, cls=CJsonEncoder)
# coding: utf-8
def wizdata(): invite_code=flaskhelper.getargs('invite_code') total =1 data = select(p for p in wiz_user if p.regcode== invite_code) return getGridData(wiz_user, total, data)