#!C:\Python25\python.exe # -*- coding: UTF-8 -*- ''' $RCSfile: editor_mapping.py,v $ $Revision$ $Author: markus $ $Date$ The BioCASE querytool ''' import os, sys # ***** include the biocase.lib directory in the python sys path for importing ***** execfile( os.path.abspath( os.path.join( os.path.dirname( __file__ ), os.pardir, os.pardir, 'lib', 'biocase', 'adjustpath.py' ) )) execfile( os.path.abspath( os.path.join( os.path.dirname( __file__ ), os.pardir, os.pardir, 'lib', 'biocase', 'appinit.py' ) )) from biocase.configtool.general import * from biocase.wrapper.cmf_base import CMFClass ############################################################################################################ # # MAIN # #=========================================================================================================== # check datasource availablility if dsaObj is None: execfile( os.path.abspath( os.path.join( os.path.dirname( __file__ ), 'main.cgi' ) )) sys.exit() # # get psfObj # psfObj = dsaObj.getPSFObj(tmp=False) # # CAN WE USE THE DB METADATA RETRIEVAL? defines the template to be used # dbmodObj = dsaObj.getDbmodObj() # load template tmpl = PageMacro('Content', PageMacro.DELMODE) tmpl.load('Content', os.path.join(templateDir, '_mapeditor.html')) # # READ CMF OBJ # cmfObj = CMFClass() cmFile = os.path.join( dsaObj.getDsaDir(), schema ) # read preferrably pickled tmp file readTmpCmFile(cmfObj, cmFile, psfObj) # output data lists for 5 fields lit =['','','','',''] alias =['','','','',''] attr =['','','','',''] dtyp =['','','','',''] # # do we edit data? then read cmf object mapPos = int(form.getfirst('map_pos',-1)) # get concept xpath = form.getfirst('concept',None) if mapPos >= 0: # edit data # get mapping list mapList = cmfObj.getMappingsByConcept(xpath) # get right mapping mapObj = mapList[mapPos-1] i = 0 a = mapObj.getItems() for item in a: if type(item) == InstanceType: alias[i] = item.table attr[i] = item.attr dtyp[i] = item.type else: lit[i] = item i += 1 # # DISPLAY: fill template # # CMF read only data tmpl['concept'] = xpath #check if metadata is available dbMeta = "false" if dbmodObj.hasMetaInfo(): dbMeta = "true" tmpl["dbMeta"] = dbMeta message = [''] errTables = [_t.lower() for _t in dbmodObj.verifyTables([str(ta.table) for ta in psfObj.getTableAliasList()])] for et in errTables: for ta in psfObj.getTableAliasList(): if ta.table == et: message.append("Warning: Table '" + str(et) + "', alias '" + str(ta.alias) + "' does not exist in database.") tmpl["message"] = string.join(message, "
") if dbMeta == "true": columns = "{" for ta in psfObj.getTableAliasList(): if not ta.table.lower() in errTables: columns += '"' + str(ta.alias) + '": {' for c in dbmodObj.getColumns(ta.table): columns += '"' + c + '":"' + c + '", ' columns = columns[:-2] + "}, " else: if mapPos >= 0: _c = [] mapList = cmfObj.getMappingsByConcept(xpath) mapObj = mapList[mapPos-1] a = mapObj.getItems() for item in a: #log.error(item.table) if type(item) == InstanceType and item.table.lower() == ta.alias.lower(): _c.append(item.attr) if len(_c) > 0: columns += '"' + str(ta.alias) + '": {' for c in _c: columns += '"' + c + '":"' + c + '", ' columns = columns[:-2] + "}, " columns = columns[:-2] + "}" else: columns = "null" tmpl["columns"] = columns # # loop through 5 fields # selectedColumns="{" for fieldNr in [1,2,3,4,5]: selectedColumns += '"pos' + str(fieldNr) + '":"' + attr[fieldNr-1] + '",' # alias drop downs default = alias[fieldNr-1] if len(default) < 1: default = '--select--' dropDown = getDropDownOptionHtml(dict([('--select--','--select--')]+[(ta.alias,ta.alias) for ta in psfObj.getTableAliasList()]), default) tmpl['dba%i_alias'%fieldNr] = dropDown #tmpl['dba%i_alias'%fieldNr] = alias[fieldNr-1] # attribute tmpl['dba%i_attr'%fieldNr] = attr[fieldNr-1] # data type drop downs default = dtyp[fieldNr-1] if len(default) < 1: default = 'text' dropDown = getDropDownOptionHtml(dict([('text','text'),('int','int'),('date','date'),('float','float')]), default) tmpl['dba%i_type'%fieldNr] = dropDown #tmpl['dba%i_type'%fieldNr] = dtyp[fieldNr-1] # literal tmpl['lit%i'%fieldNr] = lit[fieldNr-1] selectedColumns = selectedColumns[:-1] + "}" tmpl["selectedColumns"] = selectedColumns # # print HTML ! # printOverHTTP( tmpl )