Draft api for document.write(parent_id: ...)

If the parent directory for some document node changes, we may
have a major change in the stored content, so an API is needed
for that.

Conflicts:

	document/nodes.py

bzr revid: p_christ@hol.gr-20100701175131-ldt3b0er5a7tja0u
This commit is contained in:
P. Christeas 2010-07-01 20:51:31 +03:00
parent 28464cb07c
commit 11c5171326
2 changed files with 51 additions and 1 deletions

View File

@ -28,6 +28,7 @@ import os
import pooler
import netsvc
from osv.orm import except_orm
#import StringIO
from psycopg2 import Binary
@ -153,7 +154,30 @@ 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!'))
result = super(document_file, self).write(cr, uid, ids, vals, context=context)
if 'parent_id' in vals:
# perhaps this file is 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)
ids2 = []
result = False
for fbro in self.browse(cr, uid, ids, context=context):
if fbro.parent_id != vals['parent_id']:
fnode = nodes.node_file(None,None,nctx,fbro)
res = fnode.move_to(cr, 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 len(ids):
result = super(document_file,self).write(cr, uid, ids, vals, context=context)
cr.commit()
return result

View File

@ -209,6 +209,32 @@ class node_class(object):
def get_dav_eprop(self, cr, ns, prop):
return None
def move_to(self, cr, fil_obj, ndir_obj, in_write=False):
""" Move this node to a new parent directory.
fil_obj, can be None, is the browse object for the file, if already
available.
ndir_obj must be the browse object to the new doc.directory location,
where this node should be moved to.
in_write: When called by write(), we shouldn't attempt to write the
object, but instead return the dict of vals (avoid re-entrance).
If false, we should write all data to the object, here, as if the
caller won't do anything after calling move_to()
Return value:
True: the node is moved, the caller can update other values, too.
False: the node is either removed or fully updated, the caller
must discard the fil_obj, not attempt to write any more to it.
dict: values to write back to the object. *May* contain a new id!
Depending on src and target storage, implementations of this function
could do various things.
Should also consider node<->content, dir<->dir moves etc.
Move operations, as instructed from APIs (eg. request from DAV) could
use this function.
"""
raise NotImplementedError
def rm(self, cr):
raise RuntimeError("Not Implemented")