Commit 13b68ba4 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Update to add the node cronjobs.

parent e282794c
""" Controllers for application
"""
from pathlib import Path
PATH_CITATIONS_LOG = "static/cron/citations"
def cronjobs():
"""Display last logs for cron jobs.
"""
# citations
log = f"{request.application}.log"
plog = Path(request.folder, PATH_CITATIONS_LOG, log)
if plog.exists():
data = plog.read_text()
else:
data = "no log for citation cronjob"
return dict(lines=data.split("\n"))
\ No newline at end of file
""" Controllers for cron jobs
"""
import json
from pathlib import Path
from plugin_dbui import JSONEncoder
PATH_CITATIONS_LOG = "static/cron/citations"
def citations():
"""Display last logs of the cron job updating citations table.
"""
log = f"{request.application}.log"
plog = Path(request.folder, PATH_CITATIONS_LOG, log)
if not plog.exists():
return "No log for the cron job updating citations table!!!"
# configure the Ext.data.ArrayStore
lines = plog.read_text().split("\n")
data = [[
T(el[:el.find(":")].replace("\t", "").strip()),
el[el.find(":")+1:].strip()]
for el in lines if ":" in el]
# remove the name of the application
if len(data) > 0:
del data[0]
# improve scan duration
if len(data) > 3 and "." in data[2][1]:
val = data[2][1]
data[2][1] = val[:val.find(".")]
fields = [
{"name": "item", "type": "string"},
{"name": "value", "type": "string"}]
cfg = dict(fields=fields, data=data)
# configure the Ext.grid.Panel
columns = [
{"text": "item", "dataIndex": "item", "flex": 1},
{"text": "value", "dataIndex": "value", "flex": 0.8, "align": "end"}]
return dict(cfg_store=json.dumps(cfg, cls=JSONEncoder),
columns=json.dumps(columns, cls=JSONEncoder))
......@@ -177,6 +177,7 @@
'CPPM': 'CPPM',
'Created By': 'Created By',
'Created On': 'Created On',
'Cron jobs': 'Tâches planifiées',
'Cumulative': 'Cumulé',
'Cumulative sum of publications': 'Somme cumulée des publications',
'Cumulative sum of publications / month': 'Somme cumulée des publications / mois',
......@@ -387,7 +388,6 @@
'Load in the database': 'Chargé dans la base de données',
'Loading failed': 'Echec du chargement',
'Loading...': 'Chargement en cours...',
'log cron jobs': 'journaux des taches planifiées',
'Log In': 'Log In',
'Logged in': 'Logged in',
'Logged out': 'Déconnexion',
......
......@@ -47,6 +47,7 @@ class ViewportUi(object):
nodes = [
ViewportUi.help_node(db, T, session),
ViewportUi.app_node(db, T, session),
ViewportUi.cron_jobs_node(db, T, session),
ViewportUi.wizard_node(db, T, session, virtdb),
ViewportUi.configure_harvester_node(db, T, session),
ViewportUi.configure_list_node(db, T, session),
......@@ -75,7 +76,7 @@ class ViewportUi(object):
@staticmethod
def app_node(db, T, session):
"""To deal with preferences for the application.
"""To deal with preferences for the cronjobs.
Args:
db (pyDAL.DAL): database connection
......@@ -110,14 +111,6 @@ class ViewportUi(object):
add_child(
T("relation user / groups"),
to_grid("auth_membership"))
loader = dict(
autoLoad=True,
renderer="html",
url=URL("application", "cronjobs"))
cronjob_panel = Panel(loader=loader, autoScroll=True)
add_child(T("log cron jobs"), cronjob_panel)
return node
......@@ -207,6 +200,38 @@ class ViewportUi(object):
return node
@staticmethod
def cron_jobs_node(db, T, session):
"""To display logs of admin.
Args:
db (pyDAL.DAL): database connection
T (gluon.languages.translator): language translator
session (gluon.storage.Storage):
Returns:
dbui.Node:
the configuration of a tree node.
"""
node = None
if session.role == ADMIN:
node = Node(T("Cron jobs"))
add_child = node.add_child
loader = dict(
autoLoad=True,
renderer="html",
scripts=True,
url=URL("cronjobs", "citations"))
cronjob_panel = Panel(loader=loader, autoScroll=True)
add_child(T("citations"), cronjob_panel)
return node
@staticmethod
def data_institute_node(db, T, session):
"""To define data for the institute, affiliation_keys, projects
......
{{
mytable = "margin-left: 6%;"
mytd = "text-align: right;"
table = []
for line in lines:
idx = line.find(":")
if line.find("Application") == -1 and idx != -1:
item = line[:idx].replace("\t", "").strip()
table.append( [T(item), TD(line[idx+1:], _style=mytd)])
pass
pass
= H2(T("Last update citations table"), _class="my-h2")
= TABLE(*[TR(*row, _class="dbui-tr") for row in table], _style=mytable)
}}
\ No newline at end of file
{{
#--------------------------------------------------------------------------
#
# The python controller return:
# - cfg_store, the configuration of the Ext.data.Array
# - columns, definition for the grid
#
# prepare the data
# - build unique DIV identifier
# - Title and DIV block
#
#--------------------------------------------------------------------------
#
# unique identifier for the DIV block associated to the grid
#
divgrid = "grid-%s" % id(cfg_store)
#
# The title and the DIV block for the Ext.grid.Panel
#
= H2(T("Last update citations table"), _class="my-h2")
= DIV(_id=divgrid)
}}
<script type="text/javascript">
var cfgStore = {{=XML(cfg_store)}},
columns = {{=XML(columns)}},
divgrid = '{{=divgrid}}',
grid;
//
// check that the Ext JS library is loaded
//
if (typeof Ext === "undefined") {
alert("The javascript library Ext JS is missing !");
}
//
// instantiate the grid with a summary row.
// data can be extracted via the plugin pGridExport
//
grid = Ext.create('Dbui.grid.Panel', {
store: Ext.create('Ext.data.ArrayStore', cfgStore),
columns: columns,
forceFit: true,
hideHeaders: true,
padding: "0 0 0 33",
renderTo: divgrid,
width: 350
});
</script>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment