ahserver_g/ahserver/dsProcessor.py

68 lines
1.9 KiB
Python
Raw Permalink Normal View History

2019-07-10 17:34:45 +08:00
import codecs
import json
2023-10-12 15:46:05 +08:00
import aiofiles
2019-07-10 17:34:45 +08:00
from appPublic.jsonConfig import getConfig
from appPublic.dictObject import DictObject
from .baseProcessor import BaseProcessor
from .serverenv import ServerEnv
class DataSourceProcessor(BaseProcessor):
@classmethod
def isMe(self,name):
return name=='ds'
def __init__(self,filename,k):
super(DataSourceProcessor,self).__init__(filename,k)
self.actions = {
'getdata':self.getData,
'pagingdata':self.getPagingData,
'arguments':self.getArgumentsDesc,
'resultFields':self.getDataDesc,
'gridlist':self.getGridlist,
}
self.g = ServerEnv()
2020-12-16 10:15:43 +08:00
async def getData(self,dict_data,ns,request):pass
async def getPagingData(self,dict_data,ns,request):pass
async def getArgumentsDesc(self,dict_data,ns,request):pass
async def getDataDesc(self,dict_data,ns,request):pass
async def getGridlist(self,dict_data,ns,request):
2019-07-10 17:34:45 +08:00
ret = self.getDataDesc(dict_data,ns,request)
ffs = [ f for f in ret if f.get('frozen',False) ]
fs = [ f for f in ret if not f['frozen'] ]
[ f.update({'hide':True}) for f in ffs if f.get('listhide',False) ]
[ f.update({'hide':True}) for f in fs if f.get('listhide') ]
d = {
"iconCls":"icon-search",
"url":self.resource.absUrl(request,request.path + '?action=pagingdata'),
"view":"bufferview",
"options":{
"pageSize":50,
"pagination":False
}
}
d.update({'fields':fs})
if len(ffs)>0:
d.update({'ffields':ffs})
ret = {
"__ctmpl__":"datagrid",
"data":d
}
return ret
2020-12-16 10:15:43 +08:00
async def path_call(self, request, path):
2019-07-10 17:34:45 +08:00
dict_data = {}
config = getConfig()
2023-10-12 15:46:05 +08:00
async with aiofiles.open(path,'r',encoding=config.website.coding) as f:
b = await f.read()
2019-07-10 17:34:45 +08:00
dict_data = json.loads(b)
2019-11-28 15:24:09 +08:00
ns = self.run_ns
2019-07-10 17:34:45 +08:00
act = ns.get('action','getdata')
action = self.actions.get(act)
2020-12-16 10:15:43 +08:00
return await action(dict_data,ns,request)
async def datahandle(self,request):
self.content = await path_call(request, self.path)
2019-07-10 17:34:45 +08:00