in progress

dev-fastapi
Ivan Maslov 2 years ago
parent 7def532500
commit b6fbe1bba0

@ -158,20 +158,19 @@ class ControlPanel():
lHTMLStr = self.mInitJSJinja2Template.render(**inDataDict) # Render the template into str
return lHTMLStr
def DataDictGenerate(self, inRequest):
"""
def DataDictGenerate(self, inAuthTokenStr=None):
""" Сформировать словарь для генерации шаблона
:param inRequest: request handler (from http.server import BaseHTTPRequestHandler)
:param inAuthTokenStr: Текстовый токен авторизации пользователя
:return:
"""
lData = {
"StorageRobotDict": None,
"ControlPanelInstance":self,
"OrchestratorModule":Orchestrator,
"RequestInstance": inRequest,
"UserInfoDict": Orchestrator.WebUserInfoGet(inRequest=inRequest),
"UserUACDict": Orchestrator.UACUserDictGet(inRequest=inRequest),
"UserUACCheckDef": inRequest.UACClientCheck,
"UserInfoDict": Orchestrator.WebUserInfoGet(inAuthTokenStr=inAuthTokenStr),
"UserUACDict": Orchestrator.WebUserUACHierarchyGet(inAuthTokenStr=inAuthTokenStr),
"UserUACCheckDef": lambda inKeyList: Orchestrator.WebUserUACCheck(inAuthTokenStr=inAuthTokenStr,inKeyList=inKeyList),
"EnumerateDef": enumerate,
"OperatorModule": operator,
"MathModule": math
@ -184,36 +183,36 @@ class ControlPanel():
lData.update(self.mJinja2DataUpdateDict)
return lData
def OnRefreshHTMLStr(self, inRequest):
def OnRefreshHTMLStr(self, inAuthTokenStr=None):
"""
Event to generate HTML code of the control panel when refresh time is over.
Support backward compatibility for previous versions.
:param inRequest: request handler (from http.server import BaseHTTPRequestHandler)
:param inAuthTokenStr: request handler (from http.server import BaseHTTPRequestHandler)
:return:
"""
lHTMLStr = None
lL = Orchestrator.OrchestratorLoggerGet()
if self.mBackwardCompatibilityHTMLDef is None:
if self.mRefreshHTMLJinja2Template is not None or (self.mJinja2TemplateRefreshBool == True and self.mRefreshHTMLJinja2TemplateFileNameStr is not None):
lDataDict = self.OnRefreshHTMLDataDict(inRequest = inRequest)
lDataDict = self.OnRefreshHTMLDataDict(inAuthTokenStr = inAuthTokenStr)
# Jinja code
lHTMLStr = self.RefreshHTMLJinja2StrGenerate(inDataDict=lDataDict)
else:
lHTMLStr = self.BackwardAdapterHTMLDef(inRequest=inRequest)
lHTMLStr = self.BackwardAdapterHTMLDef(inAuthTokenStr=inAuthTokenStr)
# return the str
return lHTMLStr
def OnRefreshHTMLDataDict(self, inRequest):
def OnRefreshHTMLDataDict(self, inAuthTokenStr):
"""
Event to prepare data context for the futher Jinja2 HTML generation. You can override this def if you want some thing more data
:param inRequest: request handler (from http.server import BaseHTTPRequestHandler)
:return: dict
"""
return self.DataDictGenerate(inRequest=inRequest)
return self.DataDictGenerate(inAuthTokenStr=inAuthTokenStr)
def OnRefreshHTMLHashStr(self, inRequest):
def OnRefreshHTMLHashStr(self, inAuthTokenStr):
"""
Generate the hash the result output HTML. You can override this function if you know how to optimize HTML rendering.
TODO NEED TO MODIFY ServerSettings to work with Hash because of all defs are need do use Hash
@ -223,7 +222,7 @@ class ControlPanel():
"""
return None
def OnRefreshJSONDict(self, inRequest):
def OnRefreshJSONDict(self, inAuthTokenStr):
"""
Event to transmit some data from server side to the client side in JSON format. Call when page refresh is initialized
@ -234,36 +233,36 @@ class ControlPanel():
if self.mBackwardCompatibilityJSONDef is None:
pass
else:
lResultDict = self.BackwardAdapterJSONDef(inRequest=inRequest)
lResultDict = self.BackwardAdapterJSONDef(inAuthTokenStr=inAuthTokenStr)
return lResultDict
def OnInitJSStr(self, inRequest):
def OnInitJSStr(self, inAuthTokenStr):
"""
Event when orchestrator web page is init on the client side - you can transmit some java script code is str type to execute it once.
:param inRequest: request handler (from http.server import BaseHTTPRequestHandler)
:param inAuthTokenStr: request handler (from http.server import BaseHTTPRequestHandler)
:return: ""
"""
lJSStr = ""
if self.mBackwardCompatibilityJSDef is None:
if self.mInitJSJinja2Template is not None or (self.mJinja2TemplateRefreshBool == True and self.mInitJSJinja2TemplateFileNameStr is not None):
lDataDict = self.OnInitJSDataDict(inRequest = inRequest)
lDataDict = self.OnInitJSDataDict(inAuthTokenStr = inAuthTokenStr)
# Jinja code
lJSStr = self.InitJSJinja2StrGenerate(inDataDict=lDataDict)
else:
lJSStr = self.BackwardAdapterJSDef(inRequest=inRequest)
lJSStr = self.BackwardAdapterJSDef(inAuthTokenStr=inAuthTokenStr)
return lJSStr
def OnInitJSDataDict(self, inRequest):
def OnInitJSDataDict(self, inAuthTokenStr):
"""
Event to prepare data context for the futher Jinja2 JS init generation. You can override this def if you want some thing more data
:param inRequest: request handler (from http.server import BaseHTTPRequestHandler)
:return: dict
"""
return self.DataDictGenerate(inRequest=inRequest)
return self.DataDictGenerate(inAuthTokenStr=inAuthTokenStr)
def BackwardAdapterHTMLDef(self,inRequest):
def BackwardAdapterHTMLDef(self,inAuthTokenStr):
lGS = Orchestrator.GSettingsGet()
lL = Orchestrator.OrchestratorLoggerGet()
# HTMLRenderDef
@ -277,7 +276,7 @@ class ControlPanel():
if lDEFARGLen == 1: # def (inGSettings)
lHTMLResult = lItemHTMLRenderDef(lGS)
elif lDEFARGLen == 2: # def (inRequest, inGSettings)
lHTMLResult = lItemHTMLRenderDef(inRequest, lGS)
lHTMLResult = lItemHTMLRenderDef(inAuthTokenStr, lGS)
elif lDEFARGLen == 0: # def ()
lHTMLResult = lItemHTMLRenderDef()
# RunFunction
@ -294,7 +293,7 @@ class ControlPanel():
return lResultStr
def BackwardAdapterJSONDef(self,inRequest):
def BackwardAdapterJSONDef(self,inAuthTokenStr):
lGS = Orchestrator.GSettingsGet()
lL = Orchestrator.OrchestratorLoggerGet()
# HTMLRenderDef
@ -308,7 +307,7 @@ class ControlPanel():
if lDEFARGLen == 1: # def (inGSettings)
lJSONResult = lItemJSONGeneratorDef(lGS)
elif lDEFARGLen == 2: # def (inRequest, inGSettings)
lJSONResult = lItemJSONGeneratorDef(inRequest, lGS)
lJSONResult = lItemJSONGeneratorDef(inAuthTokenStr, lGS)
elif lDEFARGLen == 0: # def ()
lJSONResult = lItemJSONGeneratorDef()
# RunFunction
@ -323,7 +322,7 @@ class ControlPanel():
f"Ошибка при формирвоании JSON (JSONGeneratorDef). Идентификатор панели управления {self.mControlPanelNameStr}")
return lResultDict
def BackwardAdapterJSDef(self,inRequest):
def BackwardAdapterJSDef(self,inAuthTokenStr):
lGS = Orchestrator.GSettingsGet()
lL = Orchestrator.OrchestratorLoggerGet()
# HTMLRenderDef
@ -337,7 +336,7 @@ class ControlPanel():
if lDEFARGLen == 1: # def (inGSettings)
lJSResult = lJSInitGeneratorDef(lGS)
elif lDEFARGLen == 2: # def (inRequest, inGSettings)
lJSResult = lJSInitGeneratorDef(inRequest, lGS)
lJSResult = lJSInitGeneratorDef(inAuthTokenStr, lGS)
elif lDEFARGLen == 0: # def ()
lJSResult = lJSInitGeneratorDef()
if type(lJSResult) is str:

Loading…
Cancel
Save