draft 1.2.7 (need test)

# Test Managers.ControlPanel HTML and add option to rerender (for debug purpose)
dev-linux
Ivan Maslov 3 years ago
parent 34396b13dd
commit b7ca9ad446

@ -7,18 +7,26 @@ from ..Web import Basic
class ControlPanel(): class ControlPanel():
""" """
Manage your control panel on the orchestrator Manage your control panel on the orchestrator
.. code-block:: python
# Usage example:
lCPManager = Orchestrator.Managers.ControlPanel(inControlPanelNameStr="TestControlPanel",
inJinja2TemplatePathStr="ControlPanel\\test.html", inJinja2TemplateRefreshBool = True)
""" """
mControlPanelNameStr = None mControlPanelNameStr = None
mJinja2TemplatePathStr = None mJinja2TemplatePathStr = None
mJinja2TemplateFileNameStr = None
mJinja2Loader = None mJinja2Loader = None
mJinja2Env = None mJinja2Env = None
mJinja2Template = None mJinja2Template = None
mJinja2TemplateRefreshBool = None
mBackwardCompatibilityHTMLDef = None mBackwardCompatibilityHTMLDef = None
mBackwardCompatibilityJSDef = None mBackwardCompatibilityJSDef = None
mBackwardCompatibilityJSONDef = None mBackwardCompatibilityJSONDef = None
def __init__(self, inControlPanelNameStr, inJinja2TemplatePathStr = None): def __init__(self, inControlPanelNameStr, inJinja2TemplatePathStr = None, inJinja2TemplateRefreshBool = False):
""" """
Constructor of the control panel manager Constructor of the control panel manager
@ -30,6 +38,7 @@ class ControlPanel():
raise Exception(f"Another control panel with name {inControlPanelNameStr} is already exists. Please resolve the error and restart") raise Exception(f"Another control panel with name {inControlPanelNameStr} is already exists. Please resolve the error and restart")
Orchestrator.GSettingsGet()["ServerDict"]["ControlPanelDict"][inControlPanelNameStr] = self Orchestrator.GSettingsGet()["ServerDict"]["ControlPanelDict"][inControlPanelNameStr] = self
self.Jinja2TemplatePathSet(inJinja2TemplatePathStr = inJinja2TemplatePathStr) self.Jinja2TemplatePathSet(inJinja2TemplatePathStr = inJinja2TemplatePathStr)
self.mJinja2TemplateRefreshBool = inJinja2TemplateRefreshBool
self.mControlPanelNameStr = inControlPanelNameStr # Set the name of the control panel self.mControlPanelNameStr = inControlPanelNameStr # Set the name of the control panel
def Jinja2TemplatePathSet(self, inJinja2TemplatePathStr): def Jinja2TemplatePathSet(self, inJinja2TemplatePathStr):
@ -42,6 +51,7 @@ class ControlPanel():
if inJinja2TemplatePathStr is not None: if inJinja2TemplatePathStr is not None:
lSystemLoaderPathStr = "/".join(inJinja2TemplatePathStr.split("\\")[0:-1]) lSystemLoaderPathStr = "/".join(inJinja2TemplatePathStr.split("\\")[0:-1])
lTemplateFileNameStr = inJinja2TemplatePathStr.split("\\")[-1] lTemplateFileNameStr = inJinja2TemplatePathStr.split("\\")[-1]
self.mJinja2TemplateFileNameStr = lTemplateFileNameStr
self.mJinja2Loader = jinja2.FileSystemLoader(lSystemLoaderPathStr) self.mJinja2Loader = jinja2.FileSystemLoader(lSystemLoaderPathStr)
self.mJinja2Env = jinja2.Environment(loader=self.mJinja2Loader, trim_blocks=True) self.mJinja2Env = jinja2.Environment(loader=self.mJinja2Loader, trim_blocks=True)
self.mJinja2Template = self.mJinja2Env.get_template(lTemplateFileNameStr) self.mJinja2Template = self.mJinja2Env.get_template(lTemplateFileNameStr)
@ -52,6 +62,8 @@ class ControlPanel():
:param inDataDict: :param inDataDict:
:return: :return:
""" """
if self.mJinja2TemplateRefreshBool == True:
self.mJinja2Template = self.mJinja2Env.get_template(self.mJinja2TemplateFileNameStr)
lHTMLStr = self.mJinja2Template.render(**inDataDict) # Render the template into str lHTMLStr = self.mJinja2Template.render(**inDataDict) # Render the template into str
return lHTMLStr return lHTMLStr

Loading…
Cancel
Save