From a286f1ae6d7fa6e07ca44439f3c57bae7d39688a Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Thu, 1 Jul 2010 20:51:32 +0300 Subject: [PATCH] Document API: fns to get nodes from orm objects. ORM objects should not directly create nodes, but instead ask the context to provide them (because they could be cached). bzr revid: p_christ@hol.gr-20100701175132-hfnvj5czdwuaswwg --- addons/document/nodes.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/addons/document/nodes.py b/addons/document/nodes.py index 14d8b16d987..acbf4ed8dcd 100644 --- a/addons/document/nodes.py +++ b/addons/document/nodes.py @@ -67,6 +67,27 @@ class node_context(object): return False duri = duri[1:] return ndir + + def get_dir_node(cr, dbro): + """Create (or locate) a node for a directory + @param dbro a browse object of document.directory + """ + fullpath = self._dirobj.get_full_path(cr, self.uid, dbro.id, self.context) + if dbro.type == 'directory': + return node_dir(fullpath, None ,self, dbro) + elif dbro.type == 'ressource': + assert dbro.ressource_parent_type_id == False + return node_res_dir(fullparh, None, self, dbro) + else: + raise ValueError("dir node for %s type", dbro.type) + + def get_file_node(cr, fbro): + """ 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) + class node_descriptor(object): """A file-like interface to the data contents of a node.