{{ #-------------------------------------------------------------------------- # 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 # # 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: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']) cfg['fields'] = [{'name': 'records', 'type': 'int'}, {'name': 'ok', 'type': 'int'}, {'name': 'project', 'type': 'string'}, {'name': 'validated', 'type': 'int'}, {'name': 'error', 'type': 'int'}] cfg['data'] = [] for project in counters: counter = counters[project] error = counter.found - counter.ok - counter.validated cfg['data'].append([counter.found, counter.ok, project, counter.validated, error]) pass cfg_statStore = json.dumps(cfg) # # configure the Ext.data.Array for the logs # cfg = dict(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'}] cfg['data'] = [] for row in logs: for txt in row.txt: cfg['data'].append([row.category, row.id, ','.join(row.ids), row.project, row.title, txt, row.year]) pass pass cfg_logsStore = json.dumps(cfg) # # 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) # # 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 = id(cfg_logsStore) divstat = id(cfg_statStore) response.write(DIV(_id="grid-%s" % divstat)) response.write(DIV(_id="grid-%s" % 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))) # # export python variables to the javascript # jsvars = ["cfgLogsStore = %s" % cfg_logsStore, "cfgStatStore = %s" % cfg_statStore, "fields = %s" % publications_fields, "trCategory = '%s'" % T('Category'), "trCollection = '%s'" % T('Collection'), "trDuplicate = '%s'" % T('Duplicate'), "trError = '%s'" % T('Error'), "trId = '%s'" % T('Id'), "trInvalid = '%s'" % T('Invalid'), "trProject = '%s'" % T('Project'), "trRecord = '%s'" % T('Record'), "trRecords = '%s'" % T('Records'), "trStatistics = '%s'" % T('Statistics'), "trStatusOK = '%s'" % T('Status OK'), "trTitle = '%s'" % T('Title'), "trUpdate = '%s'" % T('Update'), "trValidated = '%s'" % T('Validated'), "trYear = '%s'" % T('Year'), "urlRead = '%s'" % URL('publications', 'read'), "urlUpdate = '%s'" % URL('publications', 'update')] jsvars = " var %s;" % ',\n'.join(jsvars) response.write(SCRIPT(jsvars), escape=False) }}