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 lHTMLStr = self.mInitJSJinja2Template.render(**inDataDict) # Render the template into str
return lHTMLStr return lHTMLStr
def DataDictGenerate(self, inRequest): def DataDictGenerate(self, inAuthTokenStr=None):
""" """ Сформировать словарь для генерации шаблона
:param inRequest: request handler (from http.server import BaseHTTPRequestHandler) :param inAuthTokenStr: Текстовый токен авторизации пользователя
:return: :return:
""" """
lData = { lData = {
"StorageRobotDict": None, "StorageRobotDict": None,
"ControlPanelInstance":self, "ControlPanelInstance":self,
"OrchestratorModule":Orchestrator, "OrchestratorModule":Orchestrator,
"RequestInstance": inRequest, "UserInfoDict": Orchestrator.WebUserInfoGet(inAuthTokenStr=inAuthTokenStr),
"UserInfoDict": Orchestrator.WebUserInfoGet(inRequest=inRequest), "UserUACDict": Orchestrator.WebUserUACHierarchyGet(inAuthTokenStr=inAuthTokenStr),
"UserUACDict": Orchestrator.UACUserDictGet(inRequest=inRequest), "UserUACCheckDef": lambda inKeyList: Orchestrator.WebUserUACCheck(inAuthTokenStr=inAuthTokenStr,inKeyList=inKeyList),
"UserUACCheckDef": inRequest.UACClientCheck,
"EnumerateDef": enumerate, "EnumerateDef": enumerate,
"OperatorModule": operator, "OperatorModule": operator,
"MathModule": math "MathModule": math
@ -184,36 +183,36 @@ class ControlPanel():
lData.update(self.mJinja2DataUpdateDict) lData.update(self.mJinja2DataUpdateDict)
return lData 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. Event to generate HTML code of the control panel when refresh time is over.
Support backward compatibility for previous versions. 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: :return:
""" """
lHTMLStr = None lHTMLStr = None
lL = Orchestrator.OrchestratorLoggerGet() lL = Orchestrator.OrchestratorLoggerGet()
if self.mBackwardCompatibilityHTMLDef is None: if self.mBackwardCompatibilityHTMLDef is None:
if self.mRefreshHTMLJinja2Template is not None or (self.mJinja2TemplateRefreshBool == True and self.mRefreshHTMLJinja2TemplateFileNameStr is not 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 # Jinja code
lHTMLStr = self.RefreshHTMLJinja2StrGenerate(inDataDict=lDataDict) lHTMLStr = self.RefreshHTMLJinja2StrGenerate(inDataDict=lDataDict)
else: else:
lHTMLStr = self.BackwardAdapterHTMLDef(inRequest=inRequest) lHTMLStr = self.BackwardAdapterHTMLDef(inAuthTokenStr=inAuthTokenStr)
# return the str # return the str
return lHTMLStr 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 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) :param inRequest: request handler (from http.server import BaseHTTPRequestHandler)
:return: dict :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. 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 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 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 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: if self.mBackwardCompatibilityJSONDef is None:
pass pass
else: else:
lResultDict = self.BackwardAdapterJSONDef(inRequest=inRequest) lResultDict = self.BackwardAdapterJSONDef(inAuthTokenStr=inAuthTokenStr)
return lResultDict 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. 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: "" :return: ""
""" """
lJSStr = "" lJSStr = ""
if self.mBackwardCompatibilityJSDef is None: if self.mBackwardCompatibilityJSDef is None:
if self.mInitJSJinja2Template is not None or (self.mJinja2TemplateRefreshBool == True and self.mInitJSJinja2TemplateFileNameStr is not 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 # Jinja code
lJSStr = self.InitJSJinja2StrGenerate(inDataDict=lDataDict) lJSStr = self.InitJSJinja2StrGenerate(inDataDict=lDataDict)
else: else:
lJSStr = self.BackwardAdapterJSDef(inRequest=inRequest) lJSStr = self.BackwardAdapterJSDef(inAuthTokenStr=inAuthTokenStr)
return lJSStr 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 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) :param inRequest: request handler (from http.server import BaseHTTPRequestHandler)
:return: dict :return: dict
""" """
return self.DataDictGenerate(inRequest=inRequest) return self.DataDictGenerate(inAuthTokenStr=inAuthTokenStr)
def BackwardAdapterHTMLDef(self,inRequest): def BackwardAdapterHTMLDef(self,inAuthTokenStr):
lGS = Orchestrator.GSettingsGet() lGS = Orchestrator.GSettingsGet()
lL = Orchestrator.OrchestratorLoggerGet() lL = Orchestrator.OrchestratorLoggerGet()
# HTMLRenderDef # HTMLRenderDef
@ -277,7 +276,7 @@ class ControlPanel():
if lDEFARGLen == 1: # def (inGSettings) if lDEFARGLen == 1: # def (inGSettings)
lHTMLResult = lItemHTMLRenderDef(lGS) lHTMLResult = lItemHTMLRenderDef(lGS)
elif lDEFARGLen == 2: # def (inRequest, inGSettings) elif lDEFARGLen == 2: # def (inRequest, inGSettings)
lHTMLResult = lItemHTMLRenderDef(inRequest, lGS) lHTMLResult = lItemHTMLRenderDef(inAuthTokenStr, lGS)
elif lDEFARGLen == 0: # def () elif lDEFARGLen == 0: # def ()
lHTMLResult = lItemHTMLRenderDef() lHTMLResult = lItemHTMLRenderDef()
# RunFunction # RunFunction
@ -294,7 +293,7 @@ class ControlPanel():
return lResultStr return lResultStr
def BackwardAdapterJSONDef(self,inRequest): def BackwardAdapterJSONDef(self,inAuthTokenStr):
lGS = Orchestrator.GSettingsGet() lGS = Orchestrator.GSettingsGet()
lL = Orchestrator.OrchestratorLoggerGet() lL = Orchestrator.OrchestratorLoggerGet()
# HTMLRenderDef # HTMLRenderDef
@ -308,7 +307,7 @@ class ControlPanel():
if lDEFARGLen == 1: # def (inGSettings) if lDEFARGLen == 1: # def (inGSettings)
lJSONResult = lItemJSONGeneratorDef(lGS) lJSONResult = lItemJSONGeneratorDef(lGS)
elif lDEFARGLen == 2: # def (inRequest, inGSettings) elif lDEFARGLen == 2: # def (inRequest, inGSettings)
lJSONResult = lItemJSONGeneratorDef(inRequest, lGS) lJSONResult = lItemJSONGeneratorDef(inAuthTokenStr, lGS)
elif lDEFARGLen == 0: # def () elif lDEFARGLen == 0: # def ()
lJSONResult = lItemJSONGeneratorDef() lJSONResult = lItemJSONGeneratorDef()
# RunFunction # RunFunction
@ -323,7 +322,7 @@ class ControlPanel():
f"Ошибка при формирвоании JSON (JSONGeneratorDef). Идентификатор панели управления {self.mControlPanelNameStr}") f"Ошибка при формирвоании JSON (JSONGeneratorDef). Идентификатор панели управления {self.mControlPanelNameStr}")
return lResultDict return lResultDict
def BackwardAdapterJSDef(self,inRequest): def BackwardAdapterJSDef(self,inAuthTokenStr):
lGS = Orchestrator.GSettingsGet() lGS = Orchestrator.GSettingsGet()
lL = Orchestrator.OrchestratorLoggerGet() lL = Orchestrator.OrchestratorLoggerGet()
# HTMLRenderDef # HTMLRenderDef
@ -337,7 +336,7 @@ class ControlPanel():
if lDEFARGLen == 1: # def (inGSettings) if lDEFARGLen == 1: # def (inGSettings)
lJSResult = lJSInitGeneratorDef(lGS) lJSResult = lJSInitGeneratorDef(lGS)
elif lDEFARGLen == 2: # def (inRequest, inGSettings) elif lDEFARGLen == 2: # def (inRequest, inGSettings)
lJSResult = lJSInitGeneratorDef(inRequest, lGS) lJSResult = lJSInitGeneratorDef(inAuthTokenStr, lGS)
elif lDEFARGLen == 0: # def () elif lDEFARGLen == 0: # def ()
lJSResult = lJSInitGeneratorDef() lJSResult = lJSInitGeneratorDef()
if type(lJSResult) is str: if type(lJSResult) is str:

Loading…
Cancel
Save