Document: support Moving of files.
bzr revid: p_christ@hol.gr-20100709082316-d8qedrjabckypt88
This commit is contained in:
parent
173be44150
commit
0d6e0a9a02
|
@ -154,32 +154,39 @@ class document_file(osv.osv):
|
|||
return False
|
||||
if not self._check_duplication(cr, uid, vals, ids, 'write'):
|
||||
raise osv.except_osv(_('ValidateError'), _('File name must be unique!'))
|
||||
if 'parent_id' in vals:
|
||||
# perhaps this file is changing directory
|
||||
if ('parent_id' in vals) or ('name' in vals):
|
||||
# perhaps this file is renaming or changing directory
|
||||
nctx = nodes.get_node_context(cr,uid,context)
|
||||
dirobj = self.pool.get('document.directory')
|
||||
dbro = dirobj.browse(cr, uid, vals['parent_id'], context=context)
|
||||
dnode = nctx.get_dir_node(cr, dbro)
|
||||
if 'parent_id' in vals:
|
||||
dbro = dirobj.browse(cr, uid, vals['parent_id'], context=context)
|
||||
dnode = nctx.get_dir_node(cr, dbro)
|
||||
else:
|
||||
dbro = None
|
||||
dnode = None
|
||||
ids2 = []
|
||||
result = False
|
||||
for fbro in self.browse(cr, uid, ids, context=context):
|
||||
if fbro.parent_id.id != vals['parent_id']:
|
||||
fnode = nctx.get_file_node(cr, fbro)
|
||||
res = fnode.move_to(cr, dnode, fbro, dbro, True)
|
||||
if isinstance(res, dict):
|
||||
vals2 = vals.copy()
|
||||
vals2.update(res)
|
||||
wid = res.get('id', fbro.id)
|
||||
result = super(document_file,self).write(cr,uid,wid,vals2,context=context)
|
||||
# TODO: how to handle/merge several results?
|
||||
elif res == True:
|
||||
if ('parent_id' not in vals or fbro.parent_id.id == vals['parent_id']) \
|
||||
and ('name' not in vals or fbro.name == vals['name']) :
|
||||
ids2.append(fbro.id)
|
||||
elif res == False:
|
||||
pass
|
||||
continue
|
||||
fnode = nctx.get_file_node(cr, fbro)
|
||||
res = fnode.move_to(cr, dnode or fnode.parent, vals.get('name', fbro.name), fbro, dbro, True)
|
||||
if isinstance(res, dict):
|
||||
vals2 = vals.copy()
|
||||
vals2.update(res)
|
||||
wid = res.get('id', fbro.id)
|
||||
result = super(document_file,self).write(cr,uid,wid,vals2,context=context)
|
||||
# TODO: how to handle/merge several results?
|
||||
elif res == True:
|
||||
ids2.append(fbro.id)
|
||||
elif res == False:
|
||||
pass
|
||||
ids = ids2
|
||||
if 'file_size' in vals: # only write that field using direct SQL calls
|
||||
del vals['file_size']
|
||||
if len(ids):
|
||||
if len(ids) and len(vals):
|
||||
result = super(document_file,self).write(cr, uid, ids, vals, context=context)
|
||||
cr.commit() # ?
|
||||
return result
|
||||
|
|
|
@ -270,6 +270,8 @@ class document_directory(osv.osv):
|
|||
raise osv.except_osv(_('ValidateError'), _('Directory name contains special characters!'))
|
||||
return super(document_directory,self).create(cr, uid, vals, context)
|
||||
|
||||
# TODO def unlink(...
|
||||
|
||||
document_directory()
|
||||
|
||||
class document_directory_dctx(osv.osv):
|
||||
|
|
|
@ -102,8 +102,11 @@ class node_context(object):
|
|||
""" Create or locate a node for a static file
|
||||
@param fbro a browse object of an ir.attachment
|
||||
"""
|
||||
# TODO: fill the parent
|
||||
return node_file(None,None,self,fbro)
|
||||
parent = None
|
||||
if fbro.parent_id:
|
||||
parent = self.get_dir_node(cr, fbro.parent_id)
|
||||
|
||||
return node_file(fbro.name,parent,self,fbro)
|
||||
|
||||
|
||||
class node_descriptor(object):
|
||||
|
@ -190,6 +193,8 @@ class node_class(object):
|
|||
s = []
|
||||
if isinstance(self.path,list):
|
||||
s+=self.path
|
||||
elif path is None:
|
||||
s.append('')
|
||||
else:
|
||||
s.append(self.path)
|
||||
return s #map(lambda x: '/' +x, s)
|
||||
|
@ -1015,7 +1020,7 @@ class node_file(node_class):
|
|||
dbro = doc_obj.browse(cr, self.context.uid, self.file_id, context=self.context.context)
|
||||
else:
|
||||
dbro = fil_obj
|
||||
assert dbro.id == self.file_id
|
||||
assert dbro.id == self.file_id, "%s != %s for %r" % (dbro.id, self.file_id, self)
|
||||
|
||||
if not dbro:
|
||||
raise IndexError("Cannot locate doc %d", self.file_id)
|
||||
|
@ -1027,12 +1032,27 @@ class node_file(node_class):
|
|||
|
||||
# TODO: test if parent is writable.
|
||||
|
||||
if self.parent != ndir_node:
|
||||
logger.debug('Cannot move file %r from %r to %r', self, self.parent, ndir_node)
|
||||
raise NotImplementedError('Cannot move file to another dir')
|
||||
|
||||
ret = {}
|
||||
if self.parent != ndir_node:
|
||||
if not (isinstance(self.parent, node_dir) and isinstance(ndir_node, node_dir)):
|
||||
logger.debug('Cannot move file %r from %r to %r', self, self.parent, ndir_node)
|
||||
raise NotImplementedError('Cannot move files between dynamic folders')
|
||||
|
||||
if not ndir_obj:
|
||||
ndir_obj = self.context._dirobj.browse(cr, self.context.uid, \
|
||||
ndir_node.dir_id, context=self.context.context)
|
||||
|
||||
assert ndir_obj.id == ndir_node.dir_id
|
||||
|
||||
stobj = self.context._dirobj.pool.get('document.storage')
|
||||
r2 = stobj.simple_move(cr, self.context.uid, self, ndir_obj, \
|
||||
context=self.context.context)
|
||||
ret.update(r2)
|
||||
|
||||
if new_name and (new_name != dbro.name):
|
||||
if len(ret):
|
||||
raise NotImplementedError("Cannot rename and move") # TODO
|
||||
stobj = self.context._dirobj.pool.get('document.storage')
|
||||
r2 = stobj.simple_rename(cr, self.context.uid, self, new_name, self.context.context)
|
||||
ret.update(r2)
|
||||
|
|
Loading…
Reference in New Issue