merge
[odoo/odoo.git] / addons / web_uservoice / web / controllers.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #    
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2010 OpenERP s.a. (<http://openerp.com>).
6 #
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.
11 #
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.
16 #
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/>.     
19 #
20 ##############################################################################
21
22 from openerp.controllers import SecuredController
23 from openobject import rpc
24 from openobject.tools import expose
25 import cherrypy
26
27 class Root(SecuredController):
28
29     _cp_path = "/openerp"
30
31     @expose(mark_only=True)
32     def menu(self, active=None, next=None):
33         try:
34             menu_id = int(active)
35         except (TypeError, ValueError):
36             menu_id = False
37
38         menus = rpc.RPCProxy("ir.ui.menu")
39         ids = menus.search([('parent_id', '=', False)])
40         if next or active:
41             if not menu_id and ids:
42                 menu_id = ids[0]
43
44         menu = ''
45         if menu_id:
46             ctx = dict(lang='NO_LANG')  # force loading original string even if the english have been translated...
47             menu = menus.read([menu_id], ['name'], ctx)[0]['name'] or ''
48
49         general_forum = 77459
50         forum = {
51             'accounting': 87921,
52             'administration': 87935,
53             'human resources': 87923,
54             'knowledge': 87927,
55             'manufacturing': 87915,
56             'marketing': 87925,
57             'point of sale': 87929,
58             'project': 87919,
59             'purchases': 87911,
60             'sales': 87907,
61             'tools': 87933,
62             'warehouse': 87913,
63         }.get(menu.lower().strip(), general_forum)
64
65         cherrypy.request.uservoice_forum = forum
66         return super(Root, self).menu(active, next)
67
68