From a98649d044ac27b8892461108ba781a569d321a4 Mon Sep 17 00:00:00 2001 From: "ksa (Open ERP)" Date: Fri, 27 Aug 2010 12:31:48 +0530 Subject: [PATCH 1/5] [IMP]: convert language import wizard into osv memory wizard bzr revid: ksa@tinyerp.co.in-20100827070148-ts1oxuq4ip8j2nh2 --- bin/addons/base/__openerp__.py | 1 + bin/addons/base/module/module_wizard.xml | 6 -- bin/addons/base/module/wizard/__init__.py | 2 +- .../module/wizard/base_import_language.py | 63 +++++++++++++ .../wizard/base_import_language_view.xml | 53 +++++++++++ .../base/module/wizard/wizard_import_lang.py | 90 ------------------- 6 files changed, 118 insertions(+), 97 deletions(-) create mode 100644 bin/addons/base/module/wizard/base_import_language.py create mode 100644 bin/addons/base/module/wizard/base_import_language_view.xml delete mode 100644 bin/addons/base/module/wizard/wizard_import_lang.py diff --git a/bin/addons/base/__openerp__.py b/bin/addons/base/__openerp__.py index 2592ed1bf00..ee6380512b8 100644 --- a/bin/addons/base/__openerp__.py +++ b/bin/addons/base/__openerp__.py @@ -51,6 +51,7 @@ 'module/wizard/base_module_import_view.xml', 'module/wizard/base_module_update_view.xml', 'module/wizard/base_language_install_view.xml', + 'module/wizard/base_import_language_view.xml', 'res/res_request_view.xml', 'res/res_lang_view.xml', 'res/res_log_view.xml', diff --git a/bin/addons/base/module/module_wizard.xml b/bin/addons/base/module/module_wizard.xml index 341547c96a4..fd7850a02f8 100644 --- a/bin/addons/base/module/module_wizard.xml +++ b/bin/addons/base/module/module_wizard.xml @@ -55,12 +55,6 @@ - - Import a Translation File - module.lang.import - - - Update Translations wizard.module.update_translations diff --git a/bin/addons/base/module/wizard/__init__.py b/bin/addons/base/module/wizard/__init__.py index e43bbbdca07..45234a2446e 100644 --- a/bin/addons/base/module/wizard/__init__.py +++ b/bin/addons/base/module/wizard/__init__.py @@ -23,12 +23,12 @@ import wizard_module_upgrade import wizard_configuration import add_new import wizard_export_lang -import wizard_import_lang import wizard_update_translations import base_module_import import base_module_update import base_language_install +import base_import_language # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/bin/addons/base/module/wizard/base_import_language.py b/bin/addons/base/module/wizard/base_import_language.py new file mode 100644 index 00000000000..ca45c0a6c1c --- /dev/null +++ b/bin/addons/base/module/wizard/base_import_language.py @@ -0,0 +1,63 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 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 pooler +from tempfile import TemporaryFile +from osv import osv, fields + +class base_language_import(osv.osv_memory): + """ Language Import """ + + _name = "base.language.import" + _description = "Language Import" + + _columns = { + 'name': fields.char('Language Name',size=64 , required=True), + 'code': fields.char('Code (eg:en__US)',size=5 , required=True), + 'data': fields.binary('File', required=True), + } + + def import_lang(self, cr, uid, ids, context): + """ + Import Language + @param cr: the current row, from the database cursor. + @param uid: the current user’s ID for security checks. + @param ids: the ID or list of IDs + @param context: A standard dictionary + """ + + import_data = self.browse(cr, uid, ids)[0] + fileobj = TemporaryFile('w+') + fileobj.write(base64.decodestring(import_data.data)) + + # now we determine the file format + fileobj.seek(0) + first_line = fileobj.readline().strip().replace('"', '').replace(' ', '') + fileformat = first_line.endswith("type,name,res_id,src,value") and 'csv' or 'po' + fileobj.seek(0) + + tools.trans_load_data(cr.dbname, fileobj, fileformat, import_data.code, lang_name=import_data.name) + fileobj.close() + return {} + +base_language_import() \ No newline at end of file diff --git a/bin/addons/base/module/wizard/base_import_language_view.xml b/bin/addons/base/module/wizard/base_import_language_view.xml new file mode 100644 index 00000000000..799ff4e9179 --- /dev/null +++ b/bin/addons/base/module/wizard/base_import_language_view.xml @@ -0,0 +1,53 @@ + + + + + + Import Language + base.language.import + form + +
+ + + + + + + + + + + + + + +