# HG changeset patch # User dwinter # Date 1329993878 -3600 # Node ID d1b43624cc63b829f64cc952540748e15272e389 # Parent 3a5d51c60e40236031c7cc3233b6ecbb143700b8 some hacks to make the european4D connection work diff -r 3a5d51c60e40 -r d1b43624cc63 RestDbGisApi.py --- a/RestDbGisApi.py Fri Jan 27 20:02:41 2012 +0100 +++ b/RestDbGisApi.py Thu Feb 23 11:44:38 2012 +0100 @@ -148,8 +148,9 @@ def getLiveKmlUrl(self,schema,table,useTimestamp=True,REQUEST=None): 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_big"): + def getKmlData(self, schema, table, ids=None, sortBy=1, gisIdField=None, latField=None, lonField=None, geomField="point", colorField="red_big",from_year_name='from_year',until_year_name=''): """returns data structure for KML template""" + logging.debug("getKMLDATA") logging.debug("getKMLdata gid=%s lat=%s lon=%s sortBy=%s geom=%s color=%s"%(gisIdField,latField,lonField,sortBy,geomField,colorField)) if geomField is None: geomField="point" @@ -322,18 +323,24 @@ sql = "SELECT field_name FROM public.gis_table_meta_rows WHERE table_name = %s and gis_type = %s" # from_year and until_year in metadata first try: - res = self.executeSQL(sql, (table,'from_year')) + res = self.executeSQL(sql, (table,from_year_name)) if len(res['rows']) > 0: from_year = res['rows'][0][0] except: from_year = "from_year_dummy" try: - res = self.executeSQL(sql, (table,'until_year')) + res = self.executeSQL(sql, (table,until_year_name)) if len(res['rows']) > 0: until_year = res['rows'][0][0] except: until_year = "until_year_dummy" + + #DW added for testing E4D with names + from_year=from_year_name + until_year=until_year_name + logging.debug("from_year:"+from_year) + logging.debug("until_year:"+until_year) for i in range (len(dataset)): value = dataset[i] @@ -349,6 +356,7 @@ # continue val = "%s: %s"%(name, value) + logging.debug(name) value=unicode(value) if name == from_year: beg_yr= value @@ -616,6 +624,7 @@ return kmlFileName def trydatahas_key(self,data,index,key_string): + logging.debug("trying:"+key_string) try: return data[index].has_key(key_string) except: diff -r 3a5d51c60e40 -r d1b43624cc63 RestDbInterface.py --- a/RestDbInterface.py Fri Jan 27 20:02:41 2012 +0100 +++ b/RestDbInterface.py Thu Feb 23 11:44:38 2012 +0100 @@ -123,9 +123,10 @@ def JSON_schema_table(self,schema,table): """JSON index function""" + logging.debug("start: json_schema") self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json") json.dump(self.getTable(schema, table), self.REQUEST.RESPONSE) - + logging.debug("end: json_schema") def __init__(self, id, title, connection_id=None): """init""" @@ -185,6 +186,16 @@ return map + def getFieldNames(self,fields): + """returns a dict mapping field names to row indexes""" + map = [] + i = 0 + for f in fields: + map.append(f[0]) + + + return map + def executeSQL(self, query, args=None, hasResult=True, autocommit=True): """execute query with args on database and return all results. result format: {"fields":fields, "rows":data}""" @@ -260,6 +271,8 @@ # type and format are real parameter resultFormat = REQUEST.get('format','HTML').upper() queryType = REQUEST.get('type',None) + from_year_name = REQUEST.get('from_year_name',None) + until_year_name = REQUEST.get('until_year_name',None) logging.debug("index_html path=%s resultFormat=%s queryType=%s"%(path,resultFormat,queryType)) @@ -267,7 +280,7 @@ # non-empty queryType -- look for template pt = getattr(self.template, "%s_%s"%(resultFormat,queryType), None) if pt is not None: - return pt(format=resultFormat,type=queryType,path=path) + return pt(format=resultFormat,type=queryType,path=path,from_year_name=from_year_name,until_year_name=until_year_name) if len(path) == 1: # list of schemas @@ -281,8 +294,10 @@ # 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],REQUEST=REQUEST, RESPONSE=RESPONSE) - + logging.debug("index_html:will showTable") + x= self.showTable(format=resultFormat,schema=path[1],table=path[2],REQUEST=REQUEST, RESPONSE=RESPONSE) + logging.debug("index_html:have done showTable") + return x # don't know what to do return str(REQUEST) @@ -351,10 +366,15 @@ # everything else has its own template pt = getattr(self.template, '%s_schema_table'%format, REQUEST) + logging.debug("showtable: gottemplate") if pt is None: return "ERROR!! template %s_schema_table not found at %s"%(format, self.template ) #data = self.getTable(schema,table) - return pt(schema=schema,table=table,args=queryArgs) + logging.debug("table:"+repr(table)) + #x = pt(schema=schema,table=table,args={}) + x = pt(schema=schema,table=table,args=queryArgs) + logging.debug("showtable: executed Table") + return x def getLiveUrl(self,schema,table,useTimestamp=True,REQUEST=None): if REQUEST is None: @@ -381,7 +401,7 @@ attrString="" # try: for name in attrNames['rows']: - logging.debug("name: ", name[0]) + logging.debug("name: "+repr( name[0])) not_added=True if name[0] == "the_geom": #FJK: the table column is "the_geom" attrString=attrString+"ST_AsText("+name[0]+")," @@ -389,9 +409,9 @@ break for a_iter in attrTypes['rows']: not_added = True - logging.debug("attrTypes.field_name: ", a_iter[0]) + logging.debug("attrTypes.field_name: "+ repr(a_iter[0])) if a_iter[0]==name[0]: - logging.debug("attrTypes.gis_type: ", a_iter[1]) + logging.debug("attrTypes.gis_type: "+ repr(a_iter[1])) if a_iter[1] == "the_geom": #FJK: the table column is registered in gis_table_meta_rows as type "the_geom" attrString=attrString+"ST_AsText("+name[0]+")," not_added=False @@ -407,6 +427,7 @@ """ table does not exist """ # fields=self.get # self.createEmptyTable(schema, table, fields) + logging.debug("getTable: done") return data def hasTable(self,schema='public',table=None,username='guest'): diff -r 3a5d51c60e40 -r d1b43624cc63 gis_gui/blocks/table.html.pt --- a/gis_gui/blocks/table.html.pt Fri Jan 27 20:02:41 2012 +0100 +++ b/gis_gui/blocks/table.html.pt Thu Feb 23 11:44:38 2012 +0100 @@ -28,7 +28,11 @@

- + + from data (or date): + to date (if existing): + + diff -r 3a5d51c60e40 -r d1b43624cc63 gis_gui/lib/blocks.js --- a/gis_gui/lib/blocks.js Fri Jan 27 20:02:41 2012 +0100 +++ b/gis_gui/lib/blocks.js Thu Feb 23 11:44:38 2012 +0100 @@ -109,15 +109,29 @@ jQuery.getJSON(url,callback); }; -guiBlocks.prototype.e4DOpen = function(titel,tables){ +guiBlocks.prototype.e4DOpen = function(titel,tablesParam,from_year_name,until_year_name){ var e4D_URL="http://mappit.mpiwg-berlin.mpg.de:8080/e4D?"; - var paramstr = "format=KML"; + var paramstr; + if (until_year_name!='') { + paramstr = "format=KML&from_year_name="+from_year_name+"&until_year_name="+until_year_name; + }else{ + paramstr = "format=KML&from_year_name="+from_year_name + } + // var layer_URL = "http://chinagis-develop.mpiwg-berlin.mpg.de:9080/db/RESTdb/db/public/" + escape(table) + "?" + paramstr; var layer_URL = ""; + var tables; + + if (tablesParam instanceof Array) { + tables=tablesParam; + } else { + tables=new Array(tablesParam); + } for (var i=0;iThe title +

table

- + - - + +
+ +
+ -
+ \ No newline at end of file diff -r 3a5d51c60e40 -r d1b43624cc63 zpt/KML_schema_table.zpt --- a/zpt/KML_schema_table.zpt Fri Jan 27 20:02:41 2012 +0100 +++ b/zpt/KML_schema_table.zpt Thu Feb 23 11:44:38 2012 +0100 @@ -3,8 +3,14 @@ tal:define="gisIdField python:request.get('gis_id_field',None); colorField python:request.get('color_field','red'); latField python:request.get('lat_field',None); lonField python:request.get('lon_field',None); geomField python:request.get('geometry_field','point'); sortBy python:request.get('sort_field',1); ids python:request.get('id'); + from_year_name python:request.get('from_year_name','from_year'); + until_year_name python:request.get('until_year_name','until_year'); schema options/schema; table options/table; - data python:here.getKmlData(schema=schema,table=table,sortBy=sortBy,ids=ids,gisIdField=gisIdField,latField=latField,lonField=lonField,geomField=geomField,colorField=colorField ); + data python:here.getKmlData(schema=schema,table=table, + sortBy=sortBy,ids=ids,gisIdField=gisIdField, + latField=latField,lonField=lonField, + geomField=geomField,colorField=colorField, + from_year_name=from_year_name,until_year_name=until_year_name ); withLine python:request.get('connect_line',None);">