Exemplo n.º 1
0
    def import_lang(self):
        this = self[0]
        this = this.with_context(overwrite=this.overwrite)
        with TemporaryFile('wb+') as buf:
            try:
                buf.write(base64.decodestring(this.data))

                # now we determine the file format
                buf.seek(0)
                fileformat = os.path.splitext(this.filename)[-1][1:].lower()

                tools.trans_load_data(this._cr,
                                      buf,
                                      fileformat,
                                      this.code,
                                      lang_name=this.name,
                                      context=this._context)
            except Exception as e:
                _logger.exception(
                    'File unsuccessfully imported, due to format mismatch.')
                raise UserError(
                    _('File %r not imported due to format mismatch or a malformed file.'
                      ' (Valid formats are .csv, .po, .pot)\n\nTechnical Details:\n%s') % \
                    (this.filename, tools.ustr(e))
                )
        return True
Exemplo n.º 2
0
    def import_lang(self):
        this = self[0]
        with TemporaryFile('wb+') as buf:
            try:
                buf.write(base64.decodebytes(this.data))

                # now we determine the file format
                buf.seek(0)
                fileformat = os.path.splitext(this.filename)[-1][1:].lower()

                Lang = self.env["res.lang"]
                lang = Lang._activate_lang(self.code) or Lang._create_lang(
                    self.code, lang_name=self.name
                )

                tools.trans_load_data(
                    this._cr, buf, fileformat, this.code, overwrite=self.overwrite
                )
            except ProgrammingError as e:
                _logger.exception('File unsuccessfully imported, due to a malformed file.')

                with closing(sql_db.db_connect(self._cr.dbname).cursor()) as cr:
                    raise UserError(_('File %r not imported due to a malformed file.\n\n'
                                      'This issue can be caused by duplicates entries who are referring to the same field. '
                                      'Please check the content of the file you are trying to import.\n\n'
                                      'Technical Details:\n%s') % (self.filename, tools.ustr(e)))
            except Exception as e:
                _logger.exception('File unsuccessfully imported, due to format mismatch.')
                raise UserError(
                    _('File %r not imported due to format mismatch or a malformed file.'
                      ' (Valid formats are .csv, .po, .pot)\n\nTechnical Details:\n%s') % \
                    (this.filename, tools.ustr(e))
                )
        return True
Exemplo n.º 3
0
 def act_update(self):
     this = self[0]
     lang_name = self._get_lang_name(this.lang)
     with contextlib.closing(io.BytesIO()) as buf:
         tools.trans_export(this.lang, ['all'], buf, 'csv', self._cr)
         tools.trans_load_data(self._cr, buf, 'csv', this.lang, lang_name=lang_name)
     return {'type': 'ir.actions.act_window_close'}
Exemplo n.º 4
0
 def act_update(self):
     this = self[0]
     lang_name = self._get_lang_name(this.lang)
     with tempfile.NamedTemporaryFile() as buf:
         tools.trans_export(this.lang, ['all'], buf, 'po', self._cr)
         tools.trans_load_data(self._cr, buf, 'po', this.lang, lang_name=lang_name)
     return {'type': 'ir.actions.act_window_close'}
Exemplo n.º 5
0
 def act_update(self):
     this = self[0]
     lang_name = self._get_lang_name(this.lang)
     with tempfile.NamedTemporaryFile() as buf:
         tools.trans_export(this.lang, ['all'], buf, 'po', self._cr)
         context = {'create_empty_translation': True}
         tools.trans_load_data(self._cr, buf, 'po', this.lang, lang_name=lang_name, context=context)
     return {'type': 'ir.actions.act_window_close'}
Exemplo n.º 6
0
 def act_update(self):
     with tempfile.NamedTemporaryFile() as buf:
         tools.trans_export(self.lang, ['all'], buf, 'po', self._cr)
         tools.trans_load_data(self._cr,
                               buf,
                               'po',
                               self.lang,
                               create_empty_translation=True)
     return {'type': 'ir.actions.act_window_close'}
 def act_update(self):
     this = self[0]
     lang_name = self._get_lang_name(this.lang)
     with contextlib.closing(io.BytesIO()) as buf:
         tools.trans_export(this.lang, ['all'], buf, 'csv', self._cr)
         tools.trans_load_data(self._cr,
                               buf,
                               'csv',
                               this.lang,
                               lang_name=lang_name)
     return {'type': 'ir.actions.act_window_close'}
 def act_update(self):
     this = self[0]
     lang_name = self._get_lang_name(this.lang)
     with tempfile.NamedTemporaryFile() as buf:
         tools.trans_export(this.lang, ['all'], buf, 'tgz', self._cr)
         context = {'create_empty_translation': True}
         buf.seek(0)
         tar = tarfile.open(fileobj=buf)
         for file_info in tar:
             module_file = tar.extractfile(file_info)
             tools.trans_load_data(self._cr, module_file, 'po', this.lang, lang_name=lang_name,
                                   module_name=file_info.name.partition('/')[0], context=context)
         tar.close()
     return {'type': 'ir.actions.act_window_close'}
Exemplo n.º 9
0
    def import_lang(self):
        this = self[0]
        this = this.with_context(overwrite=this.overwrite)
        with TemporaryFile('wb+') as buf:
            try:
                buf.write(base64.decodestring(this.data))

                # now we determine the file format
                buf.seek(0)
                fileformat = os.path.splitext(this.filename)[-1][1:].lower()

                tools.trans_load_data(this._cr, buf, fileformat, this.code,
                                      lang_name=this.name, context=this._context)
            except Exception as e:
                _logger.exception('File unsuccessfully imported, due to format mismatch.')
                raise UserError(_('File not imported due to format mismatch or a malformed file. (Valid formats are .csv, .po, .pot)\n\nTechnical Details:\n%s') % tools.ustr(e))
        return True
Exemplo n.º 10
0
                               default=True,
                               help="If you enable this option, existing translations (including custom ones) "
                                    "will be overwritten and replaced by those in this file")

    def import_lang(self):
        this = self[0]
        with TemporaryFile('wb+') as buf:
            try:
                buf.write(base64.decodebytes(this.data))

                # now we determine the file format
                buf.seek(0)
                fileformat = os.path.splitext(this.filename)[-1][1:].lower()

<<<<<<< HEAD
                tools.trans_load_data(this._cr, buf, fileformat, this.code,
                                      lang_name=this.name, context=this._context)
=======
                Lang = self.env["res.lang"]
                lang = Lang._activate_lang(self.code) or Lang._create_lang(
                    self.code, lang_name=self.name
                )

                tools.trans_load_data(
                    this._cr, buf, fileformat, this.code, overwrite=self.overwrite
                )
>>>>>>> f0a66d05e70e432d35dc68c9fb1e1cc6e51b40b8
            except ProgrammingError as e:
                _logger.exception('File unsuccessfully imported, due to a malformed file.')

                with closing(sql_db.db_connect(self._cr.dbname).cursor()) as cr:
<<<<<<< HEAD