Mercurial > hg > ChinaGisRestApi
changeset 252:efd2469d1722
geometry-column of tables will be displayed as string
author | fknauft |
---|---|
date | Tue, 20 Sep 2011 11:19:35 +0200 |
parents | 477b054e9357 |
children | d6c7bedf4370 |
files | RestDbGisApi.py RestDbInterface.py gis_gui/blocks/tablestructure.js zpt/HTML_schema_table.zpt |
diffstat | 4 files changed, 39 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- 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):
--- 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'):
--- 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({
--- 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 @@ <table tal:attributes="id element_id"> <thead> <tr> - <th tal:repeat="field fields" tal:content="python:field[0]"/> + <th tal:repeat="field fields" tal:content="python:field[0].replace('st_astext','geometry',1)"/> </tr> </thead> <tbody>