2008-07-23 15:01:27 +00:00
|
|
|
# -*- encoding: utf-8 -*-
|
2006-12-07 13:41:40 +00:00
|
|
|
##############################################################################
|
|
|
|
#
|
2008-06-16 11:00:21 +00:00
|
|
|
# Copyright (c) 2004-2008 TINY SPRL. (http://tiny.be) All Rights Reserved.
|
|
|
|
#
|
|
|
|
# $Id$
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
|
|
|
# WARNING: This program as such is intended to be used by professional
|
|
|
|
# programmers who take the whole responsability of assessing all potential
|
|
|
|
# consequences resulting from its eventual inadequacies and bugs
|
|
|
|
# End users who are looking for a ready-to-use solution with commercial
|
|
|
|
# garantees and support are strongly adviced to contract a Free Software
|
|
|
|
# Service Company
|
|
|
|
#
|
|
|
|
# This program is Free Software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
from osv import fields,osv
|
2008-07-01 21:31:46 +00:00
|
|
|
from lxml import etree
|
|
|
|
import tools
|
|
|
|
import netsvc
|
|
|
|
import os
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2008-07-01 21:31:46 +00:00
|
|
|
def _check_xml(self, cr, uid, ids, context={}):
|
2008-07-22 14:24:36 +00:00
|
|
|
for view in self.browse(cr, uid, ids, context):
|
|
|
|
eview = etree.fromstring(view.arch)
|
|
|
|
frng = tools.file_open(os.path.join('base','rng',view.type+'.rng'))
|
|
|
|
relaxng = etree.RelaxNG(file=frng)
|
|
|
|
if not relaxng.validate(eview):
|
|
|
|
logger = netsvc.Logger()
|
|
|
|
logger.notifyChannel('init', netsvc.LOG_ERROR, 'The view do not fit the required schema !')
|
|
|
|
logger.notifyChannel('init', netsvc.LOG_ERROR, relaxng.error_log.last_error)
|
|
|
|
print view.arch
|
|
|
|
return False
|
|
|
|
return True
|
2006-12-07 13:41:40 +00:00
|
|
|
|
|
|
|
class view(osv.osv):
|
2008-07-22 14:24:36 +00:00
|
|
|
_name = 'ir.ui.view'
|
|
|
|
_columns = {
|
|
|
|
'name': fields.char('View Name',size=64, required=True),
|
|
|
|
'model': fields.char('Model', size=64, required=True),
|
|
|
|
'priority': fields.integer('Priority', required=True),
|
|
|
|
'type': fields.selection((
|
|
|
|
('tree','Tree'),
|
|
|
|
('form','Form'),
|
|
|
|
('graph', 'Graph'),
|
|
|
|
('calendar', 'Calendar')), 'View Type', required=True),
|
|
|
|
'arch': fields.text('View Architecture', required=True),
|
|
|
|
'inherit_id': fields.many2one('ir.ui.view', 'Inherited View'),
|
|
|
|
'field_parent': fields.char('Childs Field',size=64),
|
|
|
|
}
|
|
|
|
_defaults = {
|
|
|
|
'arch': lambda *a: '<?xml version="1.0"?>\n<tree title="Unknwown">\n\t<field name="name"/>\n</tree>',
|
|
|
|
'priority': lambda *a: 16
|
|
|
|
}
|
|
|
|
_order = "priority"
|
|
|
|
_constraints = [
|
|
|
|
(_check_xml, 'Invalid XML for View Architecture!', ['arch'])
|
|
|
|
]
|
2006-12-07 13:41:40 +00:00
|
|
|
|
|
|
|
view()
|
|
|
|
|
2008-07-25 10:35:27 +00:00
|
|
|
class UserView(osv.osv):
|
|
|
|
_name = 'ir.ui.view.user'
|
|
|
|
_columns = {
|
|
|
|
'name': fields.char('View Name',size=64, required=True),
|
|
|
|
'model': fields.char('Model', size=64, required=True),
|
|
|
|
'priority': fields.integer('Priority', required=True),
|
|
|
|
'type': fields.selection((
|
|
|
|
('tree','Tree'),
|
|
|
|
('form','Form'),
|
|
|
|
('graph', 'Graph'),
|
|
|
|
('calendar', 'Calendar')), 'View Type', required=True),
|
|
|
|
'arch': fields.text('View Architecture', required=True),
|
|
|
|
'inherit_id': fields.many2one('ir.ui.view', 'Inherited View'),
|
|
|
|
'field_parent': fields.char('Childs Field',size=64),
|
|
|
|
'user_id': fields.many2one('res.users', 'User'),
|
|
|
|
'ref_id': fields.many2one('ir.ui.view', 'Inherited View'),
|
|
|
|
}
|
|
|
|
_defaults = {
|
|
|
|
'arch': lambda *a: '<?xml version="1.0"?>\n<tree title="Unknwown">\n\t<field name="name"/>\n</tree>',
|
|
|
|
'priority': lambda *a: 16
|
|
|
|
}
|
|
|
|
_order = "priority"
|
|
|
|
_constraints = [
|
|
|
|
(_check_xml, 'Invalid XML for View Architecture!', ['arch'])
|
|
|
|
]
|
|
|
|
|
|
|
|
UserView()
|
2008-06-25 09:18:31 +00:00
|
|
|
|
2006-12-07 13:41:40 +00:00
|
|
|
class view_sc(osv.osv):
|
2008-07-22 14:24:36 +00:00
|
|
|
_name = 'ir.ui.view_sc'
|
|
|
|
_columns = {
|
|
|
|
'name': fields.char('Shortcut Name', size=64, required=True),
|
|
|
|
'res_id': fields.many2one('ir.values','Resource Ref.', ondelete='cascade'),
|
|
|
|
'sequence': fields.integer('Sequence'),
|
|
|
|
'user_id': fields.many2one('res.users', 'User Ref.', required=True, ondelete='cascade'),
|
|
|
|
'resource': fields.char('Resource Name', size=64, required=True)
|
|
|
|
}
|
2008-06-12 10:45:39 +00:00
|
|
|
|
2008-07-22 14:24:36 +00:00
|
|
|
def get_sc(self, cr, uid, user_id, model='ir.ui.menu', context={}):
|
|
|
|
ids = self.search(cr, uid, [('user_id','=',user_id),('resource','=',model)], context=context)
|
|
|
|
return self.read(cr, uid, ids, ['res_id','name'], context=context)
|
2007-06-28 18:00:41 +00:00
|
|
|
|
2008-07-22 14:24:36 +00:00
|
|
|
_order = 'sequence'
|
|
|
|
_defaults = {
|
|
|
|
'resource': lambda *a: 'ir.ui.menu',
|
|
|
|
'user_id': lambda obj, cr, uid, context: uid,
|
|
|
|
}
|
2006-12-07 13:41:40 +00:00
|
|
|
view_sc()
|
2008-07-23 15:01:27 +00:00
|
|
|
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
|
|
|