From 6367b545baf4d92272305d0df0164c4075b02dba Mon Sep 17 00:00:00 2001 From: yumoqing Date: Mon, 13 Dec 2021 15:21:40 +0800 Subject: [PATCH] bugfix --- ahserver/crudProcessor.py | 44 +++++++++++++++++++++++++++++++++++ ahserver/functionProcessor.py | 4 ++-- ahserver/processorResource.py | 1 + 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 ahserver/crudProcessor.py diff --git a/ahserver/crudProcessor.py b/ahserver/crudProcessor.py new file mode 100644 index 0000000..66b099d --- /dev/null +++ b/ahserver/crudProcessor.py @@ -0,0 +1,44 @@ +import ujson as json +from .baseProcessor import BaseProcessor +from crud_engine.crud_engine import CRUDEngine + +class CrudProcessor(BaseProcessor): + @classmethod + def isMe(self, name): + return name == 'crud' + + def get_default_filter_data(self): + subffix = '.filterdata' + user = self.run_evn.get('user') + if user: + subffix = f'{subffix}.{user}' + f = f'{self.real_path}{subffix}' + if os.path.exists(f): + with codecs.open(f, 'r', 'utf-8') as ff: + d = json.load(ff) + return d + return None + + async def path_call(self, request, params={}): + await self.set_run_env(request) + dic = {} + with codees.open(self.real_path, 'r', 'utf-8') as f: + dic = json.load(f) + x = request.path.split('/') + if len(x) >= 3: + act = x[-2] + if act in [':browser', ':filter', ':add', ':edit', ':delete']: + database = x[-4] + table = x[-3] + else: + database = x[-3] + table = x[-2] + act = ':browser' + default_filter_data = self.get_default_filter_data() + ce = CRUDEngine(database, table, dic, default_filter_data) + return await ce.dispatch(act) + raise HttpError(500) + + async def datahandle(self, request): + self.content = await self.path_call(request) + diff --git a/ahserver/functionProcessor.py b/ahserver/functionProcessor.py index 4a640cd..25772da 100644 --- a/ahserver/functionProcessor.py +++ b/ahserver/functionProcessor.py @@ -36,9 +36,9 @@ class FunctionProcessor(BaseProcessor): async def datahandle(self,request): x = await self.path_call(request, self.path) - if isinstance(x,Response): + if isinstance(x,web.FileResponse): self.retResponse = x - elif isinstance(x,web.FileResponse): + elif isinstance(x,Response): self.retResponse = x else: self.content = x diff --git a/ahserver/processorResource.py b/ahserver/processorResource.py index db8a658..db963bd 100644 --- a/ahserver/processorResource.py +++ b/ahserver/processorResource.py @@ -33,6 +33,7 @@ from appPublic.timecost import TimeCost from appPublic.timeUtils import timestampstr from .baseProcessor import getProcessor +from .crudProcessor import CrudProcessor from .xlsxdsProcessor import XLSXDataSourceProcessor from .sqldsProcessor import SQLDataSourceProcessor from .functionProcessor import FunctionProcessor