From 35669526cf5d7e7c5ec7465cdbbcd94b0d8f33f9 Mon Sep 17 00:00:00 2001 From: Dita Aji Pratama Date: Wed, 17 Aug 2022 15:09:08 +0700 Subject: [PATCH] Modules --- modules/__init__.py | 0 modules/api/portal/add.py | 34 +++++++++++++++++++ modules/user/__init__.py | 0 modules/user/home.py | 35 ++++++++++++++++++++ modules/user/portal.py | 69 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 138 insertions(+) create mode 100644 modules/__init__.py create mode 100644 modules/api/portal/add.py create mode 100644 modules/user/__init__.py create mode 100644 modules/user/home.py create mode 100644 modules/user/portal.py diff --git a/modules/__init__.py b/modules/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/modules/api/portal/add.py b/modules/api/portal/add.py new file mode 100644 index 0000000..a2540a0 --- /dev/null +++ b/modules/api/portal/add.py @@ -0,0 +1,34 @@ +import mysql.connector as mariadb +import config.database as database +import config.globalvar as globalvar + +class main: + + def __init__(self): + pass + + def result(self, params): + response = { + "message_action" : "success" , + "message_desc" : "New portal created" , + "message_data" : { + "title" : params['title' ], + "website" : params['website' ], + "logo" : params['logo' ], + "directory" : params['directory' ], + }, + } + if params['logo']: + query = f"INSERT INTO portal VALUES (DEFAULT, '{params['title']}', NULL, '{params['website']}', '{params['logo']}', '{params['directory']}')" + else: + query = f"INSERT INTO portal VALUES (DEFAULT, '{params['title']}', NULL, '{params['website']}', NULL, '{params['directory']}')" + try: + con = mariadb.connect(**database.main_db) + cursor = con.cursor() + cursor.execute(query) + con.close() + except Exception as e: + print(f"Error: {e}") + response["message_action" ] = "failed", + response["message_desc" ] = f"error: {e}" + return response diff --git a/modules/user/__init__.py b/modules/user/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/modules/user/home.py b/modules/user/home.py new file mode 100644 index 0000000..3d5207d --- /dev/null +++ b/modules/user/home.py @@ -0,0 +1,35 @@ +from mako.template import Template +import mysql.connector as mariadb +import config.database as database +import config.globalvar as globalvar + +class main: + + def __init__(self): + pass + + 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' ] + + con = mariadb.connect(**database.main_db) + cursor = con.cursor() + cursor.execute("SELECT id, title, logo FROM portal") + listing_portal = cursor.fetchall() + con.close() + + return Template(interface_template).render( + GV_title = globalvar.GV_title, + GV_base_url = globalvar.GV_base_url, + topnav = Template(topnav).render( + GV_title = globalvar.GV_title, + ), + footer = Template(footer).render(), + container = Template(container).render( + GV_base_url = globalvar.GV_base_url, + listing_portal = listing_portal + ) + ) diff --git a/modules/user/portal.py b/modules/user/portal.py new file mode 100644 index 0000000..92e01c1 --- /dev/null +++ b/modules/user/portal.py @@ -0,0 +1,69 @@ +import cherrypy + +from mako.template import Template +import mysql.connector as mariadb + +import config.database as database +import config.globalvar as globalvar + +import core.melon as melon + +class main: + + def __init__(self): + pass + + 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' ] + + portal_id = params["id"] + + con = mariadb.connect(**database.main_db) + cursor = con.cursor() + cursor.execute(f"SELECT * FROM portal WHERE id = {portal_id} ") + listing_portal = cursor.fetchone() + con.close() + + portal_info = { + 'title' : listing_portal[1], + 'description' : listing_portal[2], + 'website' : listing_portal[3], + 'logo' : listing_portal[4], + 'directory' : listing_portal[5], + } + + storage_available = melon.CheckDir(portal_info['directory']) + checking_status = None + new_file_info = None + + if storage_available: + checking_status = melon.CountCompare(portal_info['directory'], database.main_db, 'video', 'id_portal', portal_id) + + if checking_status == 'new': + new_file_info = melon.NewFileDetector(portal_info['directory'], database.main_db, 'video', 'static/media/thumbs/') + elif checking_status == 'miss': + pass + elif checking_status == 'ok': + pass + else: + pass + + return Template(interface_template).render( + GV_title = globalvar.GV_title, + GV_base_url = globalvar.GV_base_url, + topnav = Template(topnav).render( + GV_title = globalvar.GV_title, + ), + footer = Template(footer).render(), + container = Template(container).render( + GV_base_url = globalvar.GV_base_url, + portal_info = portal_info, + storage_available = storage_available, + checking_status = checking_status, + new_file_info = new_file_info, + ) + )