# HG changeset patch
# User fknauft
# Date 1283358241 -7200
# Node ID b915bce653725bd0690605119fc9b3123253e560
# Parent b8922e13e7b59c11bfd81d57862abadff8362348
added kml url option
diff -r b8922e13e7b5 -r b915bce65372 RestDbInterface.py
--- a/RestDbInterface.py Wed Aug 11 15:16:36 2010 +0200
+++ b/RestDbInterface.py Wed Sep 01 18:24:01 2010 +0200
@@ -8,6 +8,7 @@
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from Products.ZSQLExtend import ZSQLExtend
import logging
+import time
from zope.interface import implements
from zope.publisher.interfaces import IPublishTraverse
@@ -53,6 +54,8 @@
self.connection_id = connection_id
# create template folder
self.manage_addFolder('template')
+ # create data folder
+ #self.manage_addFolder('daten')
def getCursor(self):
@@ -127,10 +130,17 @@
"""index method"""
# ReST path was stored in request
path = REQUEST.get('restdb_path',[])
+
# type and format are real parameter
format = REQUEST.get('format','HTML').upper()
type = REQUEST.get('type',None)
+
+ # id and doc are used for GoogleMaps content
+ id = REQUEST.get('id',[])
+ doc = REQUEST.get('doc',None)
+
logging.debug("index_html path=%s format=%s type=%s"%(path,format,type))
+ RESPONSE.setHeader('Access-Control-Allow-Origin', '*')
if type is not None:
# non-empty type -- look for template
@@ -145,6 +155,11 @@
# list of tables
return self.showListOfTables(format=format,schema=path[1])
elif len(path) == 3:
+ # GIS
+ if format=="GIS":
+ return self.showGoogleMap(schema=path[1],table=path[2],id=id,doc=doc)
+ if format=="KML_URL":
+ return self.getKmlUrl(schema=path[1],table=path[2],id=id,doc=doc)
# table
return self.showTable(format=format,schema=path[1],table=path[2])
@@ -208,6 +223,195 @@
data={'fields': (('schemas',),), 'rows': [('public',),]}
return data
+ # Methods for GoogleMaps creation
+ def showGoogleMap(self,schema='chgis',table='mpdl',id=[],doc=None):
+ logging.debug("showGoogleMap")
+ data = self.getDataForGoogleMap(schema,table,id,doc)
+ kmlFileName=self.getKMLname(data=data,table=table)
+ initializeStringForGoogleMaps="""onload=\"initialize(\'http://chinagis.mpiwg-berlin.mpg.de/chinagis/REST/daten/"""+kmlFileName+"""\')\""""#+str(data)
+ initializeStringForGoogleMaps=initializeStringForGoogleMaps.replace("None","0")
+ googleMap_page=self.htmlHead()+str(self.getGoogleMapString(kml=initializeStringForGoogleMaps))
+ return googleMap_page
+
+ def getKmlUrl(self,schema='chgis',table='mpdl',id=[],doc=None):
+ logging.debug("getKmlUrl")
+ data = self.getDataForGoogleMap(schema,table,id,doc)
+ kml=self.getKMLname(data=data,table=table)
+ return """http://chinagis.mpiwg-berlin.mpg.de/chinagis/REST/daten/"""+kml
+
+ def getDataForGoogleMap(self,schema='chgis',table='mpdl',id=[],doc=None):
+ logging.debug("getDataForGoogleMap")
+ qstr="SELECT * FROM "+schema+"."+table
+ try:
+ if id!=[]:
+ qstr=qstr+" WHERE "
+ for id_item in id.split(","):
+ if table=='mpdl':
+ qstr=qstr+" mpdl_xmlsource_id = '"+id_item+ "' OR"
+ else:
+ qstr=qstr+" cast(id as text) LIKE '"+id_item+ "' OR"
+ qstr=str(qstr).rsplit(" ",1)[0] #to remove last " and "
+ data=self.ZSQLSimpleSearch(qstr)
+ return data
+ except:
+ return qstr
+
+ def getKMLname(self,data=[],table=""):
+ logging.debug("getKMLname")
+ #session=context.REQUEST.SESSION
+ kml4Marker="
\n"
+
+ kml4Marker=kml4Marker+"]]>