Mercurial > hg > ChinaGisRestApi
comparison RestDbInterface.py @ 30:51db9e78bf98
working on field types
| author | casties |
|---|---|
| date | Mon, 30 Aug 2010 17:29:58 +0200 |
| parents | 0b9f8cca6744 |
| children | 6d2055f1b4fa |
comparison
equal
deleted
inserted
replaced
| 29:0b9f8cca6744 | 30:51db9e78bf98 |
|---|---|
| 76 HTML_schema_table = PageTemplateFile('zpt/HTML_schema_table', globals()) | 76 HTML_schema_table = PageTemplateFile('zpt/HTML_schema_table', globals()) |
| 77 JSONHTML_index = PageTemplateFile('zpt/JSONHTML_index', globals()) | 77 JSONHTML_index = PageTemplateFile('zpt/JSONHTML_index', globals()) |
| 78 JSONHTML_schema = PageTemplateFile('zpt/JSONHTML_schema', globals()) | 78 JSONHTML_schema = PageTemplateFile('zpt/JSONHTML_schema', globals()) |
| 79 JSONHTML_schema_table = PageTemplateFile('zpt/JSONHTML_schema_table', globals()) | 79 JSONHTML_schema_table = PageTemplateFile('zpt/JSONHTML_schema_table', globals()) |
| 80 # JSON_* templates are scripts | 80 # JSON_* templates are scripts |
| 81 | 81 def JSON_index(self,data): |
| 82 | 82 """JSON index function""" |
| 83 self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json") | |
| 84 json.dump(data, self.REQUEST.RESPONSE) | |
| 85 | |
| 86 def JSON_schema(self,data,schema): | |
| 87 """JSON index function""" | |
| 88 self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json") | |
| 89 json.dump(data, self.REQUEST.RESPONSE) | |
| 90 | |
| 91 def JSON_schema_table(self,data,tablename): | |
| 92 """JSON index function""" | |
| 93 self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json") | |
| 94 json.dump(data, self.REQUEST.RESPONSE) | |
| 95 | |
| 83 | 96 |
| 84 def __init__(self, id, title, connection_id=None): | 97 def __init__(self, id, title, connection_id=None): |
| 85 """init""" | 98 """init""" |
| 86 self.id = id | 99 self.id = id |
| 87 self.title = title | 100 self.title = title |
| 226 file = REQUEST.get("create_table_file",None) | 239 file = REQUEST.get("create_table_file",None) |
| 227 if file is None: | 240 if file is None: |
| 228 RESPONSE.setStatus(400) | 241 RESPONSE.setStatus(400) |
| 229 return | 242 return |
| 230 | 243 |
| 231 fields = REQUEST.get("create_table_fields",None) | 244 fields = None |
| 232 logging.debug("put with schema=%s table=%s file=%s fields=%s"%(schema,tablename,file,repr(fields))) | 245 fieldsStr = REQUEST.get("create_table_fields",None) |
| 246 logging.debug("put with schema=%s table=%s file=%s fields=%s"%(schema,tablename,file,repr(fieldsStr))) | |
| 247 if fieldsStr is not None: | |
| 248 # unpack fields | |
| 249 fields = [{"name":n, "type": t} for (n,t) in [f.split(":") for f in fieldsStr.split(",")]] | |
| 233 ret = self.createTableFromXML(schema, tablename, file, fields) | 250 ret = self.createTableFromXML(schema, tablename, file, fields) |
| 234 # return the result as JSON | 251 # return the result as JSON |
| 235 format = REQUEST.get("format","JSON") | 252 format = REQUEST.get("format","JSON") |
| 236 if format == "JSON": | 253 if format == "JSON": |
| 237 RESPONSE.setHeader("Content-Type", "application/json") | 254 RESPONSE.setHeader("Content-Type", "application/json") |
| 329 logging.debug("getlistofschemas") | 346 logging.debug("getlistofschemas") |
| 330 # TODO: really look up schemas | 347 # TODO: really look up schemas |
| 331 data={'fields': (('schemas',),), 'rows': [('public',),]} | 348 data={'fields': (('schemas',),), 'rows': [('public',),]} |
| 332 return data | 349 return data |
| 333 | 350 |
| 334 def JSON_index(self,data): | |
| 335 """JSON index function""" | |
| 336 self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json") | |
| 337 json.dump(data, self.REQUEST.RESPONSE) | |
| 338 | |
| 339 def JSON_schema(self,data,schema): | |
| 340 """JSON index function""" | |
| 341 self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json") | |
| 342 json.dump(data, self.REQUEST.RESPONSE) | |
| 343 | |
| 344 def JSON_schema_table(self,data,tablename): | |
| 345 """JSON index function""" | |
| 346 self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json") | |
| 347 json.dump(data, self.REQUEST.RESPONSE) | |
| 348 | |
| 349 def checkTable(self,resultFormat,schema,table,REQUEST=None,RESPONSE=None): | 351 def checkTable(self,resultFormat,schema,table,REQUEST=None,RESPONSE=None): |
| 350 """check the table. | 352 """check the table. |
| 351 returns valid data fields and table name.""" | 353 returns valid data fields and table name.""" |
| 352 if REQUEST is None: | 354 if REQUEST is None: |
| 353 REQUEST = self.REQUEST | 355 REQUEST = self.REQUEST |
