This commit is contained in:
yumoqing 2022-11-04 03:17:11 -04:00
parent c13dd66f05
commit 70256ae9de
3 changed files with 1337 additions and 1327 deletions

View File

@ -168,7 +168,6 @@ class Blocks(EventDispatcher):
try: try:
hc = HttpClient() hc = HttpClient()
resp=hc(url,method=method,params=params,files=files) resp=hc(url,method=method,params=params,files=files)
# print('Blocks.py :resp=',resp)
return resp return resp
except Exception as e: except Exception as e:
print_exc() print_exc()

View File

@ -6,6 +6,12 @@ from .threadcall import HttpClient
from .utils import absurl from .utils import absurl
from appPublic.registerfunction import RegisterFunction from appPublic.registerfunction import RegisterFunction
def getUrlData(url, method='GET', params={}):
blocks = Factory.Blocks()
d = blocks.getUrlData(url, method=method,
params=params)
return d
class DataGraber(EventDispatcher): class DataGraber(EventDispatcher):
""" """
Graber format Graber format
@ -17,7 +23,7 @@ class DataGraber(EventDispatcher):
"target":"third", "target":"third",
"params": "params":
"method": "method":
"pagging":"default false" "paging":"default false"
} }
} }
if dataurl present, the DataGraber using this dataurl to get and if dataurl present, the DataGraber using this dataurl to get and
@ -36,6 +42,11 @@ class DataGraber(EventDispatcher):
def load(self, *args, **kw): def load(self, *args, **kw):
ret = None ret = None
if self.options['paging']:
if kw.get('rows') is None:
kw['rows'] = 60
if kw.get('page') is None:
kw['page'] = 1
while True: while True:
try: try:
dataurl = self.options.get('dataurl') dataurl = self.options.get('dataurl')
@ -62,11 +73,11 @@ class DataGraber(EventDispatcher):
def loadUrlData(self, *args, **kw): def loadUrlData(self, *args, **kw):
dataurl = self.options.get('dataurl') dataurl = self.options.get('dataurl')
hc = HttpClient()
params = self.options.get('params',{}).copy() params = self.options.get('params',{}).copy()
params.update(kw) params.update(kw)
method = self.options.get('method','GET') method = self.options.get('method','GET')
d = hc(dataurl, params=params,method=method) d = getUrlData(dataurl, method=method,
params=params)
return d return d
def loadRFData(self, *args, **kw): def loadRFData(self, *args, **kw):
@ -126,7 +137,7 @@ class DataLoader(EventDispatcher):
def load(self): def load(self):
pass pass
class HttpDataLoader(DataLoader): class UrlDataLoader(DataLoader):
def load(self, *args, **kw): def load(self, *args, **kw):
app = App.get_running_app() app = App.get_running_app()
url = app.realurl(self.data_user.url) url = app.realurl(self.data_user.url)
@ -136,9 +147,9 @@ class HttpDataLoader(DataLoader):
"page":self.data_user.curpage, "page":self.data_user.curpage,
"rows":self.data_user.page_rows "rows":self.data_user.page_rows
}) })
hc = HttpClient()
try: try:
r = hc(url, method=method, params=params) r = getUrlData(url, method=method, params=params)
self.dispatch('on_success', r) self.dispatch('on_success', r)
return r return r
except Exception as e: except Exception as e:

View File

@ -13,7 +13,7 @@ from appPublic.jsonConfig import getConfig
from .baseWidget import Text, HTTPDataHandler from .baseWidget import Text, HTTPDataHandler
from .utils import CSize, absurl, alert from .utils import CSize, absurl, alert
from .form import StrSearchForm from .form import StrSearchForm
from .dataloader import HttpDataLoader from .dataloader import UrlDataLoader
from .dataloader import ListDataLoader from .dataloader import ListDataLoader
from .dataloader import RegisterFunctionDataLoader from .dataloader import RegisterFunctionDataLoader
@ -62,7 +62,7 @@ class PageLoader(EventDispatcher):
self.register_event_type('on_pageloaded') self.register_event_type('on_pageloaded')
self.newbegin = True self.newbegin = True
if self.url: if self.url:
self.loader = HttpDataLoader(self) self.loader = UrlDataLoader(self)
elif self.rfname: elif self.rfname:
self.loader = RegisterFunctionDataLoader(self) self.loader = RegisterFunctionDataLoader(self)
elif self.data: elif self.data: