melon/modules/user/portal.py

70 lines
2.0 KiB
Python
Raw Normal View History

2022-08-17 15:09:08 +07:00
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,
)
)