version 1.143, 2012/02/15 08:08:42
|
version 1.144, 2012/09/03 13:06:11
|
Line 99 def sql_quote(v):
|
Line 99 def sql_quote(v):
|
v=string.join(string.split(v,dkey),quote_dict[dkey]) |
v=string.join(string.split(v,dkey),quote_dict[dkey]) |
return "'%s'" % v |
return "'%s'" % v |
|
|
def showSQLConnectionIDs(self): |
#def showSQLConnectionIDs(self): |
return SQLConnectionIDs(self) |
# return SQLConnectionIDs(self) |
|
|
class Options: |
class Options: |
"""options class""" |
"""options class""" |
Line 126 class ZSQLExtendFolder(Folder,Persistent
|
Line 126 class ZSQLExtendFolder(Folder,Persistent
|
""" |
""" |
meta_type="ZSQLExtendFolder" |
meta_type="ZSQLExtendFolder" |
|
|
|
#primaryKeys={} |
|
#primaryKey= |
|
|
|
def getSQLConnectionIDs(self): |
|
logging.debug(SQLConnectionIDs(self)) |
|
return SQLConnectionIDs(self) |
|
|
|
def getPrimaryKey(self,table=None): |
|
"""returns primary key for the database""" |
|
if table is None: |
|
return getattr(self,'primaryKey','oid') |
|
|
|
|
|
|
|
pks= getattr(self, "primaryKeys",{}) |
|
|
|
k = pks.get(table,None) |
|
|
|
if k is None: |
|
logging.debug("getPrimaryKey: no primary key for table %s stored use standard key %s"%(table,getattr(self,'primaryKey','oid'))) |
|
logging.debug(pks) |
|
return getattr(self,'primaryKey','oid') |
|
|
|
return k |
|
|
|
|
|
def getPrimaryKeysAsString(self): |
|
"""get all keys""" |
|
|
|
if not hasattr(self, 'primaryKeys'): |
|
return "" |
|
|
|
return ";".join(["%s:%s"%val for val in self.primaryKeys.items()]) |
|
|
|
|
def ZSQLQuote(self,str): |
def ZSQLQuote(self,str): |
"""quote str for sql""" |
"""quote str for sql""" |
return sql_quote(str) |
return sql_quote(str) |
Line 163 class ZSQLExtendFolder(Folder,Persistent
|
Line 198 class ZSQLExtendFolder(Folder,Persistent
|
qstr="""alter table %s add %s %s""" |
qstr="""alter table %s add %s %s""" |
self.ZSQLSimpleSearch(qstr%(table,newFieldName,'text')) |
self.ZSQLSimpleSearch(qstr%(table,newFieldName,'text')) |
|
|
qstr="select oid,%s from %s"%(fieldname,table) |
qstr="select %s from %s"%(fieldname,table) |
for result in self.ZSQLSimpleSearch(qstr): |
for result in self.ZSQLSimpleSearch(qstr): |
qstr="update %s set %s = %s where oid = %s" |
qstr="update %s set %s = %s where "+self.getPrimaryKey()+" = %s" |
|
|
self.ZSQLSimpleSearch(qstr%(table,newFieldName,self.ZSQLQuote(normal(getattr(result,fieldname))),result.oid)) |
self.ZSQLSimpleSearch(qstr%(table,newFieldName,self.ZSQLQuote(normal(getattr(result,fieldname))),getattr(result,self.getPrimaryKey))) |
|
|
def importAccessModell(self,configFileName,RESPONSE=None): |
def importAccessModell(self,configFileName,RESPONSE=None): |
"""import tables from access |
"""import tables from access |
Line 479 class ZSQLExtendFolder(Folder,Persistent
|
Line 514 class ZSQLExtendFolder(Folder,Persistent
|
|
|
|
|
index={} |
index={} |
founds=self.ZSQLSimpleSearch("""SELECT %s,oid FROM %s """%(field,table)) |
founds=self.ZSQLSimpleSearch("""SELECT %s FROM %s """%(field,table)) |
|
|
for found in founds: |
for found in founds: |
tmp=getattr(found,field,None) |
tmp=getattr(found,field,None) |
Line 487 class ZSQLExtendFolder(Folder,Persistent
|
Line 522 class ZSQLExtendFolder(Folder,Persistent
|
strings=tmp.split(" ") |
strings=tmp.split(" ") |
for string in strings: |
for string in strings: |
if index.get(string): |
if index.get(string): |
index[string].append(found.oid) |
index[string].append(gettr(found,self.getPrimaryKey())) |
else: |
else: |
index[string]=[found.oid] |
index[string]=[gettr(found,self.getPrimaryKey())] |
RESPONSE.write(string+"\n") |
RESPONSE.write(string+"\n") |
|
|
if not hasattr(self,index_name): |
if not hasattr(self,index_name): |
Line 589 class ZSQLExtendFolder(Folder,Persistent
|
Line 624 class ZSQLExtendFolder(Folder,Persistent
|
return pt() |
return pt() |
|
|
|
|
def changeZSQLExtend(self,label,description,weight=0,connection_id=None,autocommit=None,REQUEST=None,): |
def changeZSQLExtend(self,label,description,primaryKey,primaryKeys="",weight=0,connection_id=None,autocommit=None,REQUEST=None,): |
"""change the Konfiguration""" |
"""change the Konfiguration""" |
self.connection_id=connection_id |
self.connection_id=connection_id |
self.weight=weight |
self.weight=weight |
self.label=label |
self.label=label |
self.description=description |
self.description=description |
self.autocommit = (autocommit == "on") |
self.autocommit = (autocommit == "on") |
|
self.primaryKey=primaryKey |
|
|
|
if primaryKeys.lstrip().rstrip()!="": |
|
|
|
for vals in primaryKeys.split(";"): |
|
splitted=vals.split(":") |
|
if len(splitted)<2: |
|
if REQUEST is not None: |
|
return """<html><body>Wrong Syntax of keystring: %s<br/> %s is not of the form TABLE:key.</body></html>"""%(primaryKeys,vals) |
|
|
|
self.primaryKeys[splitted[0]]=splitted[1] |
|
|
|
|
|
|
|
|
|
|
if REQUEST is not None: |
if REQUEST is not None: |
return self.manage_main(self, REQUEST) |
return self.manage_main(self, REQUEST) |
Line 1244 class ZSQLExtendFolder(Folder,Persistent
|
Line 1294 class ZSQLExtendFolder(Folder,Persistent
|
return True |
return True |
|
|
|
|
def ZSQLFindIndexed(self,tableList=[],qs="",select="oid,*",storename=None,indexedFields=['data_line'],restrictField='id_text',**argv): |
def ZSQLFindIndexed(self,tableList=[],qs="",select="*",storename=None,indexedFields=['data_line'],restrictField='id_text',**argv): |
"""find2""" |
"""find2""" |
|
|
for index in self.ZopeFind(self,obj_ids=indexedFields): |
for index in self.ZopeFind(self,obj_ids=indexedFields): |
Line 1257 class ZSQLExtendFolder(Folder,Persistent
|
Line 1307 class ZSQLExtendFolder(Folder,Persistent
|
search2 = self.ZSQLFind(tableExt=tableList[0],qs=qs,select=select,storename=storename,restrictConnect=(tableList[0]+"."+restrictField,search1),**argv) |
search2 = self.ZSQLFind(tableExt=tableList[0],qs=qs,select=select,storename=storename,restrictConnect=(tableList[0]+"."+restrictField,search1),**argv) |
return search2 |
return search2 |
|
|
def ZSQLFind2(self,qs="",select="oid,*",storename=None,tableList=['cdli_translit','cdli_cat'],restrictField='id_text',**argv): |
def ZSQLFind2(self,qs="",select="*",storename=None,tableList=['cdli_translit','cdli_cat'],restrictField='id_text',**argv): |
"""find2""" |
"""find2""" |
|
|
search1= self.ZSQLFind(qs=qs,select=select,storename=storename,tableExt=tableList[1],restrictField=restrictField,NoQuery='yes',NoLimit='yes',**argv) |
search1= self.ZSQLFind(qs=qs,select=select,storename=storename,tableExt=tableList[1],restrictField=restrictField,NoQuery='yes',NoLimit='yes',**argv) |
Line 1267 class ZSQLExtendFolder(Folder,Persistent
|
Line 1317 class ZSQLExtendFolder(Folder,Persistent
|
|
|
|
|
|
|
def ZSQLFind(self,qs="",select="oid,*",storename="foundCount",tableExt=None,NoQuery=None,NoLimit=None,restrictField=None,restrictConnect=None,filter=None,**argv): |
def ZSQLFind(self,qs="",select="*",storename="foundCount",tableExt=None,NoQuery=None,NoLimit=None,restrictField=None,restrictConnect=None,filter=None,**argv): |
"""search in database""" |
"""search in database""" |
|
|
def delEmpty(list): |
def delEmpty(list): |
Line 1430 class ZSQLExtendFolder(Folder,Persistent
|
Line 1480 class ZSQLExtendFolder(Folder,Persistent
|
debug=None |
debug=None |
|
|
if not select: |
if not select: |
select="oid,*" |
select="*" |
|
|
#check for op |
#check for op |
splitted=qs.split(",") |
splitted=qs.split(",") |
Line 1442 class ZSQLExtendFolder(Folder,Persistent
|
Line 1492 class ZSQLExtendFolder(Folder,Persistent
|
select=restrictField |
select=restrictField |
|
|
|
|
#erster durchgang suche operatoren |
params={} |
for q in splitted: |
for q in splitted: |
|
|
name=re.sub("r'+'"," ",q.split("=")[0].lower()) |
name=re.sub("r'+'"," ",q.split("=")[0].lower()) |
if name=="_debug": |
if name=="_debug": |
debug=True |
debug=True |
Line 1453 class ZSQLExtendFolder(Folder,Persistent
|
Line 1502 class ZSQLExtendFolder(Folder,Persistent
|
value=urllib.unquote(q.split("=",1)[1]) |
value=urllib.unquote(q.split("=",1)[1]) |
except: |
except: |
value="" |
value="" |
|
|
|
params[name]=value |
|
|
|
|
|
|
|
#set table |
|
primaryKey="" |
|
if not tableExt: |
|
table=params.get(iCT+'table') |
|
primaryKey=self.getPrimaryKey(table) |
|
logging.debug("table:"+table) |
|
logging.debug("primkey:"+primaryKey); |
|
|
|
|
|
#erster durchgang suche operatoren |
|
for name,value in params.items(): |
|
|
|
# name=re.sub("r'+'"," ",q.split("=")[0].lower()) |
|
# if name=="_debug": |
|
# debug=True |
|
# |
|
# try: |
|
# value=urllib.unquote(q.split("=",1)[1]) |
|
# except: |
|
# value="" |
#print "Hi",name[0:3],q |
#print "Hi",name[0:3],q |
if name[0:3]==iCT+"op": |
if name[0:3]==iCT+"op": |
op=value |
op=value |
Line 1482 class ZSQLExtendFolder(Folder,Persistent
|
Line 1556 class ZSQLExtendFolder(Folder,Persistent
|
sortfields[field]=value |
sortfields[field]=value |
|
|
#zweiter durchgang analysiere felder |
#zweiter durchgang analysiere felder |
for q in qs.split(","): |
for name,value in params.items(): |
|
|
|
|
|
|
name=re.sub("r'+'"," ",q.split("=")[0].lower()) |
|
|
|
try: |
|
value=urllib.unquote(q.split("=",1)[1]) |
|
|
|
except: |
|
value="" |
|
|
|
|
# |
|
# name=re.sub("r'+'"," ",q.split("=")[0].lower()) |
|
# |
|
# try: |
|
# value=urllib.unquote(q.split("=",1)[1]) |
|
# |
|
# except: |
|
# value="" |
|
# |
punktsplit=name.split(".") #sonderfall feld mit punkten(tabelle.suchFeld.ausgewaehltesFeld,feldinoriginal), d.h. suche in anderer tabelle: |
punktsplit=name.split(".") #sonderfall feld mit punkten(tabelle.suchFeld.ausgewaehltesFeld,feldinoriginal), d.h. suche in anderer tabelle: |
|
|
#analysiere alle anderen faelle |
#analysiere alle anderen faelle |
Line 1614 class ZSQLExtendFolder(Folder,Persistent
|
Line 1688 class ZSQLExtendFolder(Folder,Persistent
|
else: |
else: |
op="ct" |
op="ct" |
namealt=name |
namealt=name |
name="LOWER("+name+")" |
##DW hack 29-8-12 lower(oid) funktioniert nicht, generell muss oid handling noch korrigiert werden. |
|
|
|
|
|
|
|
|
|
if not name==primaryKey: |
|
name="LOWER("+name+")" #immer lower key nicht definiert fuer keys. |
|
else: |
|
op="eq" # bei keys immer eq benutzen |
|
|
|
logging.debug("NAME: %s"%name) |
|
|
if op=="ct": |
if op=="ct": |
tmp=(name+" LIKE "+sql_quote("%"+value+"%")) |
tmp=(name+" LIKE "+sql_quote("%"+value+"%")) |
elif op=="gt": |
elif op=="gt": |
Line 1625 class ZSQLExtendFolder(Folder,Persistent
|
Line 1710 class ZSQLExtendFolder(Folder,Persistent
|
tmp=(name+"="+sql_quote(value)) |
tmp=(name+"="+sql_quote(value)) |
elif op=="bw": |
elif op=="bw": |
tmp=(name+" LIKE "+sql_quote(value+"%")) |
tmp=(name+" LIKE "+sql_quote(value+"%")) |
elif op=="ew": |
#tmp=(name+" LIKE "+sql_quote("%"+value)) |
tmp=(name+" LIKE "+sql_quote("%"+value)) |
|
elif op=="all": |
elif op=="all": |
tmps=[] |
tmps=[] |
for word in value.split(" "): |
for word in value.split(" "): |
Line 1648 class ZSQLExtendFolder(Folder,Persistent
|
Line 1732 class ZSQLExtendFolder(Folder,Persistent
|
|
|
op="all" |
op="all" |
|
|
if (value!='') and ((not tableExt) or (namealt.split('.')[0]==tableExt)): #keine leeren werde und keine auschluss |
if (value!='') and ((not tableExt) or (namealt.split('.')[0]==tableExt)): #keine leeren werte und keine auschluss |
if searchFields.has_key(namealt): |
if searchFields.has_key(namealt): |
searchFields[namealt]+=lopfields.get(name,'OR')+" "+tmp |
searchFields[namealt]+=lopfields.get(name,'OR')+" "+tmp |
searchFieldsOnly[namealt]+=lopfields.get(name,'OR')+" "+value |
searchFieldsOnly[namealt]+=lopfields.get(name,'OR')+" "+value |
Line 2002 class ZSQLBibliography(Folder,ZSQLExtend
|
Line 2086 class ZSQLBibliography(Folder,ZSQLExtend
|
pt.content_type="text/html" |
pt.content_type="text/html" |
return pt() |
return pt() |
|
|
def changeZSQLBibliography(self,tableName,label,description,connection_id=None,REQUEST=None): |
def changeZSQLBibliography(self,tableName,label,description,primaryKey="",primaryKeys="",connection_id=None,REQUEST=None): |
"""change it""" |
"""change it""" |
self.connection_id=connection_id |
self.connection_id=connection_id |
self.tableName=tableName |
self.tableName=tableName |
self.label=label |
self.label=label |
self.description=description |
self.description=description |
|
self.primaryKey=primaryKey |
|
|
|
self.primaryKeys={} |
|
if primaryKeys.lstrip().rstrip()!="": |
|
|
|
for vals in primaryKeys.split(";"): |
|
splitted=vals.split(":") |
|
if len(splitted)<2: |
|
if REQUEST is not None: |
|
return """<html><body>Wrong Syntax of keystring: %s<br/> %s is not of the form TABLE:key.</body></html>"""%(primaryKeys,vals) |
|
|
|
logging.debug(splitted) |
|
self.primaryKeys[splitted[0]]=splitted[1] |
|
|
|
|
|
|
|
|
|
|
|
|
if REQUEST is not None: |
if REQUEST is not None: |
return self.manage_main(self, REQUEST) |
return self.manage_main(self, REQUEST) |
Line 2041 class ZSQLBibliography(Folder,ZSQLExtend
|
Line 2143 class ZSQLBibliography(Folder,ZSQLExtend
|
except: |
except: |
return None |
return None |
|
|
|
|
|
def getMetaDataManager(self): |
|
return self.metadata |
|
|
def findTagsFromMapping(self,referenceType): |
def findTagsFromMapping(self,referenceType): |
"""gib hash mit label -> generic zurueck""" |
"""gib hash mit label -> generic zurueck""" |
self.referencetypes=self.ZopeFind(self.standardMD) |
self.referencetypes=self.ZopeFind(self.getMetaDataManager(),search_sub=1) |
bibdata={} |
bibdata={} |
retdata={} |
retdata={} |
fieldlist=self.standardMD.fieldList |
#fieldlist=self.standardMD.fieldList |
|
|
for referenceTypeF in self.referencetypes: |
for referenceTypeF in self.referencetypes: |
#print referenceType,referenceTypeF[1].title |
#print referenceType,referenceTypeF[1].title |
if referenceTypeF[1].title == referenceType: |
if referenceTypeF[1].title.lower() == referenceType.lower(): |
bibdata[referenceTypeF[1].title]=referenceTypeF[1].fields |
bibdata[referenceTypeF[1].title]=referenceTypeF[1].fields |
bibdata['data']=referenceTypeF[1] |
bibdata['data']=referenceTypeF[1] |
self.fields=bibdata[referenceType] |
self.fields=bibdata[referenceTypeF[1].title] |
for field in fieldlist: |
|
|
|
|
|
|
for field in referenceTypeF[1].getFieldList(): |
if referenceTypeF[1].getValue(field)[0]==None: |
if referenceTypeF[1].getValue(field)[0]==None: |
retdata[field]=field |
retdata[field]=field |
else: |
else: |
retdata[field]=referenceTypeF[1].getValue(field)[0] |
retdata[field]=referenceTypeF[1].getValue(field)[0] |
|
|
return retdata,fieldlist |
return retdata,referenceTypeF[1].getFieldList() |
|
|
def findLabelsFromMapping(self,referenceType): |
def findLabelsFromMapping(self,referenceType): |
"""gib hash mit label -> generic zurueck""" |
"""gib hash mit tagname -> lalbe zurueck""" |
self.referencetypes=self.ZopeFind(self.standardMD) |
|
bibdata={} |
|
retdata={} |
|
fieldlist=self.standardMD.fieldList |
|
|
|
for referenceTypeF in self.referencetypes: |
|
#print referenceType,referenceTypeF[1].title |
|
if referenceTypeF[1].title == referenceType: |
mapping= self.getMetaDataManager().getBibMapping(referenceType) |
bibdata[referenceTypeF[1].title]=referenceTypeF[1].fields |
|
bibdata['data']=referenceTypeF[1] |
|
self.fields=bibdata[referenceType] |
|
|
fields=mapping.getFields() |
|
|
|
|
|
|
|
|
|
fieldlist=fields.keys() |
|
|
|
retdata={} |
for field in fieldlist: |
for field in fieldlist: |
retdata[field]=referenceTypeF[1].getValue(field)[1] |
retdata[field]=fields[field]['label'] |
|
|
|
# self.referencetypes=self.ZopeFind(self.getMetaDataManager(),search_sub=1) |
|
# |
|
# bibdata={} |
|
# retdata={} |
|
# #fieldlist=self.standardMD.fieldList |
|
# logging.debug("XX") |
|
# for referenceTypeF in self.referencetypes: |
|
# #print referenceType,referenceTypeF[1].title |
|
# logging.debug("%s=%s"%(referenceTypeF[1].title,referenceType)) |
|
# if referenceTypeF[1].title.lower() == referenceType.lower(): |
|
# |
|
# bibdata[referenceTypeF[1].title]=referenceTypeF[1].fields |
|
# bibdata['data']=referenceTypeF[1] |
|
# self.fields=bibdata[referenceTypeF[1].title] |
|
# for field in referenceTypeF[1].getFieldList(): |
|
# retdata[field]=referenceTypeF[1].getValue(field)[1] |
|
|
|
|
return retdata,fieldlist |
return retdata,fieldlist |
|
|
|
|
def createRDFTag(self,tag,content,namespace="cdli"): |
def createRDFTag(self,tag,content,namespace="cdli"): |
"""create RDF""" |
"""create RDF""" |
if content: |
if content: |
Line 2174 class ZSQLBibliography(Folder,ZSQLExtend
|
Line 2306 class ZSQLBibliography(Folder,ZSQLExtend
|
|
|
ret="""<?xml version="1.0" ?> |
ret="""<?xml version="1.0" ?> |
<index>""" |
<index>""" |
for found in self.ZSQLSimpleSearch("select oid from %s limit ALL"%self.tableName): |
for found in self.ZSQLSimpleSearch("select % from %s limit ALL"%(self.getPrimaryKey,self.tableName)): |
base_url = self.absolute_url() |
base_url = self.absolute_url() |
if fix_host: |
if fix_host: |
#print "replacing ", http_host, " by ", fix_host |
#print "replacing ", http_host, " by ", fix_host |
base_url = string.replace(base_url, http_host, fix_host, 1) |
base_url = string.replace(base_url, http_host, fix_host, 1) |
|
|
link=base_url+"/"+"record.html?oid=%i"%found.oid |
link=base_url+"/"+"record.html?oid=%i"%getattr(found,self.getPrimaryKey()) |
metalink=base_url+"/"+"getMetaDataXML?oid=%i"%found.oid |
metalink=base_url+"/"+"getMetaDataXML?oid=%i"%getattr(found,self.getPrimaryKey()) |
|
|
ret+="""<resource resourceLink="%s" metaLink="%s"/>\n"""%(link,metalink) |
ret+="""<resource resourceLink="%s" metaLink="%s"/>\n"""%(link,metalink) |
|
|