[TYPO] Set the right category for the Point Of Sale
[odoo/odoo.git] / addons / document_webdav / document_webdav.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2010 Tiny SPRL (<http://tiny.be>).
6 #
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.
11 #
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.
16 #
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/>.
19 #
20 ##############################################################################
21
22 from osv import osv, fields
23 import nodes
24 from tools import config
25
26 class document_davdir(osv.osv):
27     _inherit = 'document.directory'
28
29     _columns = {
30         # Placed here just for a reference
31         'dav_prop_ids': fields.one2many('document.webdav.dir.property', 'dir_id', 'DAV properties'),
32         }
33
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 !
36         if dbro is None:
37             dbro = self.browse(cr, uid, ids, context=context)
38
39         if dynamic:
40             return nodes.node_res_obj
41         elif dbro.type == 'directory':
42             return nodes.node_dir
43         elif dbro.type == 'ressource':
44             return nodes.node_res_dir
45         else:
46             raise ValueError("dir node for %s type", dbro.type)
47
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'])
55         if res:
56             nctx.extra_ctx['username'] = res['login']
57         # TODO group
58         return
59
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)
63         """
64         return (nodes.node_database(context=ncontext), uri)
65
66 document_davdir()
67
68 class dav_dir_property(osv.osv):
69     """ Arbitrary WebDAV properties, attached to document.directories.
70     
71     Some DAV properties have to be settable at directories, depending
72     on the database directory structure.
73     
74     Example would be the principal-URL.
75     
76     There _can_ be properties without a directory, which means that they
77     globally apply to all the directories (aka. collections) of the
78     present database.
79     """
80     _name = 'document.webdav.dir.property'
81     
82     _columns = {
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),
92         }
93         
94     _defaults = {
95         'do_subst': False,
96         }
97         
98 dav_dir_property()
99
100 class dav_file_property(osv.osv):
101     """ Arbitrary WebDAV properties, attached to ir.attachments.
102     
103     A special case is the locks that can be applied on file nodes.
104     
105     There _can_ be properties without a file (RFC?), which means that they
106     globally apply to all the attachments of the present database.
107     
108     TODO access permissions, per property.
109     """
110     _name = 'document.webdav.file.property'
111     
112     _columns = {
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),
122         }
123         
124     _defaults = {
125         'do_subst': False,
126         }
127         
128 dav_file_property()
129
130 #eof
131 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: