[merge]
[odoo/odoo.git] / addons / wiki / wizard / wiki_create_menu.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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 osv import fields, osv
23
24 class wiki_create_menu(osv.osv_memory):
25     """ Create Menu """
26     _name = "wiki.create.menu"
27     _description = "Wizard Create Menu"
28
29     _columns = {
30         'menu_name': fields.char('Menu Name', size=256, select=True, required=True),
31         'menu_parent_id': fields.many2one('ir.ui.menu', 'Parent Menu', required=True),
32     }
33
34     def wiki_menu_create(self, cr, uid, ids, context):
35
36         """ Create Menu On the base of Group id and Action id
37         @param cr: the current row, from the database cursor,
38         @param uid: the current user’s ID for security checks,
39         @param ids: List of create menu’s IDs
40
41         """
42         obj_wiki_group = self.pool.get('wiki.groups')
43         obj_view = self.pool.get('ir.ui.view')
44         obj_menu = self.pool.get('ir.ui.menu')
45         obj_action = self.pool.get('ir.actions.act_window')
46         group_id = context.get('active_id', False)
47         if not group_id:
48             return {}
49
50         datas = self.browse(cr, uid, ids, context=context)
51         data = False
52         if datas:
53             data = datas[0]
54         if not data:
55             return {}
56         value = {            
57             'name': 'Wiki Page',
58             'view_type': 'form',
59             'view_mode': 'form,tree',
60             'res_model': 'wiki.wiki',
61             'view_id': False,
62             'type': 'ir.actions.act_window',
63             'nodestroy': True,
64         }
65         group = obj_wiki_group.browse(cr, uid, group_id, context=context)
66         value['domain'] = "[('group_id','=',%d)]" % (group.id)
67         if group.method == 'page':
68             value['res_id'] = group.home.id
69         elif group.method == 'list':
70             value['view_type'] = 'form'
71             value['view_mode'] = 'tree,form'
72         elif group.method == 'tree':
73             view_id = obj_view.search(cr, uid, [('name', '=', 'wiki.wiki.tree.childs')])
74             value['view_id'] = view_id
75             value['domain'] = [('group_id', '=', group.id), ('parent_id', '=', False)]
76             value['view_type'] = 'tree'
77
78         action_id = obj_action.create(cr, uid, value)
79             
80         menu_id = obj_menu.create(cr, uid, {
81                         'name': data.menu_name,
82                         'parent_id':data.menu_parent_id.id,
83                         'icon': 'STOCK_DIALOG_QUESTION',
84                         'action': 'ir.actions.act_window,'+ str(action_id),
85                         }, context)
86         obj_wiki_group.write(cr, uid, [group_id], {'menu_id':menu_id})        
87         return {}
88
89
90 wiki_create_menu()
91
92 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: