1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 from osv import osv, fields
24 from tools import config
26 class document_davdir(osv.osv):
27 _inherit = 'document.directory'
30 # Placed here just for a reference
31 'dav_prop_ids': fields.one2many('document.webdav.dir.property', 'dir_id', 'DAV properties'),
34 def get_node_class(self, cr, uid, ids, dbro=None, dynamic=False, context=None):
35 # Note: in this function, nodes come from document_webdav/nodes.py !
37 dbro = self.browse(cr, uid, ids, context=context)
40 return nodes.node_res_obj
41 elif dbro.type == 'directory':
43 elif dbro.type == 'ressource':
44 return nodes.node_res_dir
46 raise ValueError("dir node for %s type", dbro.type)
48 def _prepare_context(self, cr, uid, nctx, context=None):
49 nctx.node_file_class = nodes.node_file
50 # We can fill some more fields, but avoid any expensive function
51 # that might be not worth preparing.
52 nctx.extra_ctx['webdav_path'] = '/'+config.get_misc('webdav','vdir','webdav')
53 usr_obj = self.pool.get('res.users')
54 res = usr_obj.read(cr, uid, uid, ['login'])
56 nctx.extra_ctx['username'] = res['login']
60 def _locate_child(self, cr, uid, root_id, uri,nparent, ncontext):
61 """ try to locate the node in uri,
62 Return a tuple (node_dir, remaining_path)
64 return (nodes.node_database(context=ncontext), uri)
68 class dav_dir_property(osv.osv):
69 """ Arbitrary WebDAV properties, attached to document.directories.
71 Some DAV properties have to be settable at directories, depending
72 on the database directory structure.
74 Example would be the principal-URL.
76 There _can_ be properties without a directory, which means that they
77 globally apply to all the directories (aka. collections) of the
80 _name = 'document.webdav.dir.property'
83 'create_date': fields.datetime('Date Created', readonly=True),
84 'create_uid': fields.many2one('res.users', 'Creator', readonly=True),
85 'write_date': fields.datetime('Date Modified', readonly=True),
86 'write_uid': fields.many2one('res.users', 'Last Modification User', readonly=True),
87 'dir_id': fields.many2one('document.directory', 'Directory', required=False, select=1),
88 'namespace': fields.char('Namespace', size=127, required=True),
89 'name': fields.char('Name', size=64, required=True),
90 'value': fields.text('Value'),
91 'do_subst': fields.boolean('Substitute', required=True),
100 class dav_file_property(osv.osv):
101 """ Arbitrary WebDAV properties, attached to ir.attachments.
103 A special case is the locks that can be applied on file nodes.
105 There _can_ be properties without a file (RFC?), which means that they
106 globally apply to all the attachments of the present database.
108 TODO access permissions, per property.
110 _name = 'document.webdav.file.property'
113 'create_date': fields.datetime('Date Created', readonly=True),
114 'create_uid': fields.many2one('res.users', 'Creator', readonly=True),
115 'write_date': fields.datetime('Date Modified', readonly=True),
116 'write_uid': fields.many2one('res.users', 'Last Modification User', readonly=True),
117 'file_id': fields.many2one('ir.attachment', 'Document', required=False, select=1),
118 'namespace': fields.char('Namespace', size=127, required=True),
119 'name': fields.char('Name', size=64, required=True),
120 'value': fields.text('Value'),
121 'do_subst': fields.boolean('Substitute', required=True),