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