2009-10-13 05:58:37 +00:00
|
|
|
|
# -*- coding: utf-8 -*-
|
2006-12-15 07:15:10 +00:00
|
|
|
|
##############################################################################
|
2009-11-27 09:25:21 +00:00
|
|
|
|
#
|
2009-10-14 11:15:34 +00:00
|
|
|
|
# OpenERP, Open Source Management Solution
|
2010-01-12 09:18:39 +00:00
|
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
2008-06-16 11:00:21 +00:00
|
|
|
|
#
|
2008-11-03 19:18:56 +00:00
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2009-10-14 11:15:34 +00:00
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
# License, or (at your option) any later version.
|
2006-12-15 07:15:10 +00:00
|
|
|
|
#
|
2008-11-03 19:18:56 +00:00
|
|
|
|
# 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
|
2009-10-14 11:15:34 +00:00
|
|
|
|
# GNU Affero General Public License for more details.
|
2006-12-15 07:15:10 +00:00
|
|
|
|
#
|
2009-10-14 11:15:34 +00:00
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
2009-11-27 09:25:21 +00:00
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-12-15 07:15:10 +00:00
|
|
|
|
#
|
|
|
|
|
##############################################################################
|
|
|
|
|
|
2010-03-17 10:22:07 +00:00
|
|
|
|
from osv import fields, osv
|
2006-12-15 07:15:10 +00:00
|
|
|
|
import time
|
2010-11-17 11:57:05 +00:00
|
|
|
|
import tools
|
2006-12-15 07:15:10 +00:00
|
|
|
|
|
2007-12-18 21:30:26 +00:00
|
|
|
|
class board_board(osv.osv):
|
2010-03-17 05:06:34 +00:00
|
|
|
|
"""
|
|
|
|
|
Board
|
|
|
|
|
"""
|
2008-07-22 15:11:28 +00:00
|
|
|
|
_name = 'board.board'
|
2010-03-17 05:06:34 +00:00
|
|
|
|
_description = "Board"
|
2010-03-26 13:27:16 +00:00
|
|
|
|
|
2010-03-17 10:22:07 +00:00
|
|
|
|
def create_view(self, cr, uid, ids, context=None):
|
|
|
|
|
"""
|
|
|
|
|
Create view
|
|
|
|
|
@param cr: the current row, from the database cursor,
|
|
|
|
|
@param uid: the current user’s ID for security checks,
|
|
|
|
|
@param ids: List of Board's IDs
|
|
|
|
|
@return: arch of xml view.
|
|
|
|
|
"""
|
2008-07-25 10:20:22 +00:00
|
|
|
|
arch = """<?xml version="1.0"?>
|
2012-08-05 07:20:27 +00:00
|
|
|
|
<form string="My Board" version="7.0">
|
2011-11-16 05:31:49 +00:00
|
|
|
|
<board style="1-1">
|
2012-08-05 07:20:27 +00:00
|
|
|
|
<column/>
|
|
|
|
|
<column/>
|
2011-11-16 05:31:49 +00:00
|
|
|
|
</board>
|
2012-08-05 07:20:27 +00:00
|
|
|
|
</form>"""
|
2008-07-25 10:20:22 +00:00
|
|
|
|
return arch
|
|
|
|
|
|
2008-07-22 15:11:28 +00:00
|
|
|
|
def create(self, cr, user, vals, context=None):
|
2010-03-17 10:22:07 +00:00
|
|
|
|
"""
|
|
|
|
|
create new record.
|
|
|
|
|
@param cr: the current row, from the database cursor,
|
|
|
|
|
@param uid: the current user’s ID for security checks,
|
|
|
|
|
@param vals: dictionary of values for every field.
|
|
|
|
|
dictionary must use this form: {‘name_of_the_field’: value, ...}
|
|
|
|
|
@return: id of new created record of board.board.
|
|
|
|
|
"""
|
2010-03-26 13:27:16 +00:00
|
|
|
|
|
|
|
|
|
|
2008-07-22 15:11:28 +00:00
|
|
|
|
if not 'name' in vals:
|
|
|
|
|
return False
|
2010-11-19 13:48:01 +00:00
|
|
|
|
id = super(board_board, self).create(cr, user, vals, context=context)
|
2008-07-25 10:20:22 +00:00
|
|
|
|
view_id = self.pool.get('ir.ui.view').create(cr, user, {
|
|
|
|
|
'name': vals['name'],
|
2010-03-17 10:22:07 +00:00
|
|
|
|
'model': 'board.board',
|
|
|
|
|
'priority': 16,
|
2008-07-25 10:20:22 +00:00
|
|
|
|
'type': 'form',
|
2010-11-19 13:48:01 +00:00
|
|
|
|
'arch': self.create_view(cr, user, id, context=context),
|
2008-07-25 10:20:22 +00:00
|
|
|
|
})
|
2009-04-09 10:02:19 +00:00
|
|
|
|
|
2009-04-06 13:40:39 +00:00
|
|
|
|
super(board_board, self).write(cr, user, [id], {'view_id': view_id}, context)
|
2008-07-25 10:20:22 +00:00
|
|
|
|
return id
|
2009-11-27 09:25:21 +00:00
|
|
|
|
|
2010-03-26 13:27:16 +00:00
|
|
|
|
def fields_view_get(self, cr, user, view_id=None, view_type='form', context=None,\
|
|
|
|
|
toolbar=False, submenu=False):
|
2010-03-17 10:22:07 +00:00
|
|
|
|
"""
|
|
|
|
|
Overrides orm field_view_get.
|
|
|
|
|
@return: Dictionary of Fields, arch and toolbar.
|
|
|
|
|
"""
|
2010-03-26 13:27:16 +00:00
|
|
|
|
|
2008-07-26 08:35:54 +00:00
|
|
|
|
res = {}
|
2010-03-26 13:27:16 +00:00
|
|
|
|
res = super(board_board, self).fields_view_get(cr, user, view_id, view_type,\
|
|
|
|
|
context, toolbar=toolbar, submenu=submenu)
|
2009-11-27 09:25:21 +00:00
|
|
|
|
|
2010-03-26 13:27:16 +00:00
|
|
|
|
vids = self.pool.get('ir.ui.view.custom').search(cr, user,\
|
|
|
|
|
[('user_id', '=', user), ('ref_id' ,'=', view_id)])
|
2008-07-26 08:35:54 +00:00
|
|
|
|
if vids:
|
|
|
|
|
view_id = vids[0]
|
2010-11-19 13:48:01 +00:00
|
|
|
|
arch = self.pool.get('ir.ui.view.custom').browse(cr, user, view_id, context=context)
|
2011-06-01 10:38:02 +00:00
|
|
|
|
res['custom_view_id'] = view_id
|
2008-08-06 13:52:05 +00:00
|
|
|
|
res['arch'] = arch.arch
|
2010-12-30 15:03:40 +00:00
|
|
|
|
res['arch'] = self._arch_preprocessing(cr, user, res['arch'], context=context)
|
2010-03-17 10:22:07 +00:00
|
|
|
|
res['toolbar'] = {'print': [], 'action': [], 'relate': []}
|
2008-07-22 15:11:28 +00:00
|
|
|
|
return res
|
2011-11-15 07:06:00 +00:00
|
|
|
|
|
|
|
|
|
def _arch_preprocessing(self, cr, user, arch, context=None):
|
|
|
|
|
from lxml import etree
|
2010-12-30 15:03:40 +00:00
|
|
|
|
def remove_unauthorized_children(node):
|
|
|
|
|
for child in node.iterchildren():
|
|
|
|
|
if child.tag=='action' and child.get('invisible'):
|
|
|
|
|
node.remove(child)
|
|
|
|
|
else:
|
|
|
|
|
child=remove_unauthorized_children(child)
|
|
|
|
|
return node
|
2011-11-15 07:06:00 +00:00
|
|
|
|
|
2010-12-30 15:03:40 +00:00
|
|
|
|
def encode(s):
|
|
|
|
|
if isinstance(s, unicode):
|
|
|
|
|
return s.encode('utf8')
|
|
|
|
|
return s
|
2011-11-15 07:06:00 +00:00
|
|
|
|
|
|
|
|
|
archnode = etree.fromstring(encode(arch))
|
2010-12-30 15:03:40 +00:00
|
|
|
|
return etree.tostring(remove_unauthorized_children(archnode),pretty_print=True)
|
2011-11-15 07:06:00 +00:00
|
|
|
|
|
2008-07-22 15:11:28 +00:00
|
|
|
|
_columns = {
|
2010-03-26 13:27:16 +00:00
|
|
|
|
'name': fields.char('Dashboard', size=64, required=True),
|
|
|
|
|
'view_id': fields.many2one('ir.ui.view', 'Board View'),
|
2008-07-22 15:11:28 +00:00
|
|
|
|
}
|
2009-11-27 09:25:21 +00:00
|
|
|
|
|
2009-01-03 09:17:06 +00:00
|
|
|
|
# the following lines added to let the button on dashboard work.
|
|
|
|
|
_defaults = {
|
2010-03-26 13:27:16 +00:00
|
|
|
|
'name':lambda *args: 'Dashboard'
|
2009-01-03 09:17:06 +00:00
|
|
|
|
}
|
2009-11-27 09:25:21 +00:00
|
|
|
|
|
2008-07-23 14:41:47 +00:00
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|