1 # -*- coding: utf-8 -*-
2 from xml.etree import ElementTree
5 import openerp.addons.web.common.http as openerpweb
6 from openerp.addons.web.common import nonliterals
7 from openerp.addons.web.controllers.main import load_actions_from_ir_values
9 import web.common.http as openerpweb # noqa
10 from web.common import nonliterals # noqa
11 from web.controllers.main import load_actions_from_ir_values # noqa
13 class Board(openerpweb.Controller):
16 @openerpweb.jsonrequest
17 def add_to_dashboard(self, req, menu_id, action_id, context_to_save, domain, view_mode, name=''):
18 # FIXME move this method to board.board model
19 to_eval = nonliterals.CompoundContext(context_to_save)
20 to_eval.session = req.session
21 ctx = dict((k, v) for k, v in to_eval.evaluate().iteritems()
22 if not k.startswith('search_default_'))
23 ctx['dashboard_merge_domains_contexts'] = False # TODO: replace this 6.1 workaround by attribute on <action/>
24 domain = nonliterals.CompoundDomain(domain)
25 domain.session = req.session
26 domain = domain.evaluate()
28 dashboard_action = load_actions_from_ir_values(req, 'action', 'tree_but_open', [('ir.ui.menu', menu_id)], False)
31 action = dashboard_action[0][2]
32 if action['res_model'] == 'board.board' and action['views'][0][1] == 'form':
33 # Maybe should check the content instead of model board.board ?
34 view_id = action['views'][0][0]
35 board = req.session.model(action['res_model']).fields_view_get(view_id, 'form')
36 if board and 'arch' in board:
37 xml = ElementTree.fromstring(board['arch'])
38 column = xml.find('./board/column')
39 if column is not None:
40 new_action = ElementTree.Element('action', {
41 'name': str(action_id),
43 'view_mode': view_mode,
47 column.insert(0, new_action)
48 arch = ElementTree.tostring(xml, 'utf-8')
49 return req.session.model('ir.ui.view.custom').create({
50 'user_id': req.session._uid,
53 }, req.session.eval_context(req.context))