From 579e15f8f799de17654a46a1991496ad8b81a172 Mon Sep 17 00:00:00 2001 From: Steve Nyemba Date: Thu, 20 Oct 2022 14:20:31 -0500 Subject: [PATCH] refactoring ... --- cms/__init__.py | 5 +++++ cms/micro-cms.py | 10 ---------- index.py | 32 ++++++++++++++++++++------------ templates/404.html | 0 4 files changed, 25 insertions(+), 22 deletions(-) delete mode 100644 cms/micro-cms.py create mode 100644 templates/404.html diff --git a/cms/__init__.py b/cms/__init__.py index 0a14919..41450bb 100644 --- a/cms/__init__.py +++ b/cms/__init__.py @@ -67,4 +67,9 @@ class components : return _data def csv(uri) : return pd.read(uri).to_html() + def apply(**_args): + """ + :uri uri of the mapping function + :args arguments of the function + """ diff --git a/cms/micro-cms.py b/cms/micro-cms.py deleted file mode 100644 index 0ae013f..0000000 --- a/cms/micro-cms.py +++ /dev/null @@ -1,10 +0,0 @@ -class Project : - @staticmethod - def create (**_args) : - _version = "0.0.1" if "version" not in _args else _args['version'] - _context = "" if 'context' not in _args else _args['context'] - _logo = "logo.png" - _system = {"version":_version,"context":_context,"logo":_logo} - _app = {"port":8084,"debug":True} - pass - diff --git a/index.py b/index.py index d999b51..07ba38b 100644 --- a/index.py +++ b/index.py @@ -25,25 +25,32 @@ def favicon(): @_app.route("/") def _index (): global _config - _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) - return render_template("index.html",**_args) + _args = {} + 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) + _index_page = "index.html" + except Exception as e: + _index_page = "404.html" + pass + + return render_template(_index_page,**_args) @_app.route('/id/') def people(uid): """ This function will implement hardened links that can directly "do something" """ - global _config + global _config return "0",200 -@_app.route('/cms/dialog') +@_app.route('/dialog') def _dialog (): global _config _uri = os.sep.join([_config['layout']['root'],request.headers['uri']]) @@ -63,7 +70,7 @@ def _dialog (): # _html = ( e.render(**_args)) -@_app.route('/cms/page',methods=['POST']) +@_app.route('/page',methods=['POST']) def cms_page(): """ return the content of a folder formatted for a menu @@ -103,6 +110,7 @@ if len(sys.argv) > 1: i += 2 if __name__ == '__main__' : + _path = SYS_ARGS['config'] if 'config' in SYS_ARGS else 'config.json' if os.path.exists(_path): _config = json.loads((open (_path)).read()) diff --git a/templates/404.html b/templates/404.html new file mode 100644 index 0000000..e69de29