Major pattern update
This commit is contained in:
parent
f6a3d64dd2
commit
8e3529d031
@ -1,14 +1,9 @@
|
||||
import os
|
||||
|
||||
# For a static error pages
|
||||
def erpadir(err):
|
||||
return f'static/error/{err}.html'
|
||||
|
||||
# For templating
|
||||
page = "static/page"
|
||||
template = "static/template"
|
||||
email = "static/email"
|
||||
|
||||
page = {
|
||||
'public' :'page/public' ,
|
||||
'error' :'page/error' # Non-template
|
||||
}
|
||||
# For route
|
||||
dirconfig = {
|
||||
'/' :
|
||||
|
@ -1,8 +1,10 @@
|
||||
# Your global variables
|
||||
GV_base_url = "http://localhost:81"
|
||||
GV_title = "CostaPy"
|
||||
GV_copyright = "Dita Aji Pratama"
|
||||
|
||||
GV_menu_navbar = [
|
||||
GV_menu = {
|
||||
"public": {
|
||||
"topnav": [
|
||||
{
|
||||
"name":"Home",
|
||||
"href":"/",
|
||||
@ -18,4 +20,6 @@ GV_menu_navbar = [
|
||||
"href":"https://costapy.ditaajipratama.com",
|
||||
"roles":["guest"]
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -3,13 +3,17 @@ from config import directory
|
||||
update = {
|
||||
'server.socket_host' : "hostname" ,
|
||||
'server.socket_port' : "port" ,
|
||||
|
||||
'cors.expose.on' : True ,
|
||||
'tools.sessions.on' : True ,
|
||||
|
||||
'engine.autoreload.on' : False ,
|
||||
'request.show_tracebacks' : False ,
|
||||
'error_page.403' : directory.erpadir(403) ,
|
||||
'error_page.404' : directory.erpadir(404) ,
|
||||
'error_page.500' : directory.erpadir(500) ,
|
||||
|
||||
'error_page.403' : f'{directory.page["error"]}/403.html' ,
|
||||
'error_page.404' : f'{directory.page["error"]}/404.html' ,
|
||||
'error_page.500' : f'{directory.page["error"]}/500.html' ,
|
||||
|
||||
'server.max_request_body_size' : 800 * 1024 * 1024 , # 800MB; Default 100MB
|
||||
'server.socket_timeout' : 60 , # Default 10s
|
||||
'response.timeout' : 3600 , # Default 300s
|
||||
|
@ -1,25 +0,0 @@
|
||||
from core import html
|
||||
from config import directory
|
||||
|
||||
class main:
|
||||
|
||||
def __init__(self):
|
||||
# Declare a variables
|
||||
self.html_page = html.main.get_html(directory.page)
|
||||
self.html_template = html.main.get_html(directory.template)
|
||||
self.html_email = html.main.get_html(directory.email)
|
||||
|
||||
def user(self, page):
|
||||
params_list = {
|
||||
"template" : self.html_template ["template.html" ] ,
|
||||
"topnav" : self.html_template ["topnav.html" ] ,
|
||||
"footer" : self.html_template ["footer.html" ] ,
|
||||
"container" : self.html_page [ page+".html" ]
|
||||
}
|
||||
return params_list
|
||||
|
||||
def verification(self):
|
||||
params_list = {
|
||||
"template" : self.html_email ["verification.html" ]
|
||||
}
|
||||
return params_list
|
20
handler.py
20
handler.py
@ -1,21 +1,13 @@
|
||||
import cherrypy
|
||||
import cherrypy_cors
|
||||
import json
|
||||
|
||||
import core.authentication as authentication
|
||||
|
||||
import config.globalvar as globalvar
|
||||
import config.template as pages
|
||||
|
||||
import modules.user.home as user_home
|
||||
import config.directory as directory
|
||||
import templates.basic_bootstrap.main as basic_bootstrap
|
||||
import modules.public.home as public_home
|
||||
|
||||
@cherrypy.tools.accept(media="application/json")
|
||||
class handler(pages.main):
|
||||
|
||||
def __init__(self):
|
||||
pages.main.__init__(self)
|
||||
class handler():
|
||||
|
||||
def index(self, **kwargs):
|
||||
kwargs["params_page"] = pages.main().user("home")
|
||||
return user_home.main().html(kwargs)
|
||||
kwargs["mako_website"] = basic_bootstrap.main(directory.page["public"], "home")
|
||||
return public_home.main().html(kwargs)
|
||||
index.exposed = True
|
||||
|
@ -1,5 +1,3 @@
|
||||
import cherrypy
|
||||
|
||||
from mako.template import Template
|
||||
import mysql.connector as mariadb
|
||||
|
||||
@ -13,10 +11,10 @@ class main:
|
||||
|
||||
def html(self, params):
|
||||
|
||||
interface_template = params["params_page"]['template' ]
|
||||
topnav = params["params_page"]['topnav' ]
|
||||
footer = params["params_page"]['footer' ]
|
||||
container = params["params_page"]['container' ]
|
||||
interface_template = params["mako_website"]['template' ]
|
||||
topnav = params["mako_website"]['topnav' ]
|
||||
footer = params["mako_website"]['footer' ]
|
||||
container = params["mako_website"]['container' ]
|
||||
|
||||
name = "World"
|
||||
|
||||
@ -28,12 +26,12 @@ class main:
|
||||
GV_base_url = globalvar.GV_base_url,
|
||||
topnav = Template(topnav).render(
|
||||
GV_title = globalvar.GV_title,
|
||||
menu = globalvar.GV_menu_navbar,
|
||||
menu = globalvar.GV_menu['public']['topnav'],
|
||||
user_roles = user_roles,
|
||||
active_page = active_page
|
||||
),
|
||||
footer = Template(footer).render(
|
||||
copyright_holder = "Dita Aji Pratama",
|
||||
copyright_holder = globalvar.GV_copyright,
|
||||
),
|
||||
container = Template(container).render(
|
||||
GV_base_url = globalvar.GV_base_url,
|
9
page/public/home.html
Normal file
9
page/public/home.html
Normal file
@ -0,0 +1,9 @@
|
||||
<div class="container-fluid my-3">
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<h1>Welcome</h1>
|
||||
<h3>This is your first pages</h3>
|
||||
<p>${greeting}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@ -1,19 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<title>${GV_title}</title>
|
||||
<link href="${GV_base_url}/lib/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css">
|
||||
<script src="${GV_base_url}/lib/bootstrap/js/bootstrap.bundle.min.js"></script>
|
||||
<link rel="stylesheet" href="${GV_base_url}/css/style.css">
|
||||
</head>
|
||||
<body class="d-flex flex-column" style="min-height:100vh;">
|
||||
${topnav}
|
||||
<div class="mb-5">
|
||||
${container}
|
||||
</div>
|
||||
${footer}
|
||||
</body>
|
||||
</html>
|
20
templates/basic_bootstrap/html/template.html
Normal file
20
templates/basic_bootstrap/html/template.html
Normal file
@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<title>${GV_title}</title>
|
||||
<script src="${GV_base_url}/lib/jquery/jquery-3.7.0.min.js"></script>
|
||||
<link href="${GV_base_url}/lib/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css">
|
||||
<script src="${GV_base_url}/lib/bootstrap/js/bootstrap.bundle.min.js"></script>
|
||||
<link rel="stylesheet" href="${GV_base_url}/css/style.css">
|
||||
</head>
|
||||
<body class="d-flex flex-column" style="min-height:100vh;">
|
||||
${topnav}
|
||||
<div class="mb-5">
|
||||
${container}
|
||||
</div>
|
||||
${footer}
|
||||
</body>
|
||||
</html>
|
0
static/template/topnav.html → templates/basic_bootstrap/html/topnav.html
Executable file → Normal file
0
static/template/topnav.html → templates/basic_bootstrap/html/topnav.html
Executable file → Normal file
13
templates/basic_bootstrap/main.py
Normal file
13
templates/basic_bootstrap/main.py
Normal file
@ -0,0 +1,13 @@
|
||||
from core import html
|
||||
|
||||
def main(dir, page):
|
||||
|
||||
html_template = html.main.get_html("templates/basic_bootstrap/html")
|
||||
html_page = html.main.get_html(dir)
|
||||
params_list = {
|
||||
"template" : html_template ["template.html" ] ,
|
||||
"topnav" : html_template ["topnav.html" ] ,
|
||||
"footer" : html_template ["footer.html" ] ,
|
||||
"container" : html_page [ page+".html" ]
|
||||
}
|
||||
return params_list
|
Loading…
Reference in New Issue
Block a user