From 013abc77091ed4144d95dadfad7655fa8c5c80fe Mon Sep 17 00:00:00 2001 From: "Harry (Open ERP)" Date: Wed, 14 Apr 2010 17:19:40 +0530 Subject: [PATCH] [FIX] document: MKCOL bzr revid: hmo@tinyerp.com-20100414114940-jkhi3ds5eskjxhej --- addons/document/nodes.py | 49 ++++++++++++++++++++++++++++++-- addons/document_webdav/dav_fs.py | 40 +++++++------------------- 2 files changed, 57 insertions(+), 32 deletions(-) diff --git a/addons/document/nodes.py b/addons/document/nodes.py index 527fda3f594..b35dd1ed1f2 100644 --- a/addons/document/nodes.py +++ b/addons/document/nodes.py @@ -254,8 +254,8 @@ class node_dir(node_database): pass - def get_data(self,cr): - return '' + #def get_data(self,cr): + # return '' @@ -266,6 +266,26 @@ class node_dir(node_database): def _child_get(self, cr, name = None): return super(node_dir,self)._child_get(cr, name, self.dir_id) + + def create_child_collection(self, cr, objname): + object2 = False + dirobj = self.context._dirobj + uid = self.context.uid + ctx = self.context.context.copy() + ctx.update(self.dctx) + obj = dirobj.browse(cr, uid, self.dir_id) + if obj and (obj.type == 'ressource') and not object2: + raise OSError(1, 'Operation not permited.') + + #objname = uri2[-1] + val = { + 'name': objname, + 'ressource_parent_type_id': obj and obj.ressource_type_id.id or False, + 'ressource_id': object2 and object2.id or False, + 'parent_id' : obj and obj.id or False + } + + return dirobj.create(cr, uid, val) def create_child(self,cr,path,data): @@ -556,6 +576,31 @@ class node_res_obj(node_class): if dirr.type == 'ressource': res.append(node_res_dir(dirr.name, self, self.context, dirr, {'active_id': self.res_id})) return res + + def create_child_collection(self, cr, objname): + dirobj = self.context._dirobj + uid = self.context.uid + ctx = self.context.context.copy() + ctx.update(self.dctx) + res_obj = dirobj.pool.get(self.context.context['res_model']) + + object2 = res_obj.browse(cr, uid, self.context.context['res_id']) or False + + obj = dirobj.browse(cr, uid, self.dir_id) + if obj and (obj.type == 'ressource') and not object2: + raise OSError(1, 'Operation not permited.') + + + val = { + 'name': objname, + 'ressource_parent_type_id': obj and obj.ressource_type_id.id or False, + 'ressource_id': object2 and object2.id or False, + 'parent_id' : False + } + if (obj and (obj.type in ('directory'))) or not object2: + val['parent_id'] = obj and obj.id or False + + return dirobj.create(cr, uid, val) def create_child(self,cr,path,data): """ API function to create a child file object and node diff --git a/addons/document_webdav/dav_fs.py b/addons/document_webdav/dav_fs.py index 41a65c73bfb..36b7313a0fa 100644 --- a/addons/document_webdav/dav_fs.py +++ b/addons/document_webdav/dav_fs.py @@ -68,7 +68,7 @@ class openerp_dav_handler(dav_interface): if uri[-1]=='/':uri=uri[:-1] cr, uid, pool, dbname, uri2 = self.get_cr(uri) if not dbname: - cr.close() + if cr: cr.close() return props node = self.uri2object(cr, uid, pool, uri2) if node: @@ -94,7 +94,7 @@ class openerp_dav_handler(dav_interface): if uri[-1]=='/':uri=uri[:-1] cr, uid, pool, dbname, uri2 = self.get_cr(uri) if not dbname: - cr.close() + if cr: cr.close() raise DAV_NotFound node = self.uri2object(cr, uid, pool, uri2) if not node: @@ -360,40 +360,20 @@ class openerp_dav_handler(dav_interface): if cr: cr.close() def mkcol(self,uri): - """ create a new collection """ + """ create a new collection """ self.parent.log_message('MKCOL: %s' % uri) + uri = self.uri2local(uri)[1:] if uri[-1]=='/':uri=uri[:-1] - parent='/'.join(uri.split('/')[:-1]) - if not parent.startswith(self.baseuri): - parent=self.baseuri + ''.join(parent[1:]) - if not uri.startswith(self.baseuri): - uri=self.baseuri + ''.join(uri[1:]) - - + parent = '/'.join(uri.split('/')[:-1]) + parent = self.baseuri + parent + uri = self.baseuri + uri cr, uid, pool,dbname, uri2 = self.get_cr(uri) if not dbname: raise DAV_Error, 409 node = self.uri2object(cr,uid,pool, uri2[:-1]) - object2 = False - if isinstance(node, node_res_obj): - object2 = node and pool.get(node.context.context['res_model']).browse(cr, uid, node.context.context['res_id']) or False - - obj = node.context._dirobj.browse(cr, uid, node.dir_id) - if obj and (obj.type == 'ressource') and not object2: - raise OSError(1, 'Operation not permited.') - - objname = uri2[-1] - val = { - 'name': objname, - 'ressource_parent_type_id': obj and obj.ressource_type_id.id or False, - 'ressource_id': object2 and object2.id or False, - 'parent_id' : False - } - if (obj and (obj.type in ('directory'))) or not object2: - val['parent_id'] = obj and obj.id or False - - pool.get('document.directory').create(cr, uid, val) - cr.commit() + if node: + node.create_child_collection(cr, uri2[-1]) + cr.commit() cr.close() return True