Doc Webdav: at PUT, return feedback about created node.

Used in caldav, the final location of the node and its ETag must be
returned after creation.

bzr revid: p_christ@hol.gr-20100812111023-s6dv0g24enfghki9
This commit is contained in:
P. Christeas 2010-08-12 14:10:23 +03:00
parent 71c5192b08
commit 5df0b8cf8c
2 changed files with 36 additions and 6 deletions

View File

@ -522,7 +522,6 @@ class openerp_dav_handler(dav_interface):
def put(self, uri, data, content_type=None):
""" put the object into the filesystem """
self.parent.log_message('Putting %s (%d), %s'%( misc.ustr(uri), data and len(data) or 0, content_type))
parent='/'.join(uri.split('/')[:-1])
cr, uid, pool,dbname, uri2 = self.get_cr(uri)
if not dbname:
if cr: cr.close()
@ -535,20 +534,44 @@ class openerp_dav_handler(dav_interface):
objname = uri2[-1]
ext = objname.find('.') >0 and objname.split('.')[1] or False
ret = None
if not node:
dir_node = self.uri2object(cr, uid, pool, uri2[:-1])
if not dir_node:
cr.close()
raise DAV_NotFound('Parent folder not found')
self._try_function(dir_node.create_child, (cr, objname, data),
newchild = self._try_function(dir_node.create_child, (cr, objname, data),
"create %s" % objname, cr=cr)
if not newchild:
cr.commit()
cr.close()
raise DAV_Error(400, "Failed to create resource")
uparts=urlparse.urlparse(uri)
fileloc = '/'.join(newchild.full_path())
if isinstance(fileloc, unicode):
fileloc = fileloc.encode('utf-8')
# the uri we get is a mangled one, where the davpath has been removed
davpath = self.parent.get_davpath()
surl = '%s://%s' % (uparts[0], uparts[1])
uloc = urllib.quote(fileloc)
hurl = False
if uri != ('/'+uloc) and uri != (surl + '/' + uloc):
hurl = '%s%s/%s/%s' %(surl, davpath, dbname, uloc)
etag = False
try:
etag = str(newchild.get_etag(cr))
except Exception, e:
self.parent.log_error("Cannot get etag for node: %s" % e)
ret = (hurl, etag)
else:
self._try_function(node.set_data, (cr, data), "save %s" % objname, cr=cr)
cr.commit()
cr.close()
return 201
return ret
def rmcol(self,uri):
""" delete a collection """

View File

@ -214,13 +214,20 @@ class DAVHandler(HttpOptions, FixSendError, DAVRequestHandler):
return self.send_status(ec)
headers = {}
etag = None
if location and isinstance(location, tuple):
etag = location[1]
location = location[0]
# note that we have allowed for > 2 elems
if location:
headers['Location'] = location
try:
etag = dc.get_prop(location or uri, "DAV:", "getetag")
headers['ETag'] = etag
except:
if not etag:
etag = dc.get_prop(location or uri, "DAV:", "getetag")
if etag:
headers['ETag'] = str(etag)
except Exception:
pass
self.send_body(None, '201', 'Created', '', headers=headers)