diff options
| author | P. Christeas <p_christ@hol.gr> | 2010-07-01 20:51:33 +0300 |
|---|---|---|
| committer | P. Christeas <p_christ@hol.gr> | 2010-07-01 20:51:33 +0300 |
| commit | 49bf479c188533b93d74f1e0f873f8d71b6ebd75 (patch) | |
| tree | 23cfeee14a64b86ff947cfa23750821535041215 /addons/document/document_storage.py | |
| parent | 54b9e746ac4dad02e17d98c8febf5c899baf2ab0 (diff) | |
Document storage: implementation of simple rename
Conflicts:
document/document_storage.py
bzr revid: p_christ@hol.gr-20100701175133-ti0itn58w9az88w6
Diffstat (limited to 'addons/document/document_storage.py')
| -rw-r--r-- | addons/document/document_storage.py | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/addons/document/document_storage.py b/addons/document/document_storage.py index 290faac0229..aeea5f99011 100644 --- a/addons/document/document_storage.py +++ b/addons/document/document_storage.py @@ -480,7 +480,7 @@ class document_storage(osv.osv): path = storage_bo.path return ( storage_bo.id, 'file', os.path.join(path, fname)) else: - raise TypeError("No %s storage" % boo.type) + raise TypeError("No %s storage" % storage_bo.type) def do_unlink(self, cr, uid, unres): for id, ktype, fname in unres: @@ -494,6 +494,42 @@ class document_storage(osv.osv): return True + def simple_rename(self, cr, uid, file_node, new_name, context=None): + """ A preparation for a file rename. + It will not affect the database, but merely check and perhaps + rename the realstore file. + + @return the dict of values that can safely be be stored in the db. + """ + sbro = self.browse(cr, uid, file_node.storage_id, context=context) + assert sbro, "The file #%d didn't provide storage" % file_node.file_id + + if sbro.type in ('filestore', 'db'): + # nothing to do for a rename, allow to change the db field + return { 'name': new_name, 'datas_fname': new_name } + elif sbro.type == 'realstore': + fname = fil_bo.store_fname + if not fname: + return ValueError("Tried to rename a non-stored file") + path = storage_bo.path + oldpath = os.path.join(path, fname) + + for ch in ('*', '|', "\\", '/', ':', '"', '<', '>', '?', '..'): + if ch in new_name: + raise ValueError("Invalid char %s in name %s" %(ch, new_name)) + + file_node.fix_ppath(cr, ira) + npath = file_node.full_path() or [] + dpath = [path,] + dpath.extend(npath[:-1]) + dpath.append(new_name) + newpath = os.path.join(*dpath) + # print "old, new paths:", oldpath, newpath + os.rename(oldpath, newpath) + return { 'name': new_name, 'datas_fname': new_name, 'store_fname': new_name } + else: + raise TypeError("No %s storage" % boo.type) + document_storage() |
