1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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.
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.
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/>.
20 ##############################################################################
24 import gtk_contact_form
30 from osv import fields, osv
32 from tools.translate import _
34 class base_setup_config_choice(osv.osv_memory):
37 _name = 'base.setup.config'
38 logger = netsvc.Logger()
40 def _get_image(self, cr, uid, context=None):
41 file_no = str(random.randint(1,3))
42 path = os.path.join('base','res','config_pixmaps/%s.png'%file_no)
43 file_data = tools.file_open(path,'rb').read()
44 return base64.encodestring(file_data)
46 def get_users(self, cr, uid, context={}):
47 user_obj = self.pool.get('res.users')
48 user_ids = user_obj.search(cr, uid, [])
49 users = user_obj.browse(cr, uid, user_ids)
50 user_str = '\n'.join(map(lambda x: ' - %s: %s / %s' % (x.name, x.login, x.password), users))
51 return _('The following users have been installed : \n')+ user_str
54 'installed_users':fields.text('Installed Users', readonly=True),
55 'config_logo' : fields.binary('Image', readonly=True),
59 'installed_users':get_users,
60 'config_logo' : _get_image
63 def set_default_menu(self, cr, uid, menu, context=None):
64 user = self.pool.get('res.users')\
65 .browse(cr, uid, uid, context=context)
67 user.write({'action_id': menu.id,
70 def get_default_menu(self, cr, uid, context=None):
71 actions = self.pool.get('ir.actions.act_window')
73 current_menu_id = actions.search(cr, uid, [('name','=','Menu')],
75 assert len(current_menu_id) == 1,\
76 'A given user should only have one menu item'
77 return actions.browse(cr, uid, current_menu_id[0], context=context)
79 def menu(self, cr, uid, ids, context=None):
80 menu = self.get_default_menu(cr, uid, context=context)
81 self.set_default_menu(cr, uid, menu, context=context)
84 view_id = (menu.view_id.id, menu.view_id.name)
92 'domain': menu.domain,
93 'res_model': menu.res_model,
94 'src_model': menu.src_model,
95 'view_type': menu.view_type,
96 'view_mode': menu.view_mode,
100 def config(self, cr, uid, ids, context=None):
101 menu = self.get_default_menu(cr, uid, context=context)
102 self.set_default_menu(cr, uid, menu, context=context)
104 return self.pool.get('res.config').next(cr, uid, [], context=context)
106 base_setup_config_choice()
109 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: