def act_getfile(self, cr, uid, ids, context=None): this = self.browse(cr, uid, ids)[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) 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) return { 'type': 'ir.actions.act_window', 'res_model': 'base.language.export', 'view_mode': 'form', 'view_type': 'form', 'res_id': this.id, 'views': [(False, 'form')], 'target': 'new', }
def act_getfile(self, cr, uid, ids, context=None): this = self.browse(cr, uid, ids)[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) 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) return { 'type': 'ir.actions.act_window', 'res_model': 'base.language.export', 'view_mode': 'form', 'view_type': 'form', 'res_id': this.id, 'views': [(False, 'form')], 'target': 'new', }
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)
def _export(self, dbname, uid, ids, context=None): #modules = ['account_mcdb'] modules = 'all_installed' try: cr = pooler.get_db(dbname).cursor() this = self.browse(cr, uid, ids)[0] if this.modules: modules = map(lambda m: m.name, this.modules) modules.sort() if this.lang: filename = get_iso_codes(this.lang) this.name = "%s.%s" % (filename, this.format) ignore_name = ['ir.filters,model_id', 'ir.actions.server,copy_object', 'ir.ui.menu,icon', 'ir.sequence,code', 'stock.location,icon'] if this.format == 'xls': trans = tools.trans_generate(this.lang, modules, cr, ignore_name=ignore_name) if trans: headers = [] for h in trans.pop(0): headers.append([h, 'char']) xml = SpreadsheetCreator(title=this.name, headers=headers, datas=trans) out = base64.encodestring(xml.get_xml(default_filters=['decode.utf8'])) else: buf=cStringIO.StringIO() tools.trans_export(this.lang, modules, buf, this.format, cr, ignore_name=ignore_name) out = base64.encodestring(buf.getvalue()) buf.close() subject = _("Export translation %s %s ") % (this.lang, this.format) summary = _('''Export translation %s %s Find the file in attachment in the right panel.''') % (this.lang, this.format) request_obj = self.pool.get('res.request') req_id = request_obj.create(cr, uid, { 'name': subject, 'act_from': uid, 'act_to': uid, 'export_trans': True, 'body': summary, }) if req_id: request_obj.request_send(cr, uid, [req_id]) attachment = self.pool.get('ir.attachment') attachment.create(cr, uid, { 'name': this.name, 'datas_fname': this.name, 'description': 'Translations', 'res_model': 'res.request', 'res_id': req_id, 'datas': out, }) cr.commit() cr.close(True) except Exception, e: cr.rollback() req_id = self.pool.get('res.request').create(cr, uid, { 'name': _('Export translation failed'), 'act_from': uid, 'act_to': uid, 'export_trans': True, 'body': _('''The process to export the translations failed ! %s ''')% (e,), }) cr.commit() cr.close(True) raise