[IMP]: Improve in gengo_update_translation method
bzr revid: aja@tinyerp.com-20120817062730-r3mfsyinj3acdxqn
This commit is contained in:
@@ -29,7 +29,6 @@ class ir_translation(osv.Model):
|
||||
'gengo_comment': fields.text("Comments"),
|
||||
'gengo_translation': fields.boolean("Translation", help='This term has to be translated by Gengo automatically'),
|
||||
'gengo_control': fields.boolean('Active'),
|
||||
'job_id': fields.char('Gengo Job Id', size=32),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
|
||||
@@ -21,4 +21,5 @@
|
||||
|
||||
import gengo_update_translation
|
||||
import wrap_object
|
||||
import gengo_update_message
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -1,21 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<!-- Update Message Form View -->
|
||||
<record model="ir.ui.view" id="update_translation_wizard_view_confirm">
|
||||
<field name="name">update.translations.serial.wizard.view</field>
|
||||
<field name="inherit_id" ref="base.wizard_update_translations"/>
|
||||
<field name="model">base.update.translations</field>
|
||||
<field name="name">gengo.update.message.form</field>
|
||||
<field name="model">gengo.update.message</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//group" position="inside">
|
||||
<group colspan="4">
|
||||
<field name="state" invisible="1"/>
|
||||
<label string="Your Request has been Successfully Send to Gengo" states="done" colspan="4"/>
|
||||
</group>
|
||||
<group colspan="4">
|
||||
<label string="This language is select as Active All Translation Request will be sent by System Automatically" states="inprogress" colspan="4"/>
|
||||
</group>
|
||||
</xpath>
|
||||
<form string="Update Gengo Data" version="7.0">
|
||||
<group>
|
||||
<field name='name'/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import osv
|
||||
from osv import fields
|
||||
|
||||
|
||||
class gengo_update_message(osv.osv):
|
||||
"""Update Message"""
|
||||
|
||||
_name = "gengo.update.message"
|
||||
_description = "Update Message"
|
||||
_columns = {
|
||||
'name': fields.text('Message', readonly=True),
|
||||
}
|
||||
|
||||
def default_get(self, cr, uid, fields, context=None):
|
||||
if context == None:
|
||||
context = {}
|
||||
res = super(gengo_update_message, self).default_get(cr, uid, fields, context=context)
|
||||
res.update({'name': context.get('message')})
|
||||
return res
|
||||
|
||||
gengo_update_message()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@@ -1,4 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Business Applications
|
||||
@@ -19,8 +19,7 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import osv, fields
|
||||
from tools.translate import _
|
||||
from osv import osv
|
||||
import wrap_object
|
||||
import logging
|
||||
_logger = logging.getLogger(__name__)
|
||||
@@ -55,22 +54,19 @@ class gengo_update_translation(osv.osv_memory):
|
||||
for key in translation_list[total_term:limit]:
|
||||
trans_list.append(key)
|
||||
total_term = limit
|
||||
jobs = meta.pack_jobs_request(cr, uid, trans_list, context={'language_code': context['lang']})
|
||||
result = gengo.postTranslationJobs(jobs=jobs)
|
||||
self.write(cr, uid, ids, {'state': 'done'})
|
||||
request = meta.pack_jobs_request(cr, uid, trans_list, context={'language_code': context['lang']})
|
||||
result = gengo.postTranslationJobs(jobs=request)
|
||||
if user.company_id.gengo_tier == 'machine':
|
||||
if result.get('opstat') == 'ok':
|
||||
for job in result.get('response').get('jobs'):
|
||||
for translation_id, val in job.items():
|
||||
translation_pool.write(cr, uid, int(translation_id), {'value':
|
||||
val['body_tgt'], 'state': 'translated', 'gengo_control': True})
|
||||
else:
|
||||
for job in result.get('response').get('jobs'):
|
||||
for translation_id, val in job.items():
|
||||
translation_pool.write(cr, uid, int(translation_id), {'job_id': val['job_id']})
|
||||
return
|
||||
response = meta.unpack_jobs_response(result)
|
||||
for job in response.response[1]:
|
||||
for jobs in job:
|
||||
translation_term_id = translation_pool.search(cr, uid, [('src', '=', job[jobs]['body_src'])])
|
||||
translation_pool.write(cr, uid, translation_term_id, {'value': job[jobs]['body_tgt'], 'state': 'translated', 'gengo_control': True})
|
||||
return
|
||||
|
||||
def act_update(self, cr, uid, ids, context=None):
|
||||
if context == None:
|
||||
context={}
|
||||
try:
|
||||
language_pool = self.pool.get('res.lang')
|
||||
this = self.browse(cr, uid, ids)[0]
|
||||
@@ -82,16 +78,29 @@ class gengo_update_translation(osv.osv_memory):
|
||||
translation_term_id = translation_pool.search(cr, uid, [('state', '=', 'translate'), ('gengo_translation', '=', 'True'), ('lang', '=', this.lang)])
|
||||
context.update({'lang': this.lang, 'translation_term_id': translation_term_id})
|
||||
self.send_translation_terms(cr, uid, ids, context)
|
||||
return
|
||||
msg = "Your Request has been Successfully Send to Gengo"
|
||||
else:
|
||||
self.write(cr, uid, ids, {'state': 'inprogress'})
|
||||
msg = "This language is select as Active All Translation Request will be sent by System Automatically"
|
||||
|
||||
except Exception, e:
|
||||
raise osv.except_osv(_('Warning !'), _('%s') % e)
|
||||
msg = '%s' % e
|
||||
context.update({'message': msg})
|
||||
obj_model = self.pool.get('ir.model.data')
|
||||
model_data_ids = obj_model.search(cr, uid, [('model', '=', 'ir.ui.view'), ('name', '=', 'update_translation_wizard_view_confirm')])
|
||||
resource_id = obj_model.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
|
||||
return {
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'res_model': 'gengo.update.message',
|
||||
'views': [(resource_id, 'form')],
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
'context': context,
|
||||
}
|
||||
|
||||
def scheduler_get_gengo_response(self, cr, uid, ids=0, context=None):
|
||||
"""Scheduler will be call to get response from gengo and all term will get
|
||||
by scheduler which terms are in reviewable state"""
|
||||
|
||||
meta = self.pool.get('jobs.meta')
|
||||
translation_pool = self.pool.get('ir.translation')
|
||||
gengo = meta.gengo_authentication(cr, uid, ids, context)
|
||||
@@ -99,9 +108,10 @@ class gengo_update_translation(osv.osv_memory):
|
||||
if res:
|
||||
response = meta.unpack_jobs_response(res)
|
||||
for job in response.response:
|
||||
translation_id = translation_pool.search(cr, uid, [('job_id', '=', job.job_id)], context)
|
||||
response = gengo.getTranslationJob(id=job.job_id)
|
||||
translation_pool.write(cr, uid, translation_id, {'value': response['response']['job']['body_tgt'], 'state': 'translated', 'gengo_control': True})
|
||||
job_response=gengo.getTranslationJob(id=job['job_id'])
|
||||
jobs_response = meta.unpack_jobs_response(job_response)
|
||||
translation_id = translation_pool.search(cr, uid, [('src', '=', jobs_response.response[0]['body_src'])], context)
|
||||
translation_pool.write(cr, uid, translation_id, {'value': jobs_response.response[0]['body_tgt'], 'state': 'translated', 'gengo_control': True})
|
||||
|
||||
def scheduler_get_gengo_sync_request(self, cr, uid, ids=0, context=None):
|
||||
"""This scheduler will send a job request to the gengo , which terms are
|
||||
@@ -116,7 +126,7 @@ class gengo_update_translation(osv.osv_memory):
|
||||
lang_ids = language_pool.read(cr, uid, lang_search_id)
|
||||
|
||||
for lang_id in lang_ids:
|
||||
translation_term_id = translation_pool.search(cr, uid, [('state', '=', 'translate'), ('gengo_translation', '=', 'True'), ('lang', '=', lang_id['code']), ('job_id', '=', False)])
|
||||
translation_term_id = translation_pool.search(cr, uid, [('state', '=', 'translate'), ('gengo_translation', '=', 'True'), ('lang', '=', lang_id['code'])])
|
||||
context.update({'lang': lang_id['code'], 'translation_term_id': translation_term_id})
|
||||
if translation_term_id:
|
||||
self.send_translation_terms(cr, uid, ids, context)
|
||||
@@ -125,13 +135,6 @@ class gengo_update_translation(osv.osv_memory):
|
||||
|
||||
_name = 'base.update.translations'
|
||||
_inherit = "base.update.translations"
|
||||
_columns = {
|
||||
'state': fields.selection([('init', 'init'), ('inprogress', 'inprogress'), ('done', 'done')], 'state'),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'state': 'init',
|
||||
}
|
||||
|
||||
gengo_update_translation()
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
Reference in New Issue
Block a user