1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-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 osv import fields, osv
26 class board_board(osv.osv):
31 _description = "Board"
33 def create_view(self, cr, uid, ids, context=None):
36 @param cr: the current row, from the database cursor,
37 @param uid: the current user’s ID for security checks,
38 @param ids: List of Board's IDs
39 @return: arch of xml view.
41 board = self.pool.get('board.board').browse(cr, uid, ids, context=context)
45 for line in board.line_ids:
46 linestr = '<action string="%s" name="%d"' % (line.name, line.action_id.id)
48 if line.position == 'left':
53 arch = """<?xml version="1.0"?>
54 <form string="My Board">
63 </form>""" % ('\n'.join(left), '\n'.join(right))
67 def write(self, cr, uid, ids, vals, context=None):
70 Writes values in one or several fields.
71 @param cr: the current row, from the database cursor,
72 @param uid: the current user’s ID for security checks,
73 @param ids: List of Board's IDs
74 @param vals: dictionary with values to update.
75 dictionary must be with the form: {‘name_of_the_field’: value, ...}.
78 result = super(board_board, self).write(cr, uid, ids, vals, context=context)
80 board = self.pool.get('board.board').browse(cr, uid, ids[0], context=context)
81 view = self.create_view(cr, uid, ids[0], context=context)
83 cr.execute("update ir_ui_view set arch=%s where id=%s", (view, id))
86 def create(self, cr, user, vals, context=None):
89 @param cr: the current row, from the database cursor,
90 @param uid: the current user’s ID for security checks,
91 @param vals: dictionary of values for every field.
92 dictionary must use this form: {‘name_of_the_field’: value, ...}
93 @return: id of new created record of board.board.
97 if not 'name' in vals:
99 id = super(board_board, self).create(cr, user, vals, context=context)
100 view_id = self.pool.get('ir.ui.view').create(cr, user, {
101 'name': vals['name'],
102 'model': 'board.board',
105 'arch': self.create_view(cr, user, id, context=context),
108 super(board_board, self).write(cr, user, [id], {'view_id': view_id}, context)
112 def fields_view_get(self, cr, user, view_id=None, view_type='form', context=None,\
113 toolbar=False, submenu=False):
115 Overrides orm field_view_get.
116 @return: Dictionary of Fields, arch and toolbar.
120 res = super(board_board, self).fields_view_get(cr, user, view_id, view_type,\
121 context, toolbar=toolbar, submenu=submenu)
123 vids = self.pool.get('ir.ui.view.custom').search(cr, user,\
124 [('user_id', '=', user), ('ref_id' ,'=', view_id)])
127 arch = self.pool.get('ir.ui.view.custom').browse(cr, user, view_id, context=context)
128 res['custom_view_id'] = view_id
129 res['arch'] = arch.arch
130 res['arch'] = self._arch_preprocessing(cr, user, res['arch'], context=context)
131 res['toolbar'] = {'print': [], 'action': [], 'relate': []}
135 def _arch_preprocessing(self, cr, user, arch, context=None):
136 from lxml import etree
137 def remove_unauthorized_children(node):
138 for child in node.iterchildren():
139 if child.tag=='action' and child.get('invisible'):
142 child=remove_unauthorized_children(child)
146 if isinstance(s, unicode):
147 return s.encode('utf8')
150 archnode = etree.fromstring(encode(arch))
151 return etree.tostring(remove_unauthorized_children(archnode),pretty_print=True)
157 'name': fields.char('Dashboard', size=64, required=True),
158 'view_id': fields.many2one('ir.ui.view', 'Board View'),
159 'line_ids': fields.one2many('board.board.line', 'board_id', 'Action Views')
162 # the following lines added to let the button on dashboard work.
164 'name':lambda *args: 'Dashboard'
167 class board_line(osv.osv):
171 _name = 'board.board.line'
172 _description = "Board Line"
173 _order = 'position,sequence'
175 'name': fields.char('Title', size=64, required=True),
176 'sequence': fields.integer('Sequence', help="Gives the sequence order\
177 when displaying a list of board lines.", select=True),
178 'height': fields.integer('Height'),
179 'width': fields.integer('Width'),
180 'board_id': fields.many2one('board.board', 'Dashboard', required=True, ondelete='cascade'),
181 'action_id': fields.many2one('ir.actions.act_window', 'Action', required=True),
182 'position': fields.selection([('left','Left'),
183 ('right','Right')], 'Position', required=True, select=True)
186 'position': lambda *args: 'left'
189 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: