bug fix: 404 (html), start project template

v3.0
Steve Nyemba 3 days ago
parent fab8cf5b54
commit 001265060f

@ -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()

@ -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"""
<div align="center">
<div class="large-text">Thank you for considering QCMS</div>
@ -119,7 +121,7 @@ def _index (_path,root):
</div>
<div class="border border-round">
<b>QCMS</b> has built-in support for industry standard frameworks
<b>QCMS</b> has built-in support for industry standard frameworks, and open resources
<div style="float:right; width:250px;">
<i class="fa-solid fa-cog fa-spin" style="font-size:125px; color:#ff6500"></i>
<i class="fa-solid fa-cog fa-spin fa-2x" style="margin-top:-20px; margin-left:-20px; font-size:100px; color:#4682B4"></i>
@ -128,6 +130,7 @@ def _index (_path,root):
<i class="fa-solid fa-minus"></i> fontawesome
<br><i class="fa-solid fa-minus"></i> jQuery
<br><i class="fa-solid fa-minus"></i> Apexcharts
<br><i class="fa-solid fa-minus"></i> iconfinder
</ul>
<ul>
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):
</div>
</div>
<p>
<div>
<div style="display:grid; grid-template-columns: auto 50%; gap:20px; width:80%; margin-left:10%;">
<div class="border-round border">
Add custom python functions and provide access as <b>api</b>
<p>
<b><i class="fa-solid fa-code"></i> Available API</b>
<div>
These functions are made available in the manifest
</div>
<ul>
<li><a href="http://localhost:{_system['app']['port']}/api/system/debug">http://localhost:{_system['app']['port']}/api/system/debug</a></li>
<li><a href="http://localhost:{_system['app']['port']}/api/demo/info">http://localhost:{_system['app']['port']}/api/demo/info</a></li>
</ul>
<i class="fa-solid fa-terminal"></i> In a terminal window, list the apis online/offline
<div class="source-code">
$ qcms api status < project-folder >
</div>
</p>
</div>
<div class="border-round border">
Custom API are simple python functions, that are loaded in the <b>_plugins</b> folder
<pre class="source-code" style="font-size:10px">
{_code}
</pre>
</div>
</div>
<div align="center">Learn more about <b>QCMS</b> and at {themes.URL}</div>
</p>
@ -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

@ -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 = "<div align='center'><h2>404</h2></div>"
_mimeType = 'plain/html'
_data = f"<div align='center' style='padding:20%'><div style='font-size:32px; font-weight:bold'>404</div style='font-weight:lighter'><div>{_request.path} Not Found</div></div>"
_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())])

Loading…
Cancel
Save