summaryrefslogtreecommitdiff
path: root/addons/document/nodes.py
diff options
context:
space:
mode:
authorP. Christeas <p_christ@hol.gr>2010-07-01 20:51:33 +0300
committerP. Christeas <p_christ@hol.gr>2010-07-01 20:51:33 +0300
commit54b9e746ac4dad02e17d98c8febf5c899baf2ab0 (patch)
treebfeb7b37508368c5fc7a3645a6309b49f04cc156 /addons/document/nodes.py
parent9cdbcbfee1d356ebaab68e17e75aa0bf1eb16b5d (diff)
Document API: trivial implementation of simple file rename
bzr revid: p_christ@hol.gr-20100701175133-k0gnyan62wo2gs7n
Diffstat (limited to 'addons/document/nodes.py')
-rw-r--r--addons/document/nodes.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/addons/document/nodes.py b/addons/document/nodes.py
index 639d0e9b9b8..a77c35b4cdf 100644
--- a/addons/document/nodes.py
+++ b/addons/document/nodes.py
@@ -941,6 +941,44 @@ class node_file(node_class):
def _get_ttag(self,cr):
return 'file-%d' % self.file_id
+ def move_to(self, cr, ndir_node, new_name=False, fil_obj=None, ndir_obj=None, in_write=False):
+ if ndir_node.context != self.context:
+ raise NotImplementedError("Cannot move files between contexts")
+
+ doc_obj = self.context._dirobj.pool.get('ir.attachment')
+ if not fil_obj:
+ 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
+
+ if not dbro:
+ raise IndexError("Cannot locate doc %d", self.file_id)
+
+ if (not self.parent):
+ # there *must* be a parent node for this one
+ self.parent = self.context.get_dir_node(cr, dbro.parent_id.id)
+
+ 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 new_name and (new_name != dbro.name):
+ 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)
+
+ del dbro
+
+ if not in_write:
+ # We have to update the data ourselves
+ if ret:
+ doc_obj.write(cr, self.context.uid, [self.file_id,], ret, self.context.context)
+ ret = True
+
+ return ret
+
class node_content(node_class):
our_type = 'content'
def __init__(self, path, parent, context, cnt, dctx = None, act_id=None):