Mercurial > hg > ChinaGisRestApi
changeset 13:e2c73c077533
NEW - # 12: create table and upload data
https://it-dev.mpiwg-berlin.mpg.de/tracs/GIS/ticket/12
ongoing...
author | casties |
---|---|
date | Thu, 12 Aug 2010 20:04:57 +0200 |
parents | 0fa22c291ff1 |
children | 05933707897f |
files | RestDbInterface.py |
diffstat | 1 files changed, 29 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/RestDbInterface.py Thu Aug 12 11:48:09 2010 +0200 +++ b/RestDbInterface.py Thu Aug 12 20:04:57 2010 +0200 @@ -100,9 +100,13 @@ path = request.get('restdb_path', []) logging.debug("publishtraverse: name=%s restdb_path=%s"%(name,path)) - if name == "index_html": + if name in ("index_html", "PUT"): # end of traversal - return self.index_html + if request.get("method") == "POST" and request.get("action",None) == "PUT": + # fake PUT by POST with action=PUT + name = "PUT" + + return getattr(self, name) #TODO: should we check more? else: # traverse @@ -155,9 +159,27 @@ """ Implement WebDAV/HTTP PUT/FTP put method for this object. """ - logging.debug("PUT with REQUEST=%s"%(REQUEST)) + logging.debug("RestDbInterface PUT") + #logging.debug("req=%s"%REQUEST) #self.dav__init(REQUEST, RESPONSE) #self.dav__simpleifhandler(REQUEST, RESPONSE) + # ReST path was stored in request + path = REQUEST.get('restdb_path',[]) + if len(path) == 3: + schema = path[1] + tablename = path[2] + file = REQUEST.get("create_table_file",None) + if file is None: + RESPONSE.setStatus(400) + return + + logging.debug("put with schema=%s table=%s file=%s"%(schema,tablename,file)) + self.createTableFromXML(schema, tablename, file) + + else: + # 400 Bad Request + RESPONSE.setStatus(400) + return def showTable(self,format='XML',schema='public',table=None): @@ -216,6 +238,10 @@ data={'fields': (('schemas',),), 'rows': [('public',),]} return data + def createTableFromXML(self,schema,table,data): + """create or replace a table with the given XML data""" + logging.debug("createTableFromXML schema=%s table=%s data=%s"%(schema,table,data)) + def manage_editRestDbInterface(self, title=None, connection_id=None, REQUEST=None):