1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # Copyright (c) 2004-2008 TINY SPRL. (http://tiny.be) All Rights Reserved.
8 # WARNING: This program as such is intended to be used by professional
9 # programmers who take the whole responsability of assessing all potential
10 # consequences resulting from its eventual inadequacies and bugs
11 # End users who are looking for a ready-to-use solution with commercial
12 # garantees and support are strongly adviced to contract a Free Software
15 # This program is Free Software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License
17 # as published by the Free Software Foundation; either version 2
18 # of the License, or (at your option) any later version.
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 ##############################################################################
31 from osv import fields,osv
32 from lxml import etree
37 def _check_xml(self, cr, uid, ids, context={}):
39 for view in self.browse(cr, uid, ids, context):
40 eview = etree.fromstring(view.arch)
41 frng = tools.file_open(os.path.join('base','rng','view.rng'))
42 relaxng = etree.RelaxNG(file=frng)
43 if not relaxng.validate(eview):
44 logger = netsvc.Logger()
45 logger.notifyChannel('init', netsvc.LOG_ERROR, 'The view do not fit the required schema !')
46 logger.notifyChannel('init', netsvc.LOG_ERROR, relaxng.error_log.last_error)
50 class view_custom(osv.osv):
51 _name = 'ir.ui.view.custom'
53 'ref_id': fields.many2one('ir.ui.view', 'Orignal View'),
54 'user_id': fields.many2one('res.users', 'User'),
55 'arch': fields.text('View Architecture', required=True),
62 'name': fields.char('View Name',size=64, required=True),
63 'model': fields.char('Model', size=64, required=True),
64 'priority': fields.integer('Priority', required=True),
65 'type': fields.selection((
69 ('calendar', 'Calendar')), 'View Type', required=True),
70 'arch': fields.text('View Architecture', required=True),
71 'inherit_id': fields.many2one('ir.ui.view', 'Inherited View', ondelete='cascade'),
72 'field_parent': fields.char('Childs Field',size=64),
75 'arch': lambda *a: '<?xml version="1.0"?>\n<tree title="Unknwown">\n\t<field name="name"/>\n</tree>',
76 'priority': lambda *a: 16
80 (_check_xml, 'Invalid XML for View Architecture!', ['arch'])
83 def read(self, cr, uid, ids, fields=None, context={}, load='_classic_read'):
85 if not isinstance(ids, (list, tuple)):
88 result = super(view, self).read(cr, uid, ids, fields, context, load)
89 print '************************** : ',result
92 if rs.get('model') == 'board.board':
93 cr.execute("select id,arch,ref_id from ir_ui_view_custom where user_id=%d and ref_id=%d", (uid, rs['id']))
94 oview = cr.dictfetchall()
96 rs['arch'] = oview[0]['arch']
101 def write(self, cr, uid, ids, vals, context={}):
103 if not isinstance(ids, (list, tuple)):
106 exist = self.pool.get('ir.ui.view').browse(cr, uid, ids[0])
107 if exist.model == 'board.board' and 'arch' in vals:
108 vids = self.pool.get('ir.ui.view.custom').search(cr, uid, [('user_id','=',uid), ('ref_id','=',ids[0])])
109 vals2 = {'user_id': uid, 'ref_id': ids[0], 'arch': vals.pop('arch')}
111 # write fields except arch to the `ir.ui.view`
112 result = super(view, self).write(cr, uid, ids, vals, context)
115 self.pool.get('ir.ui.view.custom').create(cr, uid, vals2)
117 self.pool.get('ir.ui.view.custom').write(cr, uid, vids, vals2)
121 return super(view, self).write(cr, uid, ids, vals, context)
124 class view_sc(osv.osv):
125 _name = 'ir.ui.view_sc'
127 'name': fields.char('Shortcut Name', size=64, required=True),
128 'res_id': fields.many2one('ir.values','Resource Ref.', ondelete='cascade'),
129 'sequence': fields.integer('Sequence'),
130 'user_id': fields.many2one('res.users', 'User Ref.', required=True, ondelete='cascade'),
131 'resource': fields.char('Resource Name', size=64, required=True)
134 def get_sc(self, cr, uid, user_id, model='ir.ui.menu', context={}):
135 ids = self.search(cr, uid, [('user_id','=',user_id),('resource','=',model)], context=context)
136 return self.read(cr, uid, ids, ['res_id','name'], context=context)
140 'resource': lambda *a: 'ir.ui.menu',
141 'user_id': lambda obj, cr, uid, context: uid,
145 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: