From 001265060fc97617ea27bcfd10bf9df54ae435cc Mon Sep 17 00:00:00 2001 From: Steve Nyemba Date: Fri, 31 Oct 2025 16:38:51 -0500 Subject: [PATCH] bug fix: 404 (html), start project template --- bin/qcms | 2 +- cms/engine/project/__init__.py | 63 ++++++++++++++++++++++++---------- cms/sites/__init__.py | 7 ++-- 3 files changed, 50 insertions(+), 22 deletions(-) diff --git a/bin/qcms b/bin/qcms index 531ef9d..5371120 100755 --- a/bin/qcms +++ b/bin/qcms @@ -502,5 +502,5 @@ def handle_theme ( if __name__ == '__main__': cli.add_typer(cli_theme,name="themes",help="manage themes associated with a site") cli.add_typer(cms.cli.auth.cli,name="login",help="manage login (authentication/authorization) to a sites") - cli.add_typer(cms.cli.plugins.cli,name="plugins",help="manage plugins associated with a site") + cli.add_typer(cms.cli.plugins.cli,name="api",help="manage plugins associated with a site") cli() diff --git a/cms/engine/project/__init__.py b/cms/engine/project/__init__.py index 458cdaf..cd29f5f 100644 --- a/cms/engine/project/__init__.py +++ b/cms/engine/project/__init__.py @@ -36,6 +36,18 @@ from cms.engine import themes # _info['layout']['footer'] = [{'text':'Powered by QCMS'}] # return _info +_code = """ +import cms +# +# register this in config.plugins: {"demo":["info"]} + + +@cms.Plugin(mimetype='application/json',methods=['POST','GET']) +def info (**_args): + _request= _args['request'] + _config = _args['config'] + return {"version":_config['system']['version'],'title':_config['layout']['header']['title']}""" + def make_folder (projectFolder, webroot): """ This function creates project folders, inside the project folder is the web root folder @@ -54,18 +66,7 @@ def _icode(_path,_root): This function will generate some default plugins to show the users how plugins work and can be used/written :path location of the project """ - _code = """ -import cms -# -# register this in config.plugins: {"demo":["info"]} - - -@cms.Plugin(mimetype='application/json',methods=['POST','GET']) -def info (**_args): - _request= _args['request'] - _config = _args['config'] - return {"version":_config['system']['version'],'title':_config['layout']['header']['title']} - """ + global _code loc = os.sep.join([_path,_root,'_plugins','demo.py']) f = open(loc,'w') f.write(_code) @@ -89,11 +90,12 @@ def _ilogo (_path): f.close() _index += 1 -def _index (_path,root): +def _index (_path,root,_config): """ Creating a default index.html for the site given the project root location """ import cms + _system = _config['system'] _html = f"""
Thank you for considering QCMS
@@ -119,7 +121,7 @@ def _index (_path,root):
- QCMS has built-in support for industry standard frameworks + QCMS has built-in support for industry standard frameworks, and open resources
@@ -128,6 +130,7 @@ def _index (_path,root): fontawesome
jQuery
Apexcharts +
iconfinder
    As a python/flask enabled framework, there can also be support for the wide range of libraries for various AI/ML projects @@ -136,8 +139,32 @@ def _index (_path,root):

-

- Add custom python functions and provide access as api +
+
+ Add custom python functions and provide access as api +

+ Available API +

+ These functions are made available in the manifest +
+ + + In a terminal window, list the apis online/offline +
+ $ qcms api status < project-folder > +
+

+
+
+ Custom API are simple python functions, that are loaded in the _plugins folder +
                
+                    {_code}
+                
+
+
Learn more about QCMS and at {themes.URL}

@@ -167,7 +194,7 @@ def make (**_args) : This function create a project folder and within the folder are all the elements needed """ _config = _args['config'] - _config['plugins'] = {} + _config['plugins'] = {"demo":["info"]} _folder = _args['folder'] _root = _config['layout']['root'] #-- web root folder make_folder(_folder,_root) #-- creating the project folder structure @@ -176,7 +203,7 @@ def make (**_args) : f.close() _ilogo(os.sep.join([_folder,_root])) #-- adding logo - _index(os.sep.join([_folder,_root]),_root) + _index(os.sep.join([_folder,_root]),_root,_config) _itheme(_folder,_root) #-- adding theme folder _icode(_folder,_root) #-- adding the plugins sample code diff --git a/cms/sites/__init__.py b/cms/sites/__init__.py index f1bdcd4..cfaa448 100644 --- a/cms/sites/__init__.py +++ b/cms/sites/__init__.py @@ -217,7 +217,8 @@ class Initialization (IOConfig): # _icon = f'{_context}/api/cloud/download?doc={_logo}' # else: # _icon = f'{_context}/api/disk/read?uri={_logo}' - _icon = f'{_context}/{_logo}'.replace(_root,'') + # _icon = f'{_context}/{_logo}'.replace(_root,'') + _icon = f'{_context}/{_logo}' if _context else _logo @@ -559,8 +560,8 @@ class Site(Initialization) : return _env.render(**_kwargs) def run(self,_request) : _plugins = self.get('plugins') - _data = "

404

" - _mimeType = 'plain/html' + _data = f"
404
{_request.path} Not Found
" + _mimeType = 'text/html' _code = 404 _key = _request.path[1:] #if self.get('system.context') != '' else _request.path[1:] # print ([_key,_key in list(_plugins.keys())])