summaryrefslogtreecommitdiff
path: root/addons/document
diff options
context:
space:
mode:
authorHarry (Open ERP) <hmo@tinyerp.com>2009-12-15 16:18:10 +0530
committerHarry (Open ERP) <hmo@tinyerp.com>2009-12-15 16:18:10 +0530
commit7c11b0e8fed2ff9ac716557eb352f661faa4fa09 (patch)
tree472ff48b836cc2d14cc300f368d01f7611c21ab1 /addons/document
parent4a6d0a4a5112de7c89e8fe468f5ea0470ab01acf (diff)
[FIX+IMP] document: fixed problem on rename file and directory of sub-directory of ressource directory
bzr revid: hmo@tinyerp.com-20091215104810-vi711k1ny28a55uc
Diffstat (limited to 'addons/document')
-rw-r--r--addons/document/document_directory.py1
-rw-r--r--addons/document/ftpserver/abstracted_fs.py62
-rw-r--r--addons/document/nodes.py90
3 files changed, 81 insertions, 72 deletions
diff --git a/addons/document/document_directory.py b/addons/document/document_directory.py
index 1f95fd6a61a..d4232caadb2 100644
--- a/addons/document/document_directory.py
+++ b/addons/document/document_directory.py
@@ -27,6 +27,7 @@ import urlparse
import os
import nodes
+from tools.translate import _
class document_directory(osv.osv):
_name = 'document.directory'
diff --git a/addons/document/ftpserver/abstracted_fs.py b/addons/document/ftpserver/abstracted_fs.py
index 017ef584d51..0073b26b9f2 100644
--- a/addons/document/ftpserver/abstracted_fs.py
+++ b/addons/document/ftpserver/abstracted_fs.py
@@ -189,13 +189,13 @@ class abstracted_fs:
# Ok
def ftp2fs(self, path_orig, data):
- path = self.ftpnorm(path_orig)
+ path = self.ftpnorm(path_orig)
if not data or (path and path=='/'):
return None
path2 = filter(None,path.split('/'))[1:]
(cr, uid, pool) = data
if len(path2):
- path2[-1]=_to_unicode(path2[-1])
+ path2[-1]=_to_unicode(path2[-1])
res = pool.get('document.directory').get_object(cr, uid, path2[:])
if not res:
raise OSError(2, 'Not such file or directory.')
@@ -209,7 +209,7 @@ class abstracted_fs:
res = res.replace("\\", "/")
while res[:2] == '//':
res = res[1:]
- res='/' + node.context.dbname + '/' + _to_decode(res)
+ res = '/' + node.context.dbname + '/' + _to_decode(res)
#res = node and ('/' + node.cr.dbname + '/' + _to_decode(self.ftpnorm(node.path))) or '/'
return res
@@ -403,11 +403,11 @@ class abstracted_fs:
val = {
'name': basename,
'ressource_parent_type_id': obj and obj.ressource_type_id.id or False,
- 'ressource_id': object2 and object2.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
- val['parent_id'] = node.dir_id
+ if (obj and (obj.type in ('directory'))) or not object2:
+ val['parent_id'] = obj and obj.id or False
# Check if it alreayd exists !
pool.get('document.directory').create(cr, uid, val)
cr.commit()
@@ -523,8 +523,7 @@ class abstracted_fs:
try:
dst_basename = _to_unicode(dst_basename)
cr = pooler.get_db(src.context.dbname).cursor()
- uid = src.context.uid
-
+ uid = src.context.uid
if src.type == 'collection':
obj2 = False
dst_obj2 = False
@@ -534,40 +533,39 @@ class abstracted_fs:
obj = src.context._dirobj.browse(cr, uid, src.dir_id)
if isinstance(dst_basedir, node_res_obj):
dst_obj2 = dst_basedir and pool.get(dst_basedir.context.context['res_model']).browse(cr, uid, dst_basedir.context.context['res_id']) or False
- dst_obj = dst_basedir.context._dirobj.browse(cr, uid, dst_basedir.dir_id)
+ dst_obj = dst_basedir.context._dirobj.browse(cr, uid, dst_basedir.dir_id)
if obj._table_name <> 'document.directory':
raise OSError(1, 'Operation not permited.')
result = {
'directory': [],
'attachment': []
}
- # Compute all childs to set the new ressource ID
+ # Compute all childs to set the new ressource ID
child_ids = [src]
while len(child_ids):
node = child_ids.pop(0)
- child_ids += node.children(cr)
- object2 = node and hasattr(node, "res_model") and node.res_model or False
- object = node.context._dirobj.browse(cr, uid, node.dir_id)
+ child_ids += node.children(cr)
if node.type == 'collection':
+ 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
+ object = node.context._dirobj.browse(cr, uid, node.dir_id)
result['directory'].append(object.id)
if (not object.ressource_id) and object2:
raise OSError(1, 'Operation not permited.')
elif node.type == 'file':
result['attachment'].append(object.id)
-
if obj2 and not obj.ressource_id:
raise OSError(1, 'Operation not permited.')
- val = {
- 'name':dst_basename,
- }
+
if (dst_obj and (dst_obj.type in ('directory'))) or not dst_obj2:
- val['parent_id'] = dst_obj and dst_obj.id or False
+ parent_id = dst_obj and dst_obj.id or False
else:
- val['parent_id'] = False
- res = pool.get('document.directory').write(cr, uid, [obj.id], val)
-
- if dst_obj2:
+ parent_id = False
+
+
+ if dst_obj2:
ressource_type_id = pool.get('ir.model').search(cr, uid, [('model','=',dst_obj2._name)])[0]
ressource_id = dst_obj2.id
title = dst_obj2.name
@@ -575,17 +573,18 @@ class abstracted_fs:
if dst_obj2._name == 'res.partner':
partner_id = dst_obj2.id
else:
- partner_id= pool.get(dst_obj2._name).fields_get(cr, uid, ['partner_id']) and dst_obj2.partner_id.id or False
+ partner_id = pool.get(dst_obj2._name).fields_get(cr, uid, ['partner_id']) and dst_obj2.partner_id.id or False
else:
ressource_type_id = False
ressource_id = False
ressource_model = False
partner_id = False
- title = False
-
+ title = False
pool.get('document.directory').write(cr, uid, result['directory'], {
+ 'name' : dst_basename,
'ressource_id': ressource_id,
- 'ressource_type_id': ressource_type_id
+ 'ressource_parent_type_id': ressource_type_id,
+ 'parent_id' : parent_id
})
val = {
'res_id': ressource_id,
@@ -598,12 +597,13 @@ class abstracted_fs:
cr.execute('update ir_attachment set res_id=NULL where id in ('+','.join(map(str,result['attachment']))+')')
cr.commit()
+
elif src.type == 'file':
pool = pooler.get_pool(src.context.dbname)
obj = pool.get('ir.attachment').browse(cr, uid, src.file_id)
- dst_obj2 = False
- if isinstance(dst_basedir, node_res_dir):
- dst_obj2 = dst_basedir and dst_basedir.res_model or False
+ dst_obj2 = False
+ if isinstance(dst_basedir, node_res_obj):
+ dst_obj2 = dst_basedir and pool.get(dst_basedir.context.context['res_model']).browse(cr, uid, dst_basedir.context.context['res_id']) or False
dst_obj = dst_basedir.context._dirobj.browse(cr, uid, dst_basedir.dir_id)
val = {
@@ -627,7 +627,7 @@ class abstracted_fs:
if dst_obj2._name == 'res.partner':
val['partner_id'] = dst_obj2.id
else:
- val['partner_id'] = pool.get(dst_obj2._name).fields_get(src.cr, src.uid, ['partner_id']) and dst_obj2.partner_id.id or False
+ val['partner_id'] = pool.get(dst_obj2._name).fields_get(cr, uid, ['partner_id']) and dst_obj2.partner_id.id or False
elif obj.res_id:
# I had to do that because writing False to an integer writes 0 instead of NULL
# change if one day we decide to improve osv/fields.py
diff --git a/addons/document/nodes.py b/addons/document/nodes.py
index 9bc3de05bfa..e6a614bf6aa 100644
--- a/addons/document/nodes.py
+++ b/addons/document/nodes.py
@@ -60,14 +60,13 @@ class node_context(object):
def get_uri(self, cr, uri):
""" Although this fn passes back to doc.dir, it is needed since
- it is a potential caching point """
-
- (ndir, duri) = self._dirobj._locate_child(cr,self.uid, self.rootdir,uri, None, self)
- while duri:
- ndir = ndir.child(cr, duri[0])
+ it is a potential caching point """
+ (ndir, duri) = self._dirobj._locate_child(cr,self.uid, self.rootdir,uri, None, self)
+ while duri:
+ ndir = ndir.child(cr, duri[0])
if not ndir:
return False
- duri = duri[1:]
+ duri = duri[1:]
return ndir
@@ -190,7 +189,7 @@ class node_dir(node_class):
def children(self,cr):
return self._child_get(cr) + self._file_get(cr)
- def child(self,cr, name):
+ def child(self,cr, name):
res = self._child_get(cr,name)
if res:
return res[0]
@@ -332,7 +331,7 @@ class node_res_dir(node_class):
def children(self,cr):
return self._child_get(cr)
- def child(self,cr, name):
+ def child(self,cr, name):
res = self._child_get(cr,name)
if res:
return res[0]
@@ -380,7 +379,7 @@ class node_res_dir(node_class):
continue
# Yes! we can't do better but skip nameless records.
- res.append(node_res_obj(name,self,self.context,self.res_model, bo))
+ res.append(node_res_obj(name, self.dir_id, self, self.context, self.res_model, bo))
return res
def _get_ttag(self,cr):
@@ -393,11 +392,11 @@ class node_res_obj(node_class):
node_dirs (with limited domain).
"""
our_type = 'collection'
- def __init__(self,path, parent, context, res_model, res_bo, res_id = None):
+ def __init__(self, path, dir_id, parent, context, res_model, res_bo, res_id = None):
super(node_res_obj,self).__init__(path, parent,context)
assert parent
- #todo: more info from dirr
- self.dir_id = parent.dir_id
+ #todo: more info from dirr
+ self.dir_id = dir_id
self.mimetype = 'application/x-directory'
# 'httpd/unix-directory'
self.create_date = parent.create_date
@@ -428,8 +427,8 @@ class node_res_obj(node_class):
def children(self,cr):
return self._child_get(cr) + self._file_get(cr)
- def child(self,cr, name):
- res = self._child_get(cr,name)
+ def child(self,cr, name):
+ res = self._child_get(cr,name)
if res:
return res[0]
res = self._file_get(cr,name)
@@ -484,7 +483,7 @@ class node_res_obj(node_class):
return ('vevent-collection','http://groupdav.org/')
return None
- def _child_get(self,cr,name = None):
+ def _child_get(self,cr,name = None):
dirobj = self.context._dirobj
uid = self.context.uid
ctx = self.context.context.copy()
@@ -498,44 +497,53 @@ class node_res_obj(node_class):
# Directory Structure display in tree structure
if self.res_id and directory.ressource_tree:
- where1 = where
+ where1 = []
if obj._parent_name in obj.fields_get(cr, uid):
- where1 += [(obj._parent_name, '=', self.res_id)]
+ where1 = where + [(obj._parent_name, '=', self.res_id)]
resids = obj.search(cr,uid, where1, context=ctx)
for bo in obj.browse(cr,uid,resids,context=ctx):
namefield = directory.resource_field or 'name'
if not bo:
continue
- name = getattr(bo, namefield)
- if not name:
+ res_name = getattr(bo, namefield)
+ if not res_name:
continue
- res.append(node_res_obj(name, self, self.context, self.res_model, res_bo = bo))
-
- # Get Child Ressource Directories
- where12 = [('ressource_parent_type_id','=',directory.ressource_type_id.id)]
- dirids = dirobj.search(cr,uid, where12)
- for dirr in dirobj.browse(cr, uid, dirids, context=ctx):
- if dirr.type == 'ressource':
- res.append(node_res_dir(dirr.name, self, self.context, dirr, {'active_id': self.res_id}))
+ res.append(node_res_obj(res_name, self.dir_id, self, self.context, self.res_model, res_bo = bo))
- where = [('parent_id','=',self.dir_id) ]
- ids = dirobj.search(cr, uid, where,context=ctx)
- if ids:
- for dirr in dirobj.browse(cr,uid,ids,context=ctx):
- if dirr.type == 'directory':
- res.append(node_res_obj(dirr.name,self,self.context,self.res_model,res_bo = None, res_id = self.res_id))
- elif dirr.type == 'ressource':
- # child resources can be controlled by properly set dctx
- res.append(node_res_dir(dirr.name,self,self.context, dirr, {'active_id': self.res_id}))
- fil_obj=dirobj.pool.get('ir.attachment')
- where2 = where + [('res_model', '=', self.res_model), ('res_id','=',self.res_id)]
+ where2 = where + [('parent_id','=',self.dir_id) ]
+ ids = dirobj.search(cr, uid, where2, context=ctx)
+ for dirr in dirobj.browse(cr, uid, ids, context=ctx):
+ if dirr.type == 'directory':
+ res.append(node_res_obj(dirr.name, dirr.id, self, self.context, self.res_model, res_bo = None, res_id = self.res_id))
+ elif dirr.type == 'ressource':
+ # child resources can be controlled by properly set dctx
+ res.append(node_res_dir(dirr.name,self,self.context, dirr, {'active_id': self.res_id}))
+
+
+
+
+ fil_obj = dirobj.pool.get('ir.attachment')
+ where3 = where2 + [('res_model', '=', self.res_model), ('res_id','=',self.res_id)]
# print "where clause for dir_obj", where2
- ids = fil_obj.search(cr,uid,where2,context=ctx)
+ ids = fil_obj.search(cr, uid, where3, context=ctx)
if ids:
- for fil in fil_obj.browse(cr,uid,ids,context=ctx):
- res.append(node_file(fil.name,self,self.context,fil))
+ for fil in fil_obj.browse(cr, uid, ids, context=ctx):
+ res.append(node_file(fil.name, self, self.context, fil))
+
+ # Get Child Ressource Directories
+ if directory.ressource_type_id and directory.ressource_type_id.id:
+ where4 = where + [('ressource_parent_type_id','=',directory.ressource_type_id.id)]
+ where5 = where4 + [('ressource_id','=',0)]
+ dirids = dirobj.search(cr,uid, where5)
+ where5 = where4 + [('ressource_id','=',self.res_id)]
+ dirids = dirids + dirobj.search(cr,uid, where5)
+ for dirr in dirobj.browse(cr, uid, dirids, context=ctx):
+ if dirr.type == 'directory' and not dirr.parent_id:
+ res.append(node_res_obj(dirr.name, dirr.id, self, self.context, self.res_model, res_bo = None, res_id = self.res_id))
+ 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(self,cr,path,data):