{{ #-------------------------------------------------------------------------- # The python controller return: # - collection_logs (list of MsgCollection) one for each collection # - harvester (Storage) # - logs (list of MSg) one for each publication # - selector (Selector) #-------------------------------------------------------------------------- # # prepare the data: # - configure the Ext.data.Array for the statistics # - configure the Ext.data.Array for the logs # - the title of the page # - the DIV block # - the HTML page footer # - export python variable to the javascript # #-------------------------------------------------------------------------- import json from datetime import datetime # # configure the Ext.data.Array for the statistics # transform the collection_logs in a series of counters per collection # cfg = dict(sorters=['collection']) cfg['fields'] = [{'name': 'add', 'type': 'int'}, {'name': 'error', 'type': 'string'}, {'name': 'found', 'type': 'int'}, {'name': 'idle', 'type': 'int'}, {'name': 'lost', 'type': 'int'}, {'name': 'modify', 'type': 'int'}, {'name': 'reject', 'type': 'int'}, {'name': 'title', 'type': 'string'}, {'name': 'url', 'type': 'string'}] cfg['data'] = [] for collection in collection_logs: # count database action for this collection count = Storage(idle=0, load=0, modify=0, process=0, reject=0) for row in logs: if row.collection == collection.title: count.process += 1 count[row.action] += 1 pass pass stat = [count.load, collection.error, collection.found, count.idle, collection.found - count.process, count.modify, count.reject, collection.title, collection.url_hb()] cfg['data'].append(stat) pass cfg_statStore = json.dumps(cfg) # # configure the Ext.data.Array for the logs # cfg = dict(groupField='txt', sorters=['txt', 'title']) cfg['fields'] = [{'name': 'collection', 'type': 'string'}, {'name': 'title', 'type': 'string'}, {'name': 'txt', 'type': 'string'}, {'name': 'url', 'type': 'string'}, {'name': 'year', 'type': 'string'}] cfg['data'] = [] for row in logs: cfg['data'].append([row.collection, row.title, row.txt, row.url, row.year]) pass cfg_logsStore = json.dumps(cfg) # # Write the Title on the HTML page # period = "" if selector.year_start and selector.year_end: period = T("from %s to %s") % (selector.year_start, selector.year_end) elif selector.year_start: period = str(selector.year_start) pass project = "" if selector.id_projects: project = db.projects[selector.id_projects].project pass title = "%s %s %s" % (harvester.controller.title(), project, period) style = ["font-size: 12px;", "font-variant: small-caps;", "margin-left: 10px;", "margin-bottom: 3ex;", "margin-top: 2ex;"] response.write(P(title, _style="".join(style))) # # the DIV blocks, one for each grid # divstat = "grid-%s" % id(cfg_statStore) divlogs = "grid-%s" % id(cfg_logsStore) response.write(DIV(_id=divstat)) response.write(DIV(_id=divlogs)) # # the footer, processing time of the request # delta = (datetime.now()-request.now).total_seconds() delta = T('Harvester took %s seconds') % round(delta, 2) style = ["font-size: 10px;", "margin-left: 10px;", "margin-bottom: 3ex;", "margin-top: 2ex;"] response.write(P(delta, _style="".join(style))) # # Export python variables to the javascript # jsvars = ["cfgStatStore = %s" % cfg_statStore, "cfgLogsStore = %s" % cfg_logsStore, "divstat = '%s'" % divstat, "divlogs = '%s'" % divlogs, "gridStat", "gridLog", "harvester = %s" % json.dumps(harvester.as_dict()), "menu", "trAction = '%s'" % T('Action'), "trAdded = '%s'" % T('Added'), "trCollection = '%s'" % T('Collection'), "trEditAndInsert = '%s'" % T('Edit and insert'), "trError = '%s'" % T('Error'), "trExisting = '%s'" % T('Existing'), "trFound = '%s'" % T('Found'), "trLost = '%s'" % T('Lost'), "trModified = '%s'" % T('Modified'), "trRejected = '%s'" % T('Rejected'), "trTitle = '%s'" % T('Title'), "trStatistics = '%s'" % T('Statistics'), "trYear = '%s'" % T('Year')] jsvars = " var %s;" % ',\n'.join(jsvars) response.write(SCRIPT(jsvars), escape=False) }}