Mercurial > hg > ChinaGisRestApi
diff RestDbInterface.py @ 254:901c1f745d13
GIS-Links from MPDL-Documents now served by Mappit-Server
author | fknauft |
---|---|
date | Wed, 28 Sep 2011 15:09:14 +0200 |
parents | efd2469d1722 |
children | 3a10287447b1 |
line wrap: on
line diff
--- 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"""