# HG changeset patch # User fknauft # Date 1316510375 -7200 # Node ID efd2469d172273d014fdf53a59847431a7cd94d7 # Parent 477b054e9357b833c7ab7b0ba3ed79cbea996932 geometry-column of tables will be displayed as string diff -r 477b054e9357 -r efd2469d1722 RestDbGisApi.py --- a/RestDbGisApi.py Mon Sep 19 16:33:02 2011 +0200 +++ b/RestDbGisApi.py Tue Sep 20 11:19:35 2011 +0200 @@ -59,7 +59,8 @@ "id": "text", "gis_id": "text", "coord_lat": "numeric", - "coord_lon": "numeric" + "coord_lon": "numeric", + "the_geom": "the_geom" } def getTableOwner(self,schema,table): diff -r 477b054e9357 -r efd2469d1722 RestDbInterface.py --- a/RestDbInterface.py Mon Sep 19 16:33:02 2011 +0200 +++ b/RestDbInterface.py Tue Sep 20 11:19:35 2011 +0200 @@ -318,7 +318,12 @@ # 400 Bad Request RESPONSE.setStatus(400) return - + def getAttributeNames(self,schema='public',table=None): + return self.executeSQL("SELECT attname FROM pg_attribute, pg_class WHERE pg_class.oid = attrelid AND attnum>0 AND relname = '%s';"%(table)) + + def getAttributeTypes(self,schema='public',table=None): + return self.executeSQL("SELECT field_name, gis_type FROM public.gis_table_meta_rows WHERE table_name = '%s';"%(table)) + def showTable(self,format='XML',schema='public',table=None,REQUEST=None,RESPONSE=None): """returns PageTemplate with tables""" logging.debug("showtable") @@ -342,15 +347,36 @@ def getTable(self,schema='public',table=None,sortBy=1,username='guest'): """return table data""" logging.debug("gettable") - try: - if sortBy: - data = self.executeSQL('select * from "%s"."%s" order by %s'%(schema,table,sortBy)) - else: - data = self.executeSQL('select * from "%s"."%s"'%(schema,table)) - except: + attrNames=self.getAttributeNames(schema,table) + attrTypes=self.getAttributeTypes(schema,table) + attrString="" + # try: + for name in attrNames['rows']: + logging.debug("name: ", name[0]) + not_added=True + if name[0] == "the_geom": #FJK: the table column is "the_geom" + attrString=attrString+"ST_AsText("+name[0]+")," + not_added=False + break + for a_iter in attrTypes['rows']: + not_added = True + logging.debug("attrTypes.field_name: ", a_iter[0]) + if a_iter[0]==name[0]: + logging.debug("attrTypes.gis_type: ", 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 + if not_added: + attrString=attrString+name[0]+"," + attrString=str(attrString).rsplit(",",1)[0] #to remove last "," + if sortBy: + data = self.executeSQL('select %s from "%s"."%s" order by %s'%(attrString,schema,table,sortBy)) + else: + data = self.executeSQL('select %s from "%s"."%s"'%(attrString,schema,table)) + # except: """ table does not exist """ - fields=self.get - self.createEmptyTable(schema, table, fields) + # fields=self.get + # self.createEmptyTable(schema, table, fields) return data def hasTable(self,schema='public',table=None,username='guest'): diff -r 477b054e9357 -r efd2469d1722 gis_gui/blocks/tablestructure.js --- a/gis_gui/blocks/tablestructure.js Mon Sep 19 16:33:02 2011 +0200 +++ b/gis_gui/blocks/tablestructure.js Tue Sep 20 11:19:35 2011 +0200 @@ -27,7 +27,7 @@ var row = []; for (var i = 0; i < fields.length; i++) { colheads.push({'sTitle': fields[i].name}); - row.push(getHtmlSelectFromList(['text','number','gis_id','coord_lat','coord_lon','id'],fields[i].type,'class="type_'+fields[i].name+'"')); + row.push(getHtmlSelectFromList(['text','number','gis_id','coord_lat','coord_lon','the_geom','id'],fields[i].type,'class="type_'+fields[i].name+'"')); } // Add DataTables functionality $(tbl).dataTable({ diff -r 477b054e9357 -r efd2469d1722 zpt/HTML_schema_table.zpt --- a/zpt/HTML_schema_table.zpt Mon Sep 19 16:33:02 2011 +0200 +++ b/zpt/HTML_schema_table.zpt Tue Sep 20 11:19:35 2011 +0200 @@ -14,7 +14,7 @@ -
+