Major pattern update

This commit is contained in:
Dita Aji Pratama 2023-11-04 19:12:11 +07:00
parent f6a3d64dd2
commit 8e3529d031
13 changed files with 89 additions and 98 deletions

View File

@ -1,14 +1,9 @@
import os import os
# For a static error pages page = {
def erpadir(err): 'public' :'page/public' ,
return f'static/error/{err}.html' 'error' :'page/error' # Non-template
}
# For templating
page = "static/page"
template = "static/template"
email = "static/email"
# For route # For route
dirconfig = { dirconfig = {
'/' : '/' :

View File

@ -1,21 +1,25 @@
# Your global variables
GV_base_url = "http://localhost:81" GV_base_url = "http://localhost:81"
GV_title = "CostaPy" GV_title = "CostaPy"
GV_copyright = "Dita Aji Pratama"
GV_menu_navbar = [ GV_menu = {
{ "public": {
"name":"Home", "topnav": [
"href":"/", {
"roles":["guest"] "name":"Home",
}, "href":"/",
{ "roles":["guest"]
"name":"About", },
"href":"#", {
"roles":["guest"] "name":"About",
}, "href":"#",
{ "roles":["guest"]
"name":"CostaPy Website", },
"href":"https://costapy.ditaajipratama.com", {
"roles":["guest"] "name":"CostaPy Website",
"href":"https://costapy.ditaajipratama.com",
"roles":["guest"]
}
]
} }
] }

View File

@ -3,14 +3,18 @@ from config import directory
update = { update = {
'server.socket_host' : "hostname" , 'server.socket_host' : "hostname" ,
'server.socket_port' : "port" , 'server.socket_port' : "port" ,
'cors.expose.on' : True , 'cors.expose.on' : True ,
'tools.sessions.on' : True , 'tools.sessions.on' : True ,
'engine.autoreload.on' : False , 'engine.autoreload.on' : False ,
'request.show_tracebacks' : False , 'request.show_tracebacks' : False ,
'error_page.403' : directory.erpadir(403) ,
'error_page.404' : directory.erpadir(404) , 'error_page.403' : f'{directory.page["error"]}/403.html' ,
'error_page.500' : directory.erpadir(500) , 'error_page.404' : f'{directory.page["error"]}/404.html' ,
'server.max_request_body_size' : 800 * 1024 * 1024 , # 800MB; Default 100MB 'error_page.500' : f'{directory.page["error"]}/500.html' ,
'server.socket_timeout' : 60 , # Default 10s
'response.timeout' : 3600 , # Default 300s 'server.max_request_body_size' : 800 * 1024 * 1024 , # 800MB; Default 100MB
'server.socket_timeout' : 60 , # Default 10s
'response.timeout' : 3600 , # Default 300s
} }

View File

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

View File

@ -1,21 +1,13 @@
import cherrypy import cherrypy
import cherrypy_cors
import json import json
import config.directory as directory
import core.authentication as authentication import templates.basic_bootstrap.main as basic_bootstrap
import modules.public.home as public_home
import config.globalvar as globalvar
import config.template as pages
import modules.user.home as user_home
@cherrypy.tools.accept(media="application/json") @cherrypy.tools.accept(media="application/json")
class handler(pages.main): class handler():
def __init__(self):
pages.main.__init__(self)
def index(self, **kwargs): def index(self, **kwargs):
kwargs["params_page"] = pages.main().user("home") kwargs["mako_website"] = basic_bootstrap.main(directory.page["public"], "home")
return user_home.main().html(kwargs) return public_home.main().html(kwargs)
index.exposed = True index.exposed = True

View File

@ -1,5 +1,3 @@
import cherrypy
from mako.template import Template from mako.template import Template
import mysql.connector as mariadb import mysql.connector as mariadb
@ -13,10 +11,10 @@ class main:
def html(self, params): def html(self, params):
interface_template = params["params_page"]['template' ] interface_template = params["mako_website"]['template' ]
topnav = params["params_page"]['topnav' ] topnav = params["mako_website"]['topnav' ]
footer = params["params_page"]['footer' ] footer = params["mako_website"]['footer' ]
container = params["params_page"]['container' ] container = params["mako_website"]['container' ]
name = "World" name = "World"
@ -28,12 +26,12 @@ class main:
GV_base_url = globalvar.GV_base_url, GV_base_url = globalvar.GV_base_url,
topnav = Template(topnav).render( topnav = Template(topnav).render(
GV_title = globalvar.GV_title, GV_title = globalvar.GV_title,
menu = globalvar.GV_menu_navbar, menu = globalvar.GV_menu['public']['topnav'],
user_roles = user_roles, user_roles = user_roles,
active_page = active_page active_page = active_page
), ),
footer = Template(footer).render( footer = Template(footer).render(
copyright_holder = "Dita Aji Pratama", copyright_holder = globalvar.GV_copyright,
), ),
container = Template(container).render( container = Template(container).render(
GV_base_url = globalvar.GV_base_url, GV_base_url = globalvar.GV_base_url,

9
page/public/home.html Normal file
View 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>

View File

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

View 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>

View 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