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 openerp.osv import fields, osv
23 from openerp.tools import config
27 class document_davdir(osv.osv):
28 _inherit = 'document.directory'
31 # Placed here just for a reference
32 'dav_prop_ids': fields.one2many('document.webdav.dir.property', 'dir_id', 'DAV properties'),
35 def get_node_class(self, cr, uid, ids, dbro=None, dynamic=False, context=None):
36 # Note: in this function, nodes come from document_webdav/nodes.py !
38 dbro = self.browse(cr, uid, ids, context=context)
41 return nodes.node_res_obj
42 elif dbro.type == 'directory':
44 elif dbro.type == 'ressource':
45 return nodes.node_res_dir
47 raise ValueError("Directory node for %s type.", dbro.type)
49 def _prepare_context(self, cr, uid, nctx, context=None):
50 nctx.node_file_class = nodes.node_file
51 # We can fill some more fields, but avoid any expensive function
52 # that might be not worth preparing.
53 nctx.extra_ctx['webdav_path'] = '/'+config.get_misc('webdav','vdir','webdav')
54 usr_obj = self.pool.get('res.users')
55 res = usr_obj.read(cr, uid, uid, ['login','lang'])
57 nctx.extra_ctx['username'] = res['login']
58 nctx.extra_ctx['lang'] = res['lang']
62 def _locate_child(self, cr, uid, root_id, uri, nparent, ncontext):
63 """ try to locate the node in uri,
64 Return a tuple (node_dir, remaining_path)
66 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),
98 class dav_file_property(osv.osv):
99 """ Arbitrary WebDAV properties, attached to ir.attachments.
101 A special case is the locks that can be applied on file nodes.
103 There _can_ be properties without a file (RFC?), which means that they
104 globally apply to all the attachments of the present database.
106 TODO access permissions, per property.
108 _name = 'document.webdav.file.property'
111 'create_date': fields.datetime('Date Created', readonly=True),
112 'create_uid': fields.many2one('res.users', 'Creator', readonly=True),
113 'write_date': fields.datetime('Date Modified', readonly=True),
114 'write_uid': fields.many2one('res.users', 'Last Modification User', readonly=True),
115 'file_id': fields.many2one('ir.attachment', 'Document', required=False, select=1),
116 'namespace': fields.char('Namespace', size=127, required=True),
117 'name': fields.char('Name', size=64, required=True),
118 'value': fields.text('Value'),
119 'do_subst': fields.boolean('Substitute', required=True),
127 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: