[IMP] in the portal's contact form, only show the 'email' field to anonymous users
[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=None):
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         if context is None:
43             context = {}
44         obj_wiki_group = self.pool.get('wiki.groups')
45         obj_view = self.pool.get('ir.ui.view')
46         obj_menu = self.pool.get('ir.ui.menu')
47         obj_action = self.pool.get('ir.actions.act_window')
48         group_id = context.get('active_id', False)
49         if not group_id:
50             return {}
51
52         datas = self.browse(cr, uid, ids, context=context)
53         data = False
54         if datas:
55             data = datas[0]
56         if not data:
57             return {}
58         value = {            
59             'name': 'Wiki Page',
60             'view_type': 'form',
61             'view_mode': 'form,tree',
62             'res_model': 'wiki.wiki',
63             'view_id': False,
64             'type': 'ir.actions.act_window',
65             'nodestroy': True,
66         }
67         group = obj_wiki_group.browse(cr, uid, group_id, context=context)
68         value['domain'] = "[('group_id','=',%d)]" % (group.id)
69         if group.method == 'page':
70             value['res_id'] = group.home.id
71         elif group.method == 'list':
72             value['view_type'] = 'form'
73             value['view_mode'] = 'tree,form'
74         elif group.method == 'tree':
75             view_id = obj_view.search(cr, uid, [('name', '=', 'wiki.wiki.tree.children')])
76             value['view_id'] = view_id
77             value['domain'] = [('group_id', '=', group.id), ('parent_id', '=', False)]
78             value['view_type'] = 'tree'
79
80         action_id = obj_action.create(cr, uid, value)
81             
82         menu_id = obj_menu.create(cr, uid, {
83                         'name': data.menu_name,
84                         'parent_id':data.menu_parent_id.id,
85                         'icon': 'STOCK_DIALOG_QUESTION',
86                         'action': 'ir.actions.act_window,'+ str(action_id),
87                         }, context)
88         obj_wiki_group.write(cr, uid, [group_id], {'menu_id':menu_id})        
89         return {'type':  'ir.actions.act_window_close'}
90
91
92 wiki_create_menu()
93
94 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: