[FIX] res.partner.category: the relation table name was manually chosen, which breaks...
[odoo/odoo.git] / openerp / addons / base / module / wizard / base_update_translations.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2009 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 osv, fields
23 import tools
24 import pooler
25 import cStringIO
26 from tools.translate import _
27
28 class base_update_translations(osv.osv_memory):
29     def _get_languages(self, cr, uid, context):
30         lang_obj=pooler.get_pool(cr.dbname).get('res.lang')
31         ids=lang_obj.search(cr, uid, ['&', ('active', '=', True), ('translatable', '=', True),])
32         langs=lang_obj.browse(cr, uid, ids)
33         return [(lang.code, lang.name) for lang in langs]
34
35     def _get_lang_name(self, cr, uid, lang_code):
36         lang_obj=pooler.get_pool(cr.dbname).get('res.lang')
37         ids=lang_obj.search(cr, uid, [('code', '=', lang_code)])
38         if not ids:
39             raise osv.except_osv(_('Error!'), _('No language with code "%s" exists') % lang_code)
40         lang = lang_obj.browse(cr, uid, ids[0])
41         return lang.name
42     def act_cancel(self, cr, uid, ids, context=None):
43         return {'type': 'ir.actions.act_window_close'}
44
45     def act_update(self, cr, uid, ids, context=None):
46         this = self.browse(cr, uid, ids)[0]
47         lang_name = self._get_lang_name(cr, uid, this.lang)
48         buf=cStringIO.StringIO()
49         tools.trans_export(this.lang, ['all'], buf, 'csv', cr)
50         tools.trans_load_data(cr, buf, 'csv', this.lang, lang_name=lang_name)
51         buf.close()
52         return {'type': 'ir.actions.act_window_close'}
53
54     def default_get(self, cr, uid, fields, context=None):
55         if context is None:
56             context = {}
57         res = super(base_update_translations, self).default_get(cr, uid, fields, context=context)
58         
59         if context.get('active_model') != "res.lang":
60             return res
61         
62         record_id = context.get('active_id', False) or False
63         if record_id:
64             lang = self.pool.get('res.lang').browse(cr, uid, record_id).code
65             res.update(lang=lang)
66         return res
67
68     _name = 'base.update.translations'
69     _inherit = "ir.wizard.screen"
70     _columns = {
71         'lang': fields.selection(_get_languages, 'Language', required=True),
72     }
73
74 base_update_translations()
75
76 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: