Mercurial > hg > ChinaGisRestApi
comparison RestDbInterface.py @ 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 |
comparison
equal
deleted
inserted
replaced
12:0fa22c291ff1 | 13:e2c73c077533 |
---|---|
98 """change the traversal""" | 98 """change the traversal""" |
99 # get stored path | 99 # get stored path |
100 path = request.get('restdb_path', []) | 100 path = request.get('restdb_path', []) |
101 logging.debug("publishtraverse: name=%s restdb_path=%s"%(name,path)) | 101 logging.debug("publishtraverse: name=%s restdb_path=%s"%(name,path)) |
102 | 102 |
103 if name == "index_html": | 103 if name in ("index_html", "PUT"): |
104 # end of traversal | 104 # end of traversal |
105 return self.index_html | 105 if request.get("method") == "POST" and request.get("action",None) == "PUT": |
106 # fake PUT by POST with action=PUT | |
107 name = "PUT" | |
108 | |
109 return getattr(self, name) | |
106 #TODO: should we check more? | 110 #TODO: should we check more? |
107 else: | 111 else: |
108 # traverse | 112 # traverse |
109 if len(path) == 0: | 113 if len(path) == 0: |
110 # first segment | 114 # first segment |
153 | 157 |
154 def PUT(self, REQUEST, RESPONSE): | 158 def PUT(self, REQUEST, RESPONSE): |
155 """ | 159 """ |
156 Implement WebDAV/HTTP PUT/FTP put method for this object. | 160 Implement WebDAV/HTTP PUT/FTP put method for this object. |
157 """ | 161 """ |
158 logging.debug("PUT with REQUEST=%s"%(REQUEST)) | 162 logging.debug("RestDbInterface PUT") |
163 #logging.debug("req=%s"%REQUEST) | |
159 #self.dav__init(REQUEST, RESPONSE) | 164 #self.dav__init(REQUEST, RESPONSE) |
160 #self.dav__simpleifhandler(REQUEST, RESPONSE) | 165 #self.dav__simpleifhandler(REQUEST, RESPONSE) |
166 # ReST path was stored in request | |
167 path = REQUEST.get('restdb_path',[]) | |
168 if len(path) == 3: | |
169 schema = path[1] | |
170 tablename = path[2] | |
171 file = REQUEST.get("create_table_file",None) | |
172 if file is None: | |
173 RESPONSE.setStatus(400) | |
174 return | |
175 | |
176 logging.debug("put with schema=%s table=%s file=%s"%(schema,tablename,file)) | |
177 self.createTableFromXML(schema, tablename, file) | |
178 | |
179 else: | |
180 # 400 Bad Request | |
181 RESPONSE.setStatus(400) | |
182 return | |
161 | 183 |
162 | 184 |
163 def showTable(self,format='XML',schema='public',table=None): | 185 def showTable(self,format='XML',schema='public',table=None): |
164 """returns PageTemplate with tables""" | 186 """returns PageTemplate with tables""" |
165 logging.debug("showtable") | 187 logging.debug("showtable") |
214 logging.debug("getlistofschemas") | 236 logging.debug("getlistofschemas") |
215 # TODO: really look up schemas | 237 # TODO: really look up schemas |
216 data={'fields': (('schemas',),), 'rows': [('public',),]} | 238 data={'fields': (('schemas',),), 'rows': [('public',),]} |
217 return data | 239 return data |
218 | 240 |
241 def createTableFromXML(self,schema,table,data): | |
242 """create or replace a table with the given XML data""" | |
243 logging.debug("createTableFromXML schema=%s table=%s data=%s"%(schema,table,data)) | |
244 | |
219 | 245 |
220 def manage_editRestDbInterface(self, title=None, connection_id=None, | 246 def manage_editRestDbInterface(self, title=None, connection_id=None, |
221 REQUEST=None): | 247 REQUEST=None): |
222 """Change the object""" | 248 """Change the object""" |
223 if title is not None: | 249 if title is not None: |