diff options
| author | Xavier Morel <xmo@openerp.com> | 2014-10-10 13:45:59 +0200 |
|---|---|---|
| committer | Raphael Collet <rco@openerp.com> | 2014-12-02 09:40:58 +0100 |
| commit | f32141017bf0f8eb04d1dfe4c6ac1185ab88aeb5 (patch) | |
| tree | 3aab6a84e65fa2934e3eea46804a1616be643963 /openerp/addons/base/module/wizard/base_export_language.py | |
| parent | 0088bd578b1fcdfe9a3596b5f30e61d3dcd2892a (diff) | |
[IMP] base: language export wizard
* move stuff around
* call write() from browse, correctly pass context to browse
* remove useless default to file name
* use contextlib with stringio
Diffstat (limited to 'openerp/addons/base/module/wizard/base_export_language.py')
| -rw-r--r-- | openerp/addons/base/module/wizard/base_export_language.py | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/openerp/addons/base/module/wizard/base_export_language.py b/openerp/addons/base/module/wizard/base_export_language.py index eb9004b9abe..e76121672af 100644 --- a/openerp/addons/base/module/wizard/base_export_language.py +++ b/openerp/addons/base/module/wizard/base_export_language.py @@ -20,6 +20,7 @@ ############################################################################## import base64 +import contextlib import cStringIO from openerp import tools @@ -51,29 +52,26 @@ class base_language_export(osv.osv_memory): } _defaults = { 'state': 'choose', - 'name': 'lang.tar.gz', 'lang': NEW_LANG_KEY, 'format': 'csv', } def act_getfile(self, cr, uid, ids, context=None): - this = self.browse(cr, uid, ids)[0] + this = self.browse(cr, uid, ids, context=context)[0] lang = this.lang if this.lang != NEW_LANG_KEY else False - mods = map(lambda m: m.name, this.modules) or ['all'] - mods.sort() - buf = cStringIO.StringIO() - tools.trans_export(lang, mods, buf, this.format, cr) + mods = sorted(map(lambda m: m.name, this.modules)) or ['all'] + + with contextlib.closing(cStringIO.StringIO()) as buf: + tools.trans_export(lang, mods, buf, this.format, cr) + out = base64.encodestring(buf.getvalue()) + filename = 'new' if lang: filename = get_iso_codes(lang) elif len(mods) == 1: filename = mods[0] - this.name = "%s.%s" % (filename, this.format) - out = base64.encodestring(buf.getvalue()) - buf.close() - self.write(cr, uid, ids, {'state': 'get', - 'data': out, - 'name':this.name}, context=context) + name = "%s.%s" % (filename, this.format) + this.write({ 'state': 'get', 'data': out, 'name': name }) return { 'type': 'ir.actions.act_window', 'res_model': 'base.language.export', |
