From 99b7f4463c25ef2a2df6f0d801603b715431f424 Mon Sep 17 00:00:00 2001 From: "ksa (Open ERP)" Date: Mon, 30 Aug 2010 18:58:16 +0530 Subject: [IMP]: Improve old wizard into osv memoery wizard bzr revid: ksa@tinyerp.co.in-20100830132816-4riit83jw7y2lghz --- .../base/module/wizard/base_export_language.py | 88 ++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 bin/addons/base/module/wizard/base_export_language.py (limited to 'bin/addons/base/module/wizard/base_export_language.py') diff --git a/bin/addons/base/module/wizard/base_export_language.py b/bin/addons/base/module/wizard/base_export_language.py new file mode 100644 index 00000000000..ca4f9a0d116 --- /dev/null +++ b/bin/addons/base/module/wizard/base_export_language.py @@ -0,0 +1,88 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2009 Tiny SPRL (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +import tools +import base64 +import cStringIO +import pooler +from osv import fields,osv +from tools.translate import _ +from tools.misc import get_iso_codes + +class base_export_language(osv.osv_memory): + + def _get_languages(self, cr, uid, context): + lang_obj=pooler.get_pool(cr.dbname).get('res.lang') + ids=lang_obj.search(cr, uid, ['&', ('active', '=', True), ('translatable', '=', True),]) + langs=lang_obj.browse(cr, uid, ids) + return [(lang.code, lang.name) for lang in langs] + + def act_cancel(self, cr, uid, ids, context=None): + #self.unlink(cr, uid, ids, context) + return {'type':'ir.actions.act_window_close' } + + def act_destroy(self, *args): + return {'type':'ir.actions.act_window_close' } + + def act_getfile(self, cr, uid, ids, context=None): + this = self.browse(cr, uid, ids)[0] + mods = map(lambda m: m.name, this.modules) or ['all'] + mods.sort() + buf=cStringIO.StringIO() + tools.trans_export(this.lang, mods, buf, this.format, dbname=cr.dbname) + if this.format == 'csv': + this.advice = _("Save this document to a .CSV file and open it with your favourite spreadsheet software. The file encoding is UTF-8. You have to translate the latest column before reimporting it.") + elif this.format == 'po': + if not this.lang: + this.format = 'pot' + this.advice = _("Save this document to a %s file and edit it with a specific software or a text editor. The file encoding is UTF-8.") % ('.'+this.format,) + elif this.format == 'tgz': + ext = this.lang and '.po' or '.pot' + this.advice = _('Save this document to a .tgz file. This archive containt UTF-8 %s files and may be uploaded to launchpad.') % (ext,) + filename = _('new') + if not this.lang and len(mods) == 1: + filename = mods[0] + if this.lang: + filename = get_iso_codes(this.lang) + this.name = "%s.%s" % (filename, this.format) + out=base64.encodestring(buf.getvalue()) + buf.close() + return self.write(cr, uid, ids, {'state':'get', 'data':out, 'advice':this.advice, 'name':this.name}, context=context) + + _name = "base.export.language" + _columns = { + 'name': fields.char('Filename', 16, readonly=True), + 'lang': fields.selection(_get_languages, 'Language', help='To export a new language, do not select a language.'), # not required: unset = new language + 'format': fields.selection( ( ('csv','CSV File'), ('po','PO File'), ('tgz', 'TGZ Archive')), 'File Format', required=True), + 'modules': fields.many2many('ir.module.module', 'rel_modules_langexport', 'wiz_id', 'module_id', 'Modules', domain=[('state','=','installed')]), + 'data': fields.binary('File', readonly=True), + 'advice': fields.text('Advice', readonly=True), + 'state': fields.selection( ( ('choose','choose'), # choose language + ('get','get'), # get the file + ) ), + } + _defaults = { 'state': lambda *a: 'choose', + 'name': lambda *a: 'lang.tar.gz' + } +base_export_language() + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: + -- cgit v1.2.3 From cd527b6c9d3a7337ae689b54325a1bb574b3b285 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Mon, 4 Oct 2010 16:33:36 +0200 Subject: [IMP] base: refactor/unify base module wizards bzr revid: odo@openerp.com-20101004143336-nh0vnvbipt5dvmna --- bin/addons/base/module/wizard/base_export_language.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'bin/addons/base/module/wizard/base_export_language.py') diff --git a/bin/addons/base/module/wizard/base_export_language.py b/bin/addons/base/module/wizard/base_export_language.py index ca2e3059cfb..1b43b561ac3 100644 --- a/bin/addons/base/module/wizard/base_export_language.py +++ b/bin/addons/base/module/wizard/base_export_language.py @@ -68,6 +68,7 @@ class base_language_export(osv.osv_memory): return self.write(cr, uid, ids, {'state':'get', 'data':out, 'advice':this.advice, 'name':this.name}, context=context) _name = "base.language.export" + _inherit = "ir.wizard.screen" _columns = { 'name': fields.char('Filename', 16, readonly=True), 'lang': fields.selection(_get_languages, 'Language', help='To export a new language, do not select a language.'), # not required: unset = new language @@ -78,11 +79,11 @@ class base_language_export(osv.osv_memory): 'state': fields.selection( ( ('choose','choose'), # choose language ('get','get'), # get the file ) ), - } - _defaults = { 'state': lambda *a: 'choose', - 'name': lambda *a: 'lang.tar.gz' - } + } + _defaults = { + 'state': lambda *a: 'choose', + 'name': lambda *a: 'lang.tar.gz' + } base_language_export() -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: - +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file -- cgit v1.2.3