Example #1
0
    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,
                              fileobj,
                              fileformat,
                              import_data.code,
                              lang_name=import_data.name)
        tools.trans_update_res_ids(cr)
        fileobj.close()
        return {}
    def import_lang(self, cr, uid, ids, context=None):
        """
            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
        """
        if context is None:
            context = {}
        import_data = self.browse(cr, uid, ids)[0]
        if import_data.overwrite:
            context.update(overwrite=True)
        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, fileobj, fileformat, import_data.code, lang_name=import_data.name, context=context)
        fileobj.close()
        return {}
 def act_update(self, cr, uid, ids, context=None):
     this = self.browse(cr, uid, ids)[0]
     lang_name = self._get_lang_name(cr, uid, this.lang)
     buf=cStringIO.StringIO()
     tools.trans_export(this.lang, ['all'], buf, 'csv', dbname=cr.dbname)
     tools.trans_load_data(cr.dbname, buf, 'csv', this.lang, lang_name=lang_name)
     buf.close()
     return {'type': 'ir.actions.act_window_close'}
Example #4
0
 def act_update(self, cr, uid, ids, context=None):
     this = self.browse(cr, uid, ids)[0]
     lang_name = self._get_lang_name(cr, uid, this.lang)
     buf = cStringIO.StringIO()
     tools.trans_export(this.lang, ['all'], buf, 'csv', cr)
     tools.trans_load_data(cr, buf, 'csv', this.lang, lang_name=lang_name)
     buf.close()
     return {'type': 'ir.actions.act_window_close'}
Example #5
0
    def _import(self, dbname, uid, ids, context=None):
        try:
            cr = pooler.get_db(dbname).cursor()
            import_data = self.browse(cr, uid, ids)[0]
            (fileobj, fileformat) = lang_tools.get_data_file(cr, uid, import_data.data)
            if fileformat == 'xml':
                fileformat = 'csv'
            else:
                first_line = fileobj.readline().strip().replace('"', '').replace(' ', '')
                fileformat = first_line.endswith("type,name,res_id,src,value") and 'csv' or 'po'
                fileobj.seek(0)

            lang_obj = self.pool.get('res.lang')
            lang_ids = lang_obj.search(cr, uid, [('code', '=', import_data.name)])
            if lang_ids:
                lang_data = lang_obj.read(cr, uid, lang_ids[0], ['translatable'])
                if not lang_data['translatable']:
                    lang_obj.write(cr, uid, [lang_ids[0]], {'translatable': True})


            tools.trans_load_data(cr, fileobj, fileformat, import_data.code, lang_name=import_data.name, context={'overwrite': 1})
            tools.trans_update_res_ids(cr)
            fileobj.close()

            req_id = self.pool.get('res.request').create(cr, uid, {
                'name': _('Translation file imported'),
                'act_from': uid,
                'act_to': uid,
                'import_trans': True,
                'body': _('Your translation file has been successfully imported.')
            })
            if req_id:
                self.pool.get('res.request').request_send(cr, uid, [req_id])

            self.write(cr, uid, [ids[0]], {'data': ''})
            tools.cache.clean_caches_for_db(cr.dbname)
            cr.commit()
            cr.close(True)
        except Exception, e:
            cr.rollback()
            self.write(cr, uid, [ids[0]], {'data': ''})
            req_id = self.pool.get('res.request').create(cr, uid, {
                'name': _('Import translation failed'),
                'act_from': uid,
                'act_to': uid,
                'import_trans': True,
                'body': _('''The process to import the translation file failed !
                %s
                ''')% (e,),
            })
            cr.commit()
            cr.close(True)
            raise
Example #6
0
    def _import_lang(self, cr, uid, data, context):
        form=data['form']
        fileobj = TemporaryFile('w+')
        fileobj.write( base64.decodestring(form['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, form['code'], lang_name=form['name'])
        fileobj.close()
        return {}
 def import_lang(self, cr, uid, ids, context=None):
     if context is None:
         context = {}
     this = self.browse(cr, uid, ids[0])
     if this.overwrite:
         context.update(overwrite=True)
     fileobj = TemporaryFile('w+')
     try:
         fileobj.write(base64.decodestring(this.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, fileobj, fileformat, this.code, lang_name=this.name, context=context)
     finally:
         fileobj.close()
     return True
    def import_lang(self, cr, uid, ids, context=None):
        if context is None:
            context = {}
        this = self.browse(cr, uid, ids[0])
        if this.overwrite:
            context.update(overwrite=True)
        fileobj = TemporaryFile("w+")
        try:
            fileobj.write(base64.decodestring(this.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, fileobj, fileformat, this.code, lang_name=this.name, context=context)
        finally:
            fileobj.close()
        return True