{{ #-------------------------------------------------------------------------- # The python controller return: # - logs (List of Storage) # - selector (Selector) # - counters (dict of Storage) the key are the project # The storage keys are: found, ok, validated # #-------------------------------------------------------------------------- # # prepare the data # - create URL for id, ids and title # - configure the Ext.data.Array for the statistics # - configure the Ext.data.Array for the logs # - configure the field name for the Ext.form.Panel # - the title of the HTML page # - the DIV blocks # - the HTML page footer # - export python variables to the javascript # #-------------------------------------------------------------------------- import json from datetime import datetime from plugin_dbui import JSONEncoder # # create the URL to compare id and ids # modified the content of the row.title # for row in logs: for i in range(len(row.ids)): url = URL('wizards', 'compare_publications', vars=dict(id1=row.id, id2=row.ids[i])) row.ids[i] = str(A(row.ids[i], _href=url, _target="_blank")) pass pass # # create the URL pointing to the record in the havest store # modified the content of the row.ids # for row in logs: origin = db.publications[row.id].origin if origin: origin = origin.split(",") origin = origin[0].strip() row.title = str(A(row.title, _href=origin, _target="_blank")) pass pass # # create the URL to edit the id # modified the content of the row.id # for row in logs: script = "javascript:Limbra.onGridLogClick(%i)" % row.id row.id = str(A(row.id, _href=script)) pass #......................................................................... # # configure the Ext.data.Array for the statistics # cfg = dict(sorters=['project'], data=[]) cfg['fields'] = [{'name': 'records', 'type': 'int'}, {'name': 'ok', 'type': 'int'}, {'name': 'project', 'type': 'string'}, {'name': 'validated', 'type': 'int'}, {'name': 'error', 'type': 'int'}] for project in counters: counter = counters[project] error = counter.found - counter.ok - counter.validated record = [counter.found, counter.ok, project, counter.validated, error] cfg['data'].append(record) pass cfg_statStore = json.dumps(cfg, cls=JSONEncoder) #......................................................................... # # configure the Ext.data.Array for the logs # cfg = dict(data=[], groupField='txt', sorters=['txt', 'title']) cfg['fields'] = [{'name': 'category', 'type': 'string'}, {'name': 'id', 'type': 'string'}, {'name': 'ids', 'type': 'string'}, {'name': 'project', 'type': 'string'}, {'name': 'title', 'type': 'string'}, {'name': 'txt', 'type': 'string'}, {'name': 'year', 'type': 'int'}] for row in logs: for txt in row.txt: record = [row.category, row.id, ','.join(row.ids), row.project, row.title, txt, row.year] cfg['data'].append(record) pass pass cfg_logsStore = json.dumps(cfg, cls=JSONEncoder) #......................................................................... # # configure the field name for the Ext.form.Panel # # HACK: # simplify the encoding of the field name for the form (TableField → field) # NOTE: for publication fields are organized in tabPanel # FIXME: awfull piece of code. Have to solve it in plugin_dbbui # items = json.loads(publications_fields) for tabPanel in items: for tab in tabPanel['items']: for field in tab['items']['items']: if field['xtype'] == 'fieldcontainer': for el in field['items']: el['name'] = el['name'].replace("Publications", "").lower() pass else: field['name'] = field['name'].replace("Publications", "").lower() pass pass pass pass publications_fields = json.dumps(items, cls=JSONEncoder) #......................................................................... # # the title of the HTML page # period = "" if selector.year: period = selector.year pass team = "" if selector.id_teams: team = db.teams[selector.id_teams].team pass project = "" if selector.id_projects: project = db.projects[selector.id_projects].project pass if team and not project: project = team elif team and project: project = "%s / %s" % (team, project) pass title = "%s %s %s" % (T("Check and validate"), 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 block, one for each grid # divlogs = "grid-%s" % id(cfg_logsStore) divstat = "grid-%s" % id(cfg_statStore) response.write(DIV(_id=divstat)) response.write(DIV(_id=divlogs)) #......................................................................... # # the HTML page footer: processing time of the request # delta = (datetime.now()-request.now).total_seconds() delta = T('Check and validate 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))) }}