pcpool/wwwroot/compute_pool_list/get_compute_pool.dspy

116 lines
2.6 KiB
Plaintext

ns = params_kw.copy()
userorgid = await get_userorgid()
if not userorgid:
return {
"widgettype":"Error",
"options":{
"title":"Authorization Error",
"timeout":3,
"cwidth":16,
"cheight":9,
"message":"Please login"
}
}
ns['resellerid'] = userorgid
ns['userorgid'] = userorgid
debug(f'get_compute_pool.dspy:{ns=}')
if not ns.get('page'):
ns['page'] = 1
if not ns.get('sort'):
ns['sort'] = 'id'
sql = '''select a.*, b.pool_type_text, c.status_text
from (select * from compute_pool where 1=1 [[filterstr]]) a left join (select k as pool_type,
v as pool_type_text from appcodes_kv where parentid='cluster_type') b on a.pool_type = b.pool_type left join (select k as status,
v as status_text from appcodes_kv where parentid='product_status') c on a.status = c.status'''
filterjson = params_kw.get('data_filter')
if not filterjson:
fields = [ f['name'] for f in [
{
"name": "id",
"title": "id",
"type": "str",
"length": 32,
"nullable": "no"
},
{
"name": "resellerid",
"title": "商户机构id",
"type": "str",
"length": 32,
"nullable": "no"
},
{
"name": "name",
"title": "池名称",
"type": "str",
"length": 128,
"nullable": "no"
},
{
"name": "pool_type",
"title": "集群类型(k8s/slurm/ray)",
"type": "char",
"length": 16,
"nullable": "no"
},
{
"name": "description",
"title": "描述",
"type": "text"
},
{
"name": "status",
"title": "状态(1=启用 0=停用)",
"type": "char",
"length": 1,
"default": "1"
},
{
"name": "created_at",
"title": "创建时间",
"type": "timestamp",
"nullable": "no"
},
{
"name": "updated_at",
"title": "更新时间",
"type": "timestamp",
"nullable": "no"
}
] ]
filterjson = default_filterjson(fields, ns)
filterdic = ns.copy()
filterdic['filterstr'] = ''
filterdic['userorgid'] = '${userorgid}$'
filterdic['userid'] = '${userid}$'
if filterjson:
dbf = DBFilter(filterjson)
conds = dbf.gen(ns)
if conds:
ns.update(dbf.consts)
conds = f' and {conds}'
filterdic['filterstr'] = conds
ac = ArgsConvert('[[', ']]')
vars = ac.findAllVariables(sql)
NameSpace = {v:'${' + v + '}$' for v in vars if v != 'filterstr' }
filterdic.update(NameSpace)
sql = ac.convert(sql, filterdic)
debug(f'{sql=}')
db = DBPools()
dbname = get_module_dbname('pcpool')
async with db.sqlorContext(dbname) as sor:
r = await sor.sqlPaging(sql, ns)
return r
return {
"total":0,
"rows":[]
}