bug fixes and better handling of plugins
This commit is contained in:
parent
a9b074fa9a
commit
717251bd28
|
@ -3,7 +3,7 @@ import os
|
|||
import pandas as pd
|
||||
import transport
|
||||
import copy
|
||||
from jinja2 import Environment, BaseLoader
|
||||
from jinja2 import Environment, BaseLoader, FileSystemLoader
|
||||
import importlib
|
||||
import importlib.util
|
||||
|
||||
|
@ -61,6 +61,10 @@ class components :
|
|||
#return ' '.join(['<div id=":id" class=":id">'.replace(':id',id),_html,'</div>'])
|
||||
_html = ' '.join(['<div id=":id" class=":id">'.replace(':id',id),_html,'</div>'])
|
||||
appContext = Environment(loader=BaseLoader()).from_string(_html)
|
||||
#
|
||||
# If the rendering of the HTML happens here we should plugin custom functions (at the very least)
|
||||
#
|
||||
|
||||
return appContext.render(**_args)
|
||||
# return _html
|
||||
@staticmethod
|
||||
|
@ -119,4 +123,17 @@ class components :
|
|||
_uri = "/".join(["api",_key,_name])
|
||||
_map[_uri] = _pointer
|
||||
return _map
|
||||
|
||||
@staticmethod
|
||||
def context(_config):
|
||||
"""
|
||||
adding custom variables functions to Jinja2, this function should be called after plugins are loaded
|
||||
"""
|
||||
_plugins = _config['plugins']
|
||||
# if not location:
|
||||
# env = Environment(loader=BaseLoader())
|
||||
# else:
|
||||
location = _config['layout']['root']
|
||||
# env = Environment(loader=FileSystemLoader(location))
|
||||
env = Environment(loader=BaseLoader())
|
||||
# env.globals['routes'] = _config['plugins']
|
||||
return env
|
41
index.py
41
index.py
|
@ -11,7 +11,8 @@ import sys
|
|||
import os
|
||||
import json
|
||||
import copy
|
||||
|
||||
import io
|
||||
import base64
|
||||
from jinja2 import Environment, BaseLoader
|
||||
|
||||
|
||||
|
@ -27,16 +28,18 @@ def favicon():
|
|||
@_app.route("/")
|
||||
def _index ():
|
||||
global _config
|
||||
_args = {}
|
||||
_args = {'system':_config['system'],'routes':_config['plugins']}
|
||||
try:
|
||||
_args = {'system':_config['system']}
|
||||
|
||||
_args['layout'] = _config['layout']
|
||||
# _args = dict(_args,**_config['layout'])
|
||||
# _args = copy.copy(_config)
|
||||
uri = os.sep.join([_config['layout']['root'], _config['layout']['index']])
|
||||
_html = cms.components.html(uri,'index')
|
||||
e = Environment(loader=BaseLoader()).from_string(_html)
|
||||
_args['index'] = e.render(**_args)
|
||||
_html = cms.components.html(uri,'index',_args)
|
||||
_args['index'] = _html
|
||||
# e = Environment(loader=BaseLoader()).from_string(_html)
|
||||
# e = cms.components.context(_config).from_string(_html)
|
||||
# _args['index'] = e.render(**_args)
|
||||
_index_page = "index.html"
|
||||
except Exception as e:
|
||||
print ()
|
||||
|
@ -94,6 +97,25 @@ def _getproxy(module,name) :
|
|||
|
||||
|
||||
return _data,_code
|
||||
@_app.route("/api/<module>/<name>" , methods=['POST'])
|
||||
def _post (module,name):
|
||||
global _config
|
||||
uri = '/'.join(['api',module,name])
|
||||
|
||||
_args = request.json
|
||||
code = 404
|
||||
|
||||
_info = ""
|
||||
if uri in _config['plugins'] and _args:
|
||||
_pointer = _config['plugins'][uri]
|
||||
_info = _pointer(_args)
|
||||
if _info:
|
||||
code = 200
|
||||
|
||||
_info =io.BytesIO(_info)
|
||||
|
||||
_info = base64.encodebytes(_info.getvalue()).decode('ascii')
|
||||
return _info,code
|
||||
@_app.route('/version')
|
||||
def _version ():
|
||||
global _config
|
||||
|
@ -110,7 +132,7 @@ def cms_page():
|
|||
_html = cms.components.html(_uri,_id)
|
||||
e = Environment(loader=BaseLoader()).from_string(_html)
|
||||
# _data = {} #cms.components.data(_config)
|
||||
_args = {'system':_config['system']}
|
||||
_args = {'system':_config['system'],'routes':_config['plugins']}
|
||||
|
||||
_html = ( e.render(**_args))
|
||||
return _html,200
|
||||
|
@ -150,7 +172,10 @@ if __name__ == '__main__' :
|
|||
if 'plugins' in _config :
|
||||
_map = cms.components.plugins(_config)
|
||||
if _map :
|
||||
_config['plugins'] = _map
|
||||
_config['plugins'] = _map
|
||||
#
|
||||
# register the functions with Jinja2
|
||||
cms.components.context(_config)
|
||||
_args = _config['system']['app']
|
||||
_app.run(**_args)
|
||||
else:
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
<!--
|
||||
This file contains the panes for the various content on the page
|
||||
-->
|
||||
{{index|safe}}
|
||||
|
||||
{%for _name in layout.menu %}
|
||||
<div id="{{_name}}" class="{{_name}}"></div>
|
||||
{%endfor%}
|
||||
|
||||
{{index|safe}}
|
Loading…
Reference in New Issue