[FIX/IMP] Impoved the code and updated the usabality
bzr revid: jam@tinyerp.com-20120828113755-eaazn33wrdrw17xb
This commit is contained in:
@@ -26,10 +26,10 @@ class ir_translation(osv.Model):
|
||||
_name = "ir.translation"
|
||||
_inherit = "ir.translation"
|
||||
_columns = {
|
||||
'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),
|
||||
'gengo_comment': fields.text("Comments & Activity"),
|
||||
'gengo_translation': fields.boolean("Gengo Auto Translation ?", help='If checked the term will be translated by Gengo automatically.'),
|
||||
'gengo_control': fields.boolean('Gengo Traslated', help="If Term is translated using Gengo Service, the check box will be checked.", readonly=True),
|
||||
'job_id': fields.char('Gengo JobId', size=32),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
<field name="model">ir.translation</field>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//form[@string='Translations']/sheet" position="inside">
|
||||
<group string="comments" col="1">
|
||||
<field name="gengo_comment" nolabel="1" placeholder="Add Your comments here for Translation Job...."/>
|
||||
<group string="Gengo Comments & Activity" col="1">
|
||||
<field name="gengo_comment" nolabel="1" placeholder="Gengo Comments & Activity..."/>
|
||||
</group>
|
||||
<group col="4">
|
||||
<field name="gengo_translation" />
|
||||
|
||||
@@ -31,8 +31,8 @@ class res_company(osv.Model):
|
||||
"gengo_tier": fields.selection([('machine', 'Machine'),
|
||||
('standard', 'Standard'),
|
||||
('pro', 'Pro'),
|
||||
('ultra', 'Ultra')], "Tier types", required=True),
|
||||
"gengo_comment": fields.text("comments"),
|
||||
('ultra', 'Ultra')], "Tier Type", required=True),
|
||||
"gengo_comment": fields.text("Comments"),
|
||||
"gengo_auto_approve": fields.boolean("Auto Approve Translation ?", help="Jobs are Automatically Approved by Gengo."),
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
<field name="gengo_tier" />
|
||||
<field name="gengo_auto_approve"/>
|
||||
</group>
|
||||
<group string="Comments" col="1">
|
||||
<field name="gengo_comment" nolabel="1" placeholder="Add Your comments here for Translator...."/>
|
||||
<group string="Comments for Translator" col="1">
|
||||
<field name="gengo_comment" nolabel="1" placeholder="Add your comments here for translator...."/>
|
||||
</group>
|
||||
</page>
|
||||
</xpath>
|
||||
|
||||
@@ -127,7 +127,7 @@ class base_update_translation(osv.osv_memory):
|
||||
new_langs.append(l)
|
||||
return list(set(new_langs))
|
||||
|
||||
def _update_terms(self, cr, uid, ids, response, tier, context):
|
||||
def _update_terms(self, cr, uid, response, tier, context):
|
||||
translation_pool = self.pool.get('ir.translation')
|
||||
for jobs in response['jobs']:
|
||||
for t_id, res in jobs.items():
|
||||
@@ -139,7 +139,7 @@ class base_update_translation(osv.osv_memory):
|
||||
translation_pool.write(cr, uid, [t_id], vals, context)
|
||||
return
|
||||
|
||||
def _send_translation_terms(self, cr, uid, ids, term_ids, context):
|
||||
def _send_translation_terms(self, cr, uid, term_ids, context):
|
||||
"""
|
||||
Lazy Polling will be perform when user or cron request for the translation.
|
||||
"""
|
||||
@@ -150,7 +150,7 @@ class base_update_translation(osv.osv_memory):
|
||||
if request['jobs']:
|
||||
result = gengo.postTranslationJobs(jobs=request)
|
||||
if result['opstat'] == 'ok':
|
||||
self._update_terms(cr, uid, ids, result['response'], user.company_id.gengo_tier, context)
|
||||
self._update_terms(cr, uid, result['response'], user.company_id.gengo_tier, context)
|
||||
else:
|
||||
_logger.error(gengo)
|
||||
return True
|
||||
@@ -221,6 +221,7 @@ class base_update_translation(osv.osv_memory):
|
||||
else:
|
||||
translation_id = translation_pool.search(cr, uid, [('state', '=', 'inprogress'), ('gengo_translation', '=', True)], limit=limit, context=context)
|
||||
for term in translation_pool.browse(cr, uid, translation_id, context):
|
||||
up_term = up_comment = 0
|
||||
if term.job_id:
|
||||
vals={}
|
||||
job_response = gengo.getTranslationJob(id=term.job_id)
|
||||
@@ -231,14 +232,17 @@ class base_update_translation(osv.osv_memory):
|
||||
vals.update({'state': 'translated',
|
||||
'value': job_response['response']['job']['body_tgt'],
|
||||
'gengo_control': True})
|
||||
up_term += 1
|
||||
job_comment = gengo.getTranslationJobComments(id=term.job_id)
|
||||
if job_comment['opstat']=='ok':
|
||||
gengo_comments=""
|
||||
for comment in job_comment['response']['thread']:
|
||||
gengo_comments+='%s by %s at %s. \n' %(comment['body'],comment['author'],time.ctime(comment['ctime']))
|
||||
gengo_comments+='%s Commented on %s by %s. \n'%(comment['body'], time.ctime(comment['ctime']), comment['author'])
|
||||
vals.update({'gengo_comment':gengo_comments})
|
||||
up_comment +=1
|
||||
if vals:
|
||||
translation_pool.write(cr, uid, term.id,vals)
|
||||
_logger.info("Successfully Updated `%d` terms and Comments for `%d` terms."%(up_term, up_comment ))
|
||||
return True
|
||||
|
||||
def _sync_request(self, cr, uid, limit=20, context=None):
|
||||
@@ -256,7 +260,7 @@ class base_update_translation(osv.osv_memory):
|
||||
langs = self.check_lang_support(cr, uid, langs)
|
||||
term_ids = translation_pool.search(cr, uid, [('state', '=', 'to_translate'), ('gengo_translation', '=', True), ('lang', 'in', langs)], limit=limit)
|
||||
if term_ids:
|
||||
self._send_translation_terms(cr, uid, ids, term_ids, context)
|
||||
self._send_translation_terms(cr, uid, term_ids, context)
|
||||
_logger.info("Translation terms %s has been posted to gengo successfully", len(term_ids))
|
||||
else:
|
||||
_logger.info('No Translation terms to process.')
|
||||
|
||||
Reference in New Issue
Block a user