changeset 44:c6c47034d2a4

more refactoring of templates gis can be rendered by pagetemplate
author casties
date Thu, 02 Sep 2010 16:38:50 +0200
parents 562717546168
children ed8db63fab4f
files RestDbGisApi.py RestDbInterface.py zpt/GIS_schema_table.zpt zpt/HTML_schema_table.zpt zpt/JSONHTML_schema_table.zpt zpt/XML_schema_table.zpt
diffstat 6 files changed, 107 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/RestDbGisApi.py	Thu Sep 02 13:17:23 2010 +0200
+++ b/RestDbGisApi.py	Thu Sep 02 16:38:50 2010 +0200
@@ -35,6 +35,14 @@
 
     # data templates
     GIS_schema_table = PageTemplateFile('zpt/GIS_schema_table', globals())
+    # and scripts
+    def KML_URL_schema_table(self,schema,table):
+        """KML_URL table function"""
+        self.REQUEST.RESPONSE.setHeader("Content-Type", "text/plain")
+        id = self.REQUEST.get('id',[])           
+        doc = self.REQUEST.get('doc',None)
+        return self.getKmlUrl(schema=schema,table=table,id=id,doc=doc)
+
 
     def checkTableMetaPermission(self,action,schema,table,user=None):
         """returns if the requested action on the table is allowed"""
@@ -83,25 +91,15 @@
             RESPONSE = self.REQUEST.RESPONSE
             
         RESPONSE.setHeader('Access-Control-Allow-Origin', '*')
-        
-        # GIS gets special treatment
-        if resultFormat=="GIS":
-            id = REQUEST.get('id',[])           
-            doc = REQUEST.get('doc',None)
-            return self.showGoogleMap(schema=schema,table=table,id=id,doc=doc)
-        
-        elif resultFormat=="KML_URL":
-            id = REQUEST.get('id',[])           
-            doc = REQUEST.get('doc',None)
-            return self.getKmlUrl(schema=schema,table=table,id=id,doc=doc)
-
+                
         # everything else has its own template
         pt = getattr(self.template, '%s_schema_table'%resultFormat, None)
         if pt is None:
             return "ERROR!! template %s_schema_table not found"%resultFormat
         
-        data = self.getTable(schema,table)
-        return pt(data=data,tablename=table)
+        #data = self.getTable(schema,table)
+        # templates have to get their own data
+        return pt(schema=schema,table=table)
  
 
     def createEmptyTable(self,schema,table,fields):
@@ -140,14 +138,14 @@
     
 
     # 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 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")
@@ -248,10 +246,10 @@
 
         return kmlFileName
 
-    def getGoogleMapString(self,kml):
-        logging.debug("getGoogleMapString")
-        printed= '<body %s> '%kml +"""\n <div id="map_canvas" style="width: 98%; height: 95%"> </div> \n </body>" \n </html>"""
-        return printed
+#    def getGoogleMapString(self,kml):
+#        logging.debug("getGoogleMapString")
+#        printed= '<body %s> '%kml +"""\n <div id="map_canvas" style="width: 98%; height: 95%"> </div> \n </body>" \n </html>"""
+#        return printed
     
     def getPoint4GISid(self,gis_id):
         j=0
--- a/RestDbInterface.py	Thu Sep 02 13:17:23 2010 +0200
+++ b/RestDbInterface.py	Thu Sep 02 16:38:50 2010 +0200
@@ -97,10 +97,10 @@
         self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json")
         json.dump(data, self.REQUEST.RESPONSE)        
 
-    def JSON_schema_table(self,data,tablename):
+    def JSON_schema_table(self,schema,table):
         """JSON index function"""
         self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json")
-        json.dump(data, self.REQUEST.RESPONSE)        
+        json.dump(self.getTable(schema, table), self.REQUEST.RESPONSE)        
 
     
     def __init__(self, id, title, connection_id=None):
@@ -111,8 +111,12 @@
         self.connection_id = connection_id
         # create template folder
         self.manage_addFolder('template')
+        
 
-
+    def getRestDbUrl(self):
+        """returns url to the RestDb instance"""
+        return self.absolute_url()
+ 
     def getJsonString(self,object):
         """returns a JSON formatted string from object"""
         return json.dumps(object)
@@ -196,7 +200,8 @@
 
         # continue traversing
         return self
- 
+
+
     def index_html(self,REQUEST,RESPONSE):
         """index method"""
         # ReST path was stored in request
@@ -291,8 +296,8 @@
         if pt is None:
             return "ERROR!! template %s_schema_table not found"%resultFormat
         
-        data = self.getTable(schema,table)
-        return pt(data=data,tablename=table)
+        #data = self.getTable(schema,table)
+        return pt(schema=schema,table=table)
  
     def getTable(self,schema='public',table=None,username='guest'):
         """return table data"""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/zpt/GIS_schema_table.zpt	Thu Sep 02 16:38:50 2010 +0200
@@ -0,0 +1,64 @@
+<!DOCTYPE html>
+<html tal:define="root here/getRestDbUrl; layout python:request.get('layout','pre'); element_id python:request.get('element_id',None);
+        schema options/schema; table options/table; id python:request.get('id',[]); doc python:request.get('doc',None);
+        kmlUrl python:here.getKmlUrl(schema=schema,table=table,id=id,doc=doc);
+">
+ <head>
+    <meta http-equiv="content-type" content="text/html; charset=utf-8">
+    <meta http-Equiv="Cache-Control" Content="no-cache">
+    <meta http-Equiv="Pragma" Content="no-cache">
+    <meta http-Equiv="Expires" Content="0">
+  <link rel="stylesheet" type="text/css" tal:attributes="href string:$root/mpiwgstyles.css">
+
+  <style type="text/css">
+    html { height: 100% }
+    body { height: 100%; margin: 0px; padding: 0px }
+    #map_canvas { height: 100% }
+  </style>
+  <style type="text/css">
+     td {height:10; font-size:12;}
+     th {height:10; font-size:12;}
+     b {height:10; font-size:12;}
+     h4 {height:10; font-size:15;}
+  </style>
+    <style type="text/css">
+      .tooltip {
+        background-color:#ffffff;
+        font-weight:bold;
+        border:2px #006699 solid;
+      }
+    </style>
+
+
+   <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
+
+<!--****************
+    Now follow the additional Layers: -->
+
+   <!--  <script type="text/javascript" tal:content="python:here.getFunctionAddLayers()"></script> -->
+
+<!--**************** -->
+
+<!--  <script src="/chinagis/javascript/geoxml.js" type="text/javascript"></script>  
+  <script src="/chinagis/javascript/showSelectedInMap_kml.js" type="text/javascript"></script>
+  <script src="/chinagis/javascript/labeledMarker.js" type="text/javascript"></script>-->
+  <script type="text/javascript">
+   var map = null;
+   function initialize(data) {
+       kmlURL=initialize.arguments[0];
+       map = new google.maps.Map(document.getElementById("map_canvas"));
+       map.setMapTypeId(google.maps.MapTypeId.TERRAIN);
+       var latlng = new google.maps.LatLng(29,116);
+       map.setCenter(latlng); //(LatLng)
+       map.setZoom(5); // (Zoom-Level)
+
+       //geocoder = new google.maps.Geocoder();
+       newMarker=new google.maps.KmlLayer(kmlURL);
+       newMarker.setMap(map);
+    }
+  </script>
+</head>  
+<body tal:attributes="onload string:initialize('$kmlUrl')"> 
+  <div id="map_canvas" style="width: 98%; height: 95%"> </div> 
+</body> 
+</html>
\ No newline at end of file
--- a/zpt/HTML_schema_table.zpt	Thu Sep 02 13:17:23 2010 +0200
+++ b/zpt/HTML_schema_table.zpt	Thu Sep 02 16:38:50 2010 +0200
@@ -1,5 +1,6 @@
 <html tal:define="layout python:request.get('layout','table'); element_id python:request.get('element_id',None); 
-    fields options/data/fields; rows options/data/rows;">
+    schema options/schema; table options/table; data python:here.getTable(schema=schema,table=table);
+    fields data/fields; rows data/rows;">
   <head>
     <meta http-equiv="content-type" content="text/html;charset=utf-8">
     <title tal:content="template/title">The title</title>
--- a/zpt/JSONHTML_schema_table.zpt	Thu Sep 02 13:17:23 2010 +0200
+++ b/zpt/JSONHTML_schema_table.zpt	Thu Sep 02 16:38:50 2010 +0200
@@ -1,9 +1,10 @@
-<html tal:define="layout python:request.get('layout','pre'); element_id python:request.get('element_id',None)">
+<html tal:define="layout python:request.get('layout','pre'); element_id python:request.get('element_id',None)
+    schema options/schema; table options/table; data python:here.getTable(schema=schema,table=table);">
   <head>
     <meta http-equiv="content-type" content="text/html;charset=utf-8">
     <title tal:content="template/title">The title</title>
   </head>
   <body>
-  <pre tal:attributes="id element_id" tal:content="python:here.getJsonString(options['data'])"></pre>
+  <pre tal:attributes="id element_id" tal:content="python:here.getJsonString(data)"></pre>
   </body>
 </html>
\ No newline at end of file
--- a/zpt/XML_schema_table.zpt	Thu Sep 02 13:17:23 2010 +0200
+++ b/zpt/XML_schema_table.zpt	Thu Sep 02 16:38:50 2010 +0200
@@ -1,7 +1,8 @@
 <?xml version="1.0" encoding="utf-8"?>
 <table xmlns:tal="http://xml.zope.org/namespaces/tal" 
-  tal:define="fields options/data/fields" tal:attributes="name options/tablename">
-  <row tal:repeat="row options/data/rows">
+  tal:define="schema options/schema; table options/table; data python:here.getTable(schema=schema,table=table);
+    fields data/fields" tal:attributes="name table">
+  <row tal:repeat="row data/rows">
 	<column tal:repeat="col row" tal:content="python:col" tal:attributes="name python:fields[repeat['col'].index][0]"/>
   </row>
 </table>