Fixes for use dashboard in modules

This commit is contained in:
Antonio de la Rosa 2024-02-09 19:43:34 +01:00
parent 8a0354b85b
commit ff81d2aa8d
3 changed files with 69 additions and 8 deletions

View file

@ -6,7 +6,7 @@ from paramecio2.modules.admin import admin_app, t as admin_t
from paramecio2.libraries.db.coreforms import SelectForm, SelectModelForm, HiddenForm
from paramecio2.libraries.mtemplates import PTemplate, env_theme
from paramecio2.libraries import datetime
from paramecio2.libraries.urls import make_media_url
from paramecio2.libraries.urls import make_media_url, make_url
#from modules.monit.models.monit import Server, ServerData, Alerts
from modules.pastafari2.libraries.scandir import scandir
from paramecio2.libraries.db.webmodel import WebModel
@ -26,6 +26,7 @@ from collections import OrderedDict
from importlib import import_module, reload
from modules.pastafari2.libraries.progress import load_progress
from modules.pastafari2.libraries.load_task import load_db_in_task
from importlib import import_module
try:
import ujson as json
@ -55,17 +56,59 @@ if hasattr(config, 'pastafari_paths'):
@admin_app.route('/pastafari2/dashboard/')
def pastafari2_dashboard():
db=g.connection
config_parser=configparser.ConfigParser()
select_task=scandir(base_path, config_parser, OrderedDict(), 'tasks')
(select_task, select_hash)=scandir(base_path, config_parser, OrderedDict(), {}, 'tasks')
for module in pastafari_paths:
select_task=scandir(module, config_parser, select_task, 'tasks')
(select_task, select_hash)=scandir(module, config_parser, select_task, select_hash, 'tasks')
title_task=''
description_task=''
links=''
path_module='admin_app.pastafari2_dashboard'
task_path=request.args.get('task_path', '')
return t.load_template('dash_pastafari.phtml', title=I18n.lang('pastafari2', 'servers_dashboard', 'Servers Dashboard'), path_module='admin_app.pastafari2_dashboard', select_task=select_task, task_path=task_path)
module=os.getcwd()+'/'+task_path
details_task=[]
#import the module for load links in general dashboard
if os.path.isfile(module) and task_path in select_hash:
final_path=task_path.replace('.py', '').replace('/','.')
#print(final_path)
ptask=import_module(final_path)
if config.reloader:
reload(ptask)
task_first=ptask.ServerTask('', db, remote_user='root', remote_password='', private_key='./ssh/id_rsa', password_key='', remote_path='pastafari2', task_id=0, data=dict(request.args))
links=task_first.links
path_module=task_first.path_module
title_task=' - '+task_first.name_task
description_task=task_first.description_task
details_task=select_hash[task_path]
else:
task_path=''
#print(task_first.links)
#print(module)
return t.load_template('dash_pastafari.phtml', title=I18n.lang('pastafari2', 'servers_dashboard', 'Servers Dashboard')+title_task, path_module=path_module, select_task=select_task, task_path=task_path, links=links, description_task=description_task, details_task=details_task)
@admin_app.route('/pastafari2/settings/')
def pastafari2_settings():