changeset 254:901c1f745d13

GIS-Links from MPDL-Documents now served by Mappit-Server
author fknauft
date Wed, 28 Sep 2011 15:09:14 +0200
parents d6c7bedf4370
children ec7b63319fad
files RestDbGisApi.py RestDbInterface.py zpt/GIS_schema_table.zpt zpt/KML_schema_table.zpt
diffstat 4 files changed, 54 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/RestDbGisApi.py	Fri Sep 23 13:11:46 2011 +0200
+++ b/RestDbGisApi.py	Wed Sep 28 15:09:14 2011 +0200
@@ -11,7 +11,6 @@
 import re
 import time
 import datetime
-import urllib
 import urlFunctions
 
 from RestDbInterface import *
@@ -36,13 +35,9 @@
     
     meta_type="RESTgis"
 
-    # data templates
-    GIS_schema_table = PageTemplateFile('zpt/GIS_schema_table', globals())
-    KML_schema_table = PageTemplateFile('zpt/KML_schema_table', globals())
-    HTML_schema_usertables = PageTemplateFile('zpt/HTML_schema_usertables', globals())
     
     # and scripts
-    def KML_URL_schema_table(self,schema,table, useTimestamp=True):
+    def KML_URL_schema_table(self,schema,table, useTimestamp=True, args=None):
         """KML_URL table function"""
         self.REQUEST.RESPONSE.setHeader("Content-Type", "text/plain")
         id = self.REQUEST.get('id',[])           
@@ -150,19 +145,7 @@
     
     
     def getLiveKmlUrl(self,schema,table,useTimestamp=True,REQUEST=None):
-        if REQUEST is None:
-            REQUEST = self.REQUEST
-        logging.debug("getLiveKmlUrl")
-        baseUrl = self.absolute_url()
-        timestamp = time.time()
-        # filter parameters in URL and add to new URL
-        params = [p for p in REQUEST.form.items() if p[0] not in ('format','timestamp')]
-        params.append(('format','KML'))
-        if useTimestamp:
-            # add timestamp so URL changes every time
-            params.append(('timestamp',timestamp))
-        paramstr = urllib.urlencode(params)
-        return "%s/db/%s/%s?%s"%(baseUrl,schema,table,paramstr)
+        return self.getLiveUrl(schema,table,useTimestamp,REQUEST)
 
     def getKmlData(self, schema, table, ids=None, sortBy=1, gisIdField=None, latField=None, lonField=None, geomField="point", colorField="red"):
         """returns data structure for KML template"""
@@ -439,8 +422,10 @@
 
     ## legacy methods...    
 
-    def getKmlUrl(self,schema='chgis',table='mpdl',id=[],doc=None):
+    def getKmlUrl(self,schema='chgis',table='mpdl',args={'doc':None,'id':None}):
         logging.debug("getKmlUrl")
+        id=args.get('id')
+        doc=args.get('doc')
         data = self.getDataForGoogleMap(schema,table,id,doc)
         kml=self.getKMLname(data=data,table=table)
         baseUrl = self.absolute_url()
--- a/RestDbInterface.py	Fri Sep 23 13:11:46 2011 +0200
+++ b/RestDbInterface.py	Wed Sep 28 15:09:14 2011 +0200
@@ -13,6 +13,8 @@
 import json
 import time
 import psycopg2
+import urllib
+
 # make psycopg use unicode objects
 import psycopg2.extensions
 psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
@@ -97,10 +99,18 @@
     HTML_index = PageTemplateFile('zpt/HTML_index', globals())
     HTML_schema = PageTemplateFile('zpt/HTML_schema', globals())
     HTML_schema_table = PageTemplateFile('zpt/HTML_schema_table', globals())
+    GIS_schema_table = PageTemplateFile('zpt/GIS_schema_table', globals())
+    KML_schema_table = PageTemplateFile('zpt/KML_schema_table', globals())
+    HTML_schema_usertables = PageTemplateFile('zpt/HTML_schema_usertables', globals())
+
+    
+    
     JSONHTML_index = PageTemplateFile('zpt/JSONHTML_index', globals())
     JSONHTML_schema = PageTemplateFile('zpt/JSONHTML_schema', globals())
     JSONHTML_schema_table = PageTemplateFile('zpt/JSONHTML_schema_table', globals())
     # JSON_* templates are scripts
+
+
     def JSON_index(self):
         """JSON index function"""
         self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json")
@@ -271,7 +281,7 @@
                 # POST to table to check
                 return self.checkTable(format=resultFormat,schema=path[1],table=path[2])
             # else show table
-            return self.showTable(format=resultFormat,schema=path[1],table=path[2])
+            return self.showTable(format=resultFormat,schema=path[1],table=path[2],REQUEST=REQUEST, RESPONSE=RESPONSE)
         
         # don't know what to do
         return str(REQUEST)
@@ -329,7 +339,10 @@
         logging.debug("showtable")
         if REQUEST is None:
             REQUEST = self.REQUEST
-            
+        queryArgs={'doc':None,'id':None}
+        queryArgs['doc'] = REQUEST.get('doc')
+        queryArgs['id'] = REQUEST.get('id')
+    
         # should be cross-site accessible 
         if RESPONSE is None:
             RESPONSE = self.REQUEST.RESPONSE
@@ -337,12 +350,28 @@
         RESPONSE.setHeader('Access-Control-Allow-Origin', '*')
         
         # everything else has its own template
-        pt = getattr(self.template, '%s_schema_table'%format, None)
+        pt = getattr(self.template, '%s_schema_table'%format, REQUEST)
         if pt is None:
-            return "ERROR!! template %s_schema_table not found"%format
-        
+            return "ERROR!! template %s_schema_table not found at %s"%(format, self.template )
         #data = self.getTable(schema,table)
-        return pt(schema=schema,table=table)
+        return pt(schema=schema,table=table,args=queryArgs)
+
+    def getLiveUrl(self,schema,table,useTimestamp=True,REQUEST=None):
+        if REQUEST is None:
+            REQUEST = self.REQUEST
+        logging.debug("getLiveUrl")
+        baseUrl = self.absolute_url()
+        timestamp = time.time()
+        # filter parameters in URL and add to new URL
+        params = [p for p in REQUEST.form.items() if p[0] not in ('format','timestamp')]
+        params.append(('format','KML'))
+        if useTimestamp:
+            # add timestamp so URL changes every time
+            params.append(('timestamp',timestamp))
+        paramstr = urllib.urlencode(params)
+        return "%s/db/%s/%s?%s"%(baseUrl,schema,table,paramstr)
+
+
  
     def getTable(self,schema='public',table=None,sortBy=1,username='guest'):
         """return table data"""
--- a/zpt/GIS_schema_table.zpt	Fri Sep 23 13:11:46 2011 +0200
+++ b/zpt/GIS_schema_table.zpt	Wed Sep 28 15:09:14 2011 +0200
@@ -1,10 +1,18 @@
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
 <html xmlns="http://www.w3.org/1999/xhtml"
   tal:define="root here/getRestDbUrl;
-        schema options/schema; table options/table; useTimestamp options/useTimestamp;
-        kmlUrl python:here.getLiveKmlUrl(schema=schema,table=table, useTimestamp=useTimestamp);
+        schema options/schema; table options/table;
+        kmlUrl python:here.getLiveUrl(schema=schema,table=table,useTimestamp=False);
 ">
+<!--
+<html xmlns="http://www.w3.org/1999/xhtml"
+  tal:define="root here/getRestDbUrl;
+        schema options/schema; table options/table; args options/args;
+        kmlUrl python:RestDbGisAPI.getKmlUrl(here, schema=schema,table=table, args=args);
+">
+-->
  <head>
     <meta http-equiv="content-type" content="text/html; charset=utf-8">
     <meta http-Equiv="Cache-Control" Content="no-cache">
--- a/zpt/KML_schema_table.zpt	Fri Sep 23 13:11:46 2011 +0200
+++ b/zpt/KML_schema_table.zpt	Wed Sep 28 15:09:14 2011 +0200
@@ -176,11 +176,14 @@
       </PolyStyle>
     </Style>
     <Placemark tal:repeat="place data" tal:condition="python:here.trydatahas_key(data,0,'icon')">
-      <description tal:content="place/description" >
+   <!--
+      <description tal:content="place/description">
       ERD-0815: ERD-0815
       </description>
       <styleUrl tal:content="place/icon" >#marker_icon_red</styleUrl>
       <Point tal:condition="python:place.has_key('icon')">
+     --> 
+      <Point>
         <coordinates tal:content="string:${place/coord_x},${place/coord_y},${place/coord_z}">116.38,39.92,0</coordinates>
       </Point>
     </Placemark>