bug fixes: context handling

v2.0
Steve Nyemba 7 months ago
parent f6f7f097fb
commit bc95832fc9

@ -66,11 +66,6 @@ class Initializer :
_config = self._config _config = self._config
PATH= os.sep.join([_config['layout']['root'],'_plugins']) PATH= os.sep.join([_config['layout']['root'],'_plugins'])
# if not os.path.exists(PATH) :
# #
# # we need to determin if there's an existing
# print ([' **** ',PATH])
# PATH = os.sep.join(self._path.split(os.sep)[:-1]+ [PATH] )
if not os.path.exists(PATH) and self._location and os.path.exists(self._location) : if not os.path.exists(PATH) and self._location and os.path.exists(self._location) :
# #
# overriding the location of plugins ... # overriding the location of plugins ...
@ -79,7 +74,7 @@ class Initializer :
else: else:
_location = self._location _location = self._location
PATH = os.sep.join([_location, _config['layout']['root'],'_plugins']) PATH = os.sep.join([_location, _config['layout']['root'],'_plugins'])
_context = _config['system']['context']
_map = {} _map = {}
# if not os.path.exists(PATH) : # if not os.path.exists(PATH) :
# return _map # return _map
@ -93,9 +88,11 @@ class Initializer :
if not os.path.exists(_path): if not os.path.exists(_path):
continue continue
for _name in _conf[_key] : for _name in _conf[_key] :
_pointer = disk.plugins(path=_path,name=_name) _pointer = disk.plugins(path=_path,name=_name,context=_context)
if _pointer : if _pointer :
_uri = "/".join(["api",_key,_name]) _uri = "/".join(["api",_key,_name])
if _context :
_uri = f'{_context}/{_uri}'
_map[_uri] = _pointer _map[_uri] = _pointer
# #
# We are adding some source specific plugins to the user-defined plugins # We are adding some source specific plugins to the user-defined plugins
@ -103,9 +100,9 @@ class Initializer :
# #
if self._ISCLOUD : if self._ISCLOUD :
_plugins = cloud.plugins() _plugins = cloud.plugins(_context)
else: else:
_plugins = disk.plugins() _plugins = disk.plugins(context=_context)
# #
# If there are any plugins found, we should load them and use them # If there are any plugins found, we should load them and use them
@ -154,9 +151,10 @@ class Initializer :
# #
# post-processing menu, overwrite items and behaviors # post-processing menu, overwrite items and behaviors
# #
_layout = copy.deepcopy(self._config['layout']) _layout = copy.deepcopy(self._config['layout'])
_overwrite = _layout['overwrite'] if 'overwrite' in _layout else {} _overwrite = _layout['overwrite'] if 'overwrite' in _layout else {}
_context = self.system()['context']
for _name in _object : for _name in _object :
_submenu = _object[_name] _submenu = _object[_name]
_index = 0 _index = 0
@ -251,18 +249,22 @@ class Initializer :
_index = _layout['index'] _index = _layout['index']
_newpath = os.sep.join([_path,_oroot]) _newpath = os.sep.join([_path,_oroot])
self._config['system']['portal'] = self._caller != None self._config['system']['portal'] = self._caller != None
_context = self.system()['context']
if self._caller : if self._caller :
# #
self._config['system']['caller'] = {'icon':'/caller/main/' + self._caller.system()['icon']} _callerContext = self._caller.system()['context']
# self._config['system']['caller'] = {'icon': self._caller.icon()} if not self._config['system']['context'] :
self._config['system']['context'] = _callerContext
# self._config['system']['context'] = _callerContext
# self._config['system']['caller'] = {'icon':f'caller/main/' + self._caller.system()['icon']}
self._config['system']['caller'] = {'icon': 'caller/main/'+self._caller.system()['icon'].replace(_callerContext,'')}
if os.path.exists(_newpath) and not self._ISCLOUD: if os.path.exists(_newpath) and not self._ISCLOUD:
# #
# LOG: rewrite due to the mode in which the site is being run # LOG: rewrite due to the mode in which the site is being run
# #
_api = 'api/disk/read?uri='+_oroot _api = f'{_context}/api/disk/read?uri='+_oroot
_stream = json.dumps(self._config) _stream = json.dumps(self._config)
_stream = _stream.replace(_oroot,_api) _stream = _stream.replace(_oroot,_api)
# self._config = json.loads(_stream) # self._config = json.loads(_stream)
@ -274,19 +276,19 @@ class Initializer :
_logo = self._config['system']['logo'] _logo = self._config['system']['logo']
if self._ISCLOUD: if self._ISCLOUD:
_icon = f'/api/cloud/download?doc=/{_logo}' _icon = f'{_context}/api/cloud/download?doc=/{_logo}'
else: else:
_icon = f'api/disk/read?uri={_logo}' _icon = f'{_context}/api/disk/read?uri={_logo}'
if disk.exists(uri=_logo,config=self._config): if disk.exists(uri=_logo,config=self._config):
_icon = _logo _icon = _logo
if self._location : if self._location :
self._config['layout']['location'] = _path self._config['layout']['location'] = _path
self._config['system']['icon'] = _icon self._config['system']['icon'] = _icon
self._config['system']['logo'] = _logo self._config['system']['logo'] = _logo
# self.set('layout.root',os.sep.join([_path,_oroot])) # self.set('layout.root',os.sep.join([_path,_oroot]))
pass pass

@ -75,9 +75,10 @@ def _index ():
# # _args['routes']=_config['plugins'] # # _args['routes']=_config['plugins']
# # _system = cms.components.get_system(_config) #copy.deepcopy(_config['system']) # # _system = cms.components.get_system(_config) #copy.deepcopy(_config['system'])
# _html = "" # _html = ""
_args={} _args={'system':_handler.system(skip=['source','app','data']),'layout':_handler.layout()}
try: try:
uri = os.sep.join([_config['layout']['root'], _config['layout']['index']]) uri = os.sep.join([_config['layout']['root'], _config['layout']['index']])
# # _html = _route.get().html(uri,'index',_config,_system) # # _html = _route.get().html(uri,'index',_config,_system)
# _html = _handler.html(uri,'index') # _html = _handler.html(uri,'index')
_index_page = "index.html" _index_page = "index.html"
@ -93,7 +94,7 @@ def _index ():
# _args = {'layout':_config['layout'],'index':_html} # _args = {'layout':_config['layout'],'index':_html}
# _args['system'] = _handler.system(skip=['source','app','route']) # _args['system'] = _handler.system(skip=['source','app','route'])
return render_template(_index_page,**_args) return render_template(_index_page,**_args),200 if _index_page != "404.html" else 200
# @_app.route('/id/<uid>') # @_app.route('/id/<uid>')
# def people(uid): # def people(uid):
@ -134,10 +135,14 @@ def _getproxy(module,name) :
return _delegate(_handler,module,name) return _delegate(_handler,module,name)
def _delegate(_handler,module,name): def _delegate(_handler,module,name):
global _route
uri = '/'.join(['api',module,name]) uri = '/'.join(['api',module,name])
# _args = dict(request.args,**{}) # _args = dict(request.args,**{})
# _args['config'] = _handler.config() # _args['config'] = _handler.config()
_plugins = _handler.plugins() _plugins = _handler.plugins()
_context = _handler.system()['context']
if _context :
uri = f'{_context}/{uri}'
if uri not in _plugins : if uri not in _plugins :
_data = {} _data = {}
@ -153,7 +158,7 @@ def _delegate(_handler,module,name):
if type(_data) == pd.DataFrame : if type(_data) == pd.DataFrame :
_data = _data.to_dict(orient='records') _data = _data.to_dict(orient='records')
if type(_data) == list: if type(_data) == list:
_data = json.dumps(_data) _data = json.dumps(_data)
_code = 200 if _data else 500 _code = 200 if _data else 500
return _data,_code return _data,_code
@_app.route("/api/<module>/<name>" , methods=['POST']) @_app.route("/api/<module>/<name>" , methods=['POST'])
@ -162,32 +167,7 @@ def _post (module,name):
global _route global _route
_handler = _route.get() _handler = _route.get()
return _delegate(_handler,module,name) return _delegate(_handler,module,name)
# _config = _handler.config()
# _plugins = _handler.plugins()
# uri = '/'.join(['api',module,name])
# # _args = request.json
# # _args['config'] = _config
# code = 404
# _data = ""
# if uri in _plugins :
# _pointer = _plugins[uri]
# # _info = _pointer(**_args)
# _data = _pointer(request=request,config=_handler.config() )
# if type(_data) == pd.DataFrame :
# _data = _data.to_dict(orient='records')
# if type(_data) == list:
# _data = json.dumps(_data)
# _code = 200 if _data else 500
# # _info =io.BytesIO(_info)
# # _info = base64.encodebytes(_info.getvalue()).decode('ascii')
# return _data,code
@_app.route('/version') @_app.route('/version')
def _version (): def _version ():
global _route global _route
@ -252,23 +232,20 @@ def _cms_page ():
# _handler = _route.get() # _handler = _route.get()
# _config = _handler.config() # _config = _handler.config()
_uri = request.args['uri'] _uri = request.args['uri']
# _uri = os.sep.join([_config['layout']['root'],_uri]) # _uri = os.sep.join([_config['layout']['root'],_uri])
_title = request.args['title'] if 'title' in request.args else '' _title = request.args['title'] if 'title' in request.args else ''
# _args = {'system':_handler.system()} #cms.components.get_system(_config) }
# if 'plugins' in _config:
# _args['routes'] = _config['plugins']
# _html = _handler.html(_uri,_config) # cmsc.components.html(_uri,_title,_args)
# e = Environment(loader=BaseLoader()).from_string(_html)
# _args['system'] = _handler.system(skip=['app','source'])
# return e.render(**_args),200
_args = _route.render(_uri,_title) _args = _route.render(_uri,_title)
return _args[_title],200 return _args[_title],200
@_app.route('/set/<id>') @_app.route('/set/<id>')
def set(id): def set(id):
global _route global _route
_handler = _route.set(id) _route.set(id)
return redirect('/') _handler = _route.get()
_context = _handler.system()['context']
_uri = f'/{_context}'.replace('//','/')
return redirect(_uri)
@_app.route('/<id>') @_app.route('/<id>')
def _open(id): def _open(id):
global _route global _route

@ -6,3 +6,4 @@ numpy
pandas pandas
mistune mistune
pygments pygments
scholarly

@ -8,7 +8,8 @@ var menu = {}
* :id * :id
* :pid parent identifier * :pid parent identifier
*/ */
menu.apply = function (uri,id,pid){
menu.apply = function (uri,id,pid,_context){
id = id.replace(/ /g,'-') id = id.replace(/ /g,'-')
if(uri == null){ if(uri == null){
return ; return ;
@ -19,7 +20,7 @@ menu.apply = function (uri,id,pid){
httpclient.setHeader('uri',uri) httpclient.setHeader('uri',uri)
httpclient.setHeader('dom',id) httpclient.setHeader('dom',id)
httpclient.post('/page',function(x){ httpclient.post(_context+'/page',function(x){
var _html = x.responseText var _html = x.responseText
var template = document.createElement('template'); var template = document.createElement('template');
template.innerHTML = _html.trim(); template.innerHTML = _html.trim();

@ -26,7 +26,7 @@
<div class="active" onclick="window.open('{{_item.uri}}','_self')"> <div class="active" onclick="window.open('{{_item.uri}}','_self')">
{%elif _item.uri and _item.type not in ['dialog','embed'] %} {%elif _item.uri and _item.type not in ['dialog','embed'] %}
<div class="active" onclick="menu.apply('{{_item.uri}}','{{_item.text}}','{{_name}}')"> <div class="active" onclick="menu.apply('{{_item.uri}}','{{_item.text}}','{{_name}}','{{system.context}}')">
{% else %} {% else %}
<!-- working on links/widgets --> <!-- working on links/widgets -->
<div class="active" onclick='menu.apply_link({{_item|tojson}})'> <div class="active" onclick='menu.apply_link({{_item|tojson}})'>

Loading…
Cancel
Save