# HG changeset patch
# User casties
# Date 1282142527 -7200
# Node ID a67b7c1f7ec544cc981e23fb4da297b1b387bc5a
# Parent 67ca17753cd5065b92e739fd5021237fc2f55b5e# Parent 78e70dfa7ad6b27d10d490f9ae8820306e4fe5d4
Merge with Falks GIS stuff 78e70dfa7ad6b27d10d490f9ae8820306e4fe5d4
diff -r 67ca17753cd5 -r a67b7c1f7ec5 RestDbInterface.py
--- a/RestDbInterface.py Wed Aug 18 16:20:25 2010 +0200
+++ b/RestDbInterface.py Wed Aug 18 16:42:07 2010 +0200
@@ -11,6 +11,7 @@
import re
import psycopg2
import json
+import time
from zope.interface import implements
from zope.publisher.interfaces import IPublishTraverse
@@ -171,9 +172,15 @@
"""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))
if type is not None:
@@ -189,6 +196,9 @@
# 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)
# table
return self.showTable(format=format,schema=path[1],table=path[2])
@@ -427,6 +437,185 @@
self.executeSQL(sqlInsert, data, hasResult=False)
return cnt
+
+ # Methods for GoogleMaps creation
+ def showGoogleMap(self,schema='chgis',table='mpdl',id=[],doc=None):
+ logging.debug("showGoogleMap")
+ data = self.getDataForGoogleMap(schema,table,id,doc)
+ kml=self.getKMLname(data=data,table=table)
+ googleMap_page=self.htmlHead()+str(self.getGoogleMapString(kml=kml))
+ return googleMap_page
+
+ 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+"]]>