[IMP] added callback for gengo jobs,

- if any changes like acception of job,approval of job, comment by translator etc gengo will post that job to given callback url
- On otherside added a controller for '/website/gengo_callback' for handling callback.
so any chages on job will instantly reflected to openerp

bzr revid: pga@tinyerp.com-20140331121932-3u2usycyftdrqcrw
This commit is contained in:
Parth Gajjar (Open ERP) 2014-03-31 17:49:32 +05:30
parent ff1588a46d
commit b3c55f498f
2 changed files with 25 additions and 1 deletions

View File

@ -181,7 +181,8 @@ class base_gengo_translations(osv.osv_memory):
'lc_src': 'en',
'lc_tgt': translation_pool._get_gengo_corresponding_language(term.lang),
'auto_approve': auto_approve,
'comment': user.company_id.gengo_comment and "%s %s"%(user.company_id.gengo_comment,term.gengo_comment) or term.gengo_comment
'comment': user.company_id.gengo_comment and "%s %s"%(user.company_id.gengo_comment,term.gengo_comment) or term.gengo_comment,
'callback_url': self.pool.get('ir.config_parameter').get_param(cr, uid,'web.base.url') + '/website/gengo_callback/' + str(term.id)
}
return {'jobs': jobs}

View File

@ -1,7 +1,12 @@
# -*- coding: utf-8 -*-
import openerp
from openerp.addons.web import http
from openerp.addons.web.http import request
import time
import json
from openerp.tools.translate import _
GENGO_DEFAULT_LIMIT = 20
@ -35,3 +40,21 @@ class website_gengo(http.Controller):
def post_gengo_jobs(self):
request.registry['base.gengo.translations']._sync_request(request.cr, request.uid, limit=GENGO_DEFAULT_LIMIT, context=request.context)
return True
@http.route('/website/gengo_callback/<model("ir.translation"):term>', type='http', auth='none')
def gengo_callback(self,term,**post):
if post and post.get('job'):
translation_pool = request.registry['ir.translation']
base_gengo_pool = request.registry['base.gengo.translations']
job, vals = json.loads(post['job']), {}
if job.get('status') == 'approved':
vals.update({'state': 'translated', 'value': job.get('body_tgt')})
flag, gengo = base_gengo_pool.gengo_authentication(request.cr, openerp.SUPERUSER_ID, context=request.context)
job_comment = gengo.getTranslationJobComments(id=job.get('job_id'))
if job_comment['opstat']=='ok':
gengo_comments=""
for comment in job_comment['response']['thread']:
gengo_comments += _('%s\n-- Commented on %s by %s.\n\n') % (comment['body'], time.ctime(comment['ctime']), comment['author'])
vals.update({'gengo_comment': gengo_comments})
if vals:
translation_pool.write(request.cr, openerp.SUPERUSER_ID, term.id, vals)