improve config wizard labels
[odoo/odoo.git] / addons / board / controllers.py
1 # -*- coding: utf-8 -*-
2 from xml.etree import ElementTree
3
4 try:
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
8 except ImportError:
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
12
13 class Board(openerpweb.Controller):
14     _cp_path = '/board'
15
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()
27
28         dashboard_action = load_actions_from_ir_values(req, 'action', 'tree_but_open', [('ir.ui.menu', menu_id)], False)
29
30         if dashboard_action:
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),
42                             'string': name,
43                             'view_mode': view_mode,
44                             'context': str(ctx),
45                             'domain': str(domain)
46                         })
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,
51                             'ref_id': view_id,
52                             'arch': arch
53                         }, req.session.eval_context(req.context))
54
55         return False