85d01779842f95f85f07b03dbc4eb3145227bfd0
[odoo/odoo.git] / addons / base_setup / __init__.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 import installer
23 import todo
24 import wizard
25 import os
26 import base64
27 import random
28 import tools
29 from osv import fields, osv
30 import netsvc
31 from tools.translate import _
32
33 class base_setup_config_choice(osv.osv_memory):
34     """
35     """
36     _name = 'base.setup.config'
37     logger = netsvc.Logger()
38
39     def _get_image(self, cr, uid, context=None):
40         file_no = str(random.randint(1,3))
41         path = os.path.join('base','res','config_pixmaps/%s.png'%file_no)
42         file_data = tools.file_open(path,'rb').read()
43         return base64.encodestring(file_data)
44
45     def get_users(self, cr, uid, context=None):
46         user_obj = self.pool.get('res.users')
47         user_ids = user_obj.search(cr, uid, [])
48         users = user_obj.browse(cr, uid, user_ids, context=context)
49         user_str = '\n'.join(map(lambda x: '    - %s :\n\t\tLogin : %s \n\t\tPassword : %s' % (x.name, x.login, x.password), users))
50         return _('The following users have been installed : \n')+ user_str
51
52     _columns = {
53         'installed_users':fields.text('Installed Users', readonly=True),
54         'config_logo' : fields.binary('Image', readonly=True),
55         }
56
57     _defaults = {
58         'installed_users':get_users,
59          'config_logo' : _get_image
60         }
61
62     def reset_menu(self, cr, uid, context=None):
63         user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
64         menu_id = user._get_menu()
65         user.write({'action_id': False,
66                     'menu_id': menu_id})
67         return self.pool.get('ir.actions.act_window').browse(cr, uid, menu_id, context=context)
68
69     def menu(self, cr, uid, ids, context=None):
70         menu = self.reset_menu(cr, uid, context=context)
71
72         if menu.view_id.id:
73             view_id = (menu.view_id.id, menu.view_id.name)
74         else:
75             view_id = False
76
77         return {
78             'name': menu.name,
79             'type': menu.type,
80             'view_id': view_id,
81             'domain': menu.domain,
82             'res_model': menu.res_model,
83             'src_model': menu.src_model,
84             'view_type': menu.view_type,
85             'view_mode': menu.view_mode,
86             'views': menu.views,
87         }
88
89     def config(self, cr, uid, ids, context=None):
90         self.reset_menu(cr, uid, context=context)
91         return self.pool.get('res.config').next(cr, uid, [], context=context)
92
93 base_setup_config_choice()
94
95
96 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
97