# HG changeset patch # User casties # Date 1283438330 -7200 # Node ID c6c47034d2a4903179b80503f6ff0606c2115b32 # Parent 5627175461689daba64064096a7fabbced6f31ef more refactoring of templates gis can be rendered by pagetemplate diff -r 562717546168 -r c6c47034d2a4 RestDbGisApi.py --- 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= ' '%kml +"""\n
\n " \n """ - return printed +# def getGoogleMapString(self,kml): +# logging.debug("getGoogleMapString") +# printed= ' '%kml +"""\n
\n " \n """ +# return printed def getPoint4GISid(self,gis_id): j=0 diff -r 562717546168 -r c6c47034d2a4 RestDbInterface.py --- 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""" diff -r 562717546168 -r c6c47034d2a4 zpt/GIS_schema_table.zpt --- /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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + \ No newline at end of file diff -r 562717546168 -r c6c47034d2a4 zpt/HTML_schema_table.zpt --- 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 @@ + schema options/schema; table options/table; data python:here.getTable(schema=schema,table=table); + fields data/fields; rows data/rows;"> The title diff -r 562717546168 -r c6c47034d2a4 zpt/JSONHTML_schema_table.zpt --- 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 @@ - + The title -

+  

   
 
\ No newline at end of file
diff -r 562717546168 -r c6c47034d2a4 zpt/XML_schema_table.zpt
--- 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 @@
 
 
-  
+  tal:define="schema options/schema; table options/table; data python:here.getTable(schema=schema,table=table);
+    fields data/fields" tal:attributes="name table">
+