From 8e3529d0314c2aa98084b844ba03d934561314c4 Mon Sep 17 00:00:00 2001 From: Dita Aji Pratama Date: Sat, 4 Nov 2023 19:12:11 +0700 Subject: [PATCH] Major pattern update --- config/directory.py | 13 ++----- config/globalvar.py | 38 ++++++++++--------- config/server.py | 16 +++++--- config/template.py | 25 ------------ handler.py | 20 +++------- modules/{user => public}/__init__.py | 0 modules/{user => public}/home.py | 14 +++---- page/public/home.html | 9 +++++ static/template/template.html | 19 ---------- .../basic_bootstrap/html}/footer.html | 0 templates/basic_bootstrap/html/template.html | 20 ++++++++++ .../basic_bootstrap/html}/topnav.html | 0 templates/basic_bootstrap/main.py | 13 +++++++ 13 files changed, 89 insertions(+), 98 deletions(-) delete mode 100644 config/template.py rename modules/{user => public}/__init__.py (100%) rename modules/{user => public}/home.py (72%) create mode 100644 page/public/home.html delete mode 100644 static/template/template.html rename {static/template => templates/basic_bootstrap/html}/footer.html (100%) create mode 100644 templates/basic_bootstrap/html/template.html rename {static/template => templates/basic_bootstrap/html}/topnav.html (100%) mode change 100755 => 100644 create mode 100644 templates/basic_bootstrap/main.py diff --git a/config/directory.py b/config/directory.py index 18a3f70..ab3447d 100644 --- a/config/directory.py +++ b/config/directory.py @@ -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 = { '/' : diff --git a/config/globalvar.py b/config/globalvar.py index 6b1563b..fb6a5c0 100755 --- a/config/globalvar.py +++ b/config/globalvar.py @@ -1,21 +1,25 @@ -# Your global variables GV_base_url = "http://localhost:81" GV_title = "CostaPy" +GV_copyright = "Dita Aji Pratama" -GV_menu_navbar = [ - { - "name":"Home", - "href":"/", - "roles":["guest"] - }, - { - "name":"About", - "href":"#", - "roles":["guest"] - }, - { - "name":"CostaPy Website", - "href":"https://costapy.ditaajipratama.com", - "roles":["guest"] +GV_menu = { + "public": { + "topnav": [ + { + "name":"Home", + "href":"/", + "roles":["guest"] + }, + { + "name":"About", + "href":"#", + "roles":["guest"] + }, + { + "name":"CostaPy Website", + "href":"https://costapy.ditaajipratama.com", + "roles":["guest"] + } + ] } -] +} diff --git a/config/server.py b/config/server.py index c0a11f9..d8a1d1f 100644 --- a/config/server.py +++ b/config/server.py @@ -3,14 +3,18 @@ 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) , - 'server.max_request_body_size' : 800 * 1024 * 1024 , # 800MB; Default 100MB - 'server.socket_timeout' : 60 , # Default 10s - 'response.timeout' : 3600 , # Default 300s + + '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 } diff --git a/config/template.py b/config/template.py deleted file mode 100644 index 1d82e1f..0000000 --- a/config/template.py +++ /dev/null @@ -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 diff --git a/handler.py b/handler.py index 3183794..d6feb05 100755 --- a/handler.py +++ b/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 diff --git a/modules/user/__init__.py b/modules/public/__init__.py similarity index 100% rename from modules/user/__init__.py rename to modules/public/__init__.py diff --git a/modules/user/home.py b/modules/public/home.py similarity index 72% rename from modules/user/home.py rename to modules/public/home.py index d7d3c4f..19983c8 100644 --- a/modules/user/home.py +++ b/modules/public/home.py @@ -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, diff --git a/page/public/home.html b/page/public/home.html new file mode 100644 index 0000000..2ef0f8b --- /dev/null +++ b/page/public/home.html @@ -0,0 +1,9 @@ +
+
+
+

Welcome

+

This is your first pages

+

${greeting}

+
+
+
diff --git a/static/template/template.html b/static/template/template.html deleted file mode 100644 index f5d5932..0000000 --- a/static/template/template.html +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - ${GV_title} - - - - - - ${topnav} -
- ${container} -
- ${footer} - - diff --git a/static/template/footer.html b/templates/basic_bootstrap/html/footer.html similarity index 100% rename from static/template/footer.html rename to templates/basic_bootstrap/html/footer.html diff --git a/templates/basic_bootstrap/html/template.html b/templates/basic_bootstrap/html/template.html new file mode 100644 index 0000000..106b993 --- /dev/null +++ b/templates/basic_bootstrap/html/template.html @@ -0,0 +1,20 @@ + + + + + + + ${GV_title} + + + + + + + ${topnav} +
+ ${container} +
+ ${footer} + + diff --git a/static/template/topnav.html b/templates/basic_bootstrap/html/topnav.html old mode 100755 new mode 100644 similarity index 100% rename from static/template/topnav.html rename to templates/basic_bootstrap/html/topnav.html diff --git a/templates/basic_bootstrap/main.py b/templates/basic_bootstrap/main.py new file mode 100644 index 0000000..ddd4c5c --- /dev/null +++ b/templates/basic_bootstrap/main.py @@ -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