[MERGE] website_gengo: Migration to new API

This commit is contained in:
Yannick Tivisse
2016-07-14 11:37:41 +02:00
8 changed files with 47 additions and 49 deletions
@@ -7,7 +7,7 @@ import time
import uuid
from odoo import api, fields, models, tools, _
from openerp.exceptions import UserError
from openerp.exceptions import UserError, ValidationError
_logger = logging.getLogger(__name__)
@@ -145,8 +145,7 @@ class BaseGengoTranslations(models.TransientModel):
'gengo_order_ids': set(),
'ir_translation_ids': set(),
}
translation_terms = IrTranslation.browse(translation_ids)
for term in translation_terms:
for term in translation_ids:
terms_progress['gengo_order_ids'].add(term.order_id)
terms_progress['ir_translation_ids'].add(tools.ustr(term.id))
@@ -177,21 +176,21 @@ class BaseGengoTranslations(models.TransientModel):
if job.get('status', False) in ('approved', 'canceled'):
vals['state'] = 'translated'
if vals:
translation.write(vals)
try:
translation.write(vals)
except ValidationError:
pass
@api.model
def _update_terms(self, response, term_ids):
"""
Update the terms after their translation were requested to Gengo
"""
translation = self.env['ir.translation'].browse(term_ids)
vals = {
'order_id': response.get('order_id', ''),
'state': 'inprogress'
}
translation.write(vals)
term_ids.write(vals)
jobs = response.get('jobs', [])
if jobs:
for t_id, job in jobs.items():
@@ -212,14 +211,14 @@ class BaseGengoTranslations(models.TransientModel):
jobs = {}
user = self.env.user
auto_approve = 1 if user.company_id.gengo_auto_approve else 0
for term in IrTranslation.browse(term_ids):
for term in term_ids:
if re.search(r"\w", term.src or ""):
comment = user.company_id.gengo_comment or ''
if term.gengo_comment:
comment += '\n' + term.gengo_comment
jobs[time.strftime('%Y%m%d%H%M%S') + '-' + str(term.id)] = {
'type': 'text',
'slug': 'Single :: English to ' + term.lang.id,
'slug': 'Single :: English to ' + term.lang,
'tier': tools.ustr(term.gengo_translation),
'custom_data': str(term.id),
'body_src': term.src,
+2 -5
View File
@@ -4,7 +4,6 @@
{
'name': 'Website Gengo Translator',
'category': 'Website',
'version': '1.0',
'description': """
Website Gengo Translator
========================
@@ -16,8 +15,6 @@ Translate you website in one click
'base_gengo'
],
'data': [
'views/website_gengo.xml',
],
'qweb': [],
'installable': True,
'views/website_gengo_templates.xml',
]
}
@@ -1 +1,4 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import main
+16 -19
View File
@@ -1,41 +1,38 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import openerp
from openerp import http, SUPERUSER_ID
from openerp.http import request
import time
from odoo import http
from odoo.http import request
GENGO_DEFAULT_LIMIT = 20
class website_gengo(http.Controller):
class WebsiteGengo(http.Controller):
@http.route('/website/get_translated_length', type='json', auth='user', website=True)
def get_translated_length(self, translated_ids, lang):
ir_translation_obj = request.registry['ir.translation']
result={"done":0}
gengo_translation_ids = ir_translation_obj.search(request.cr, request.uid, [('id','in',translated_ids),('gengo_translation','!=', False)])
for trans in ir_translation_obj.browse(request.cr, request.uid, gengo_translation_ids):
result = {"done": 0}
gengo_translation_ids = request.env['ir.translation'].search([('id', 'in', translated_ids), ('gengo_translation', '!=', False)])
for trans in gengo_translation_ids:
result['done'] += len(trans.source.split())
return result
@http.route('/website/check_gengo_set', type='json', auth='user', website=True)
def check_gengo_set(self):
user = request.registry['res.users'].browse(request.cr, SUPERUSER_ID, request.uid)
company = request.env.user.sudo().company_id
company_flag = 0
if not user.company_id.gengo_public_key or not user.company_id.gengo_private_key:
company_flag = user.company_id.id
if not company.gengo_public_key or not company.gengo_private_key:
company_flag = company.id
return company_flag
@http.route('/website/set_gengo_config', type='json', auth='user', website=True)
def set_gengo_config(self,config):
user = request.registry['res.users'].browse(request.cr, request.uid, request.uid)
if user.company_id:
request.registry['res.company'].write(request.cr, request.uid, user.company_id.id, config)
def set_gengo_config(self, config):
request.env.user.company_id.write(config)
return True
@http.route('/website/post_gengo_jobs', type='json', auth='user', website=True)
def post_gengo_jobs(self):
request.registry['base.gengo.translations']._sync_request(request.cr, request.uid, limit=GENGO_DEFAULT_LIMIT, context=request.context)
request.env['base.gengo.translations']._sync_request(limit=GENGO_DEFAULT_LIMIT)
return True
@http.route('/website_gengo/set_translations', type='json', auth='user', website=True)
+3
View File
@@ -1 +1,4 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import base_gengo_translations
@@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from openerp.osv import osv
from odoo import models
class base_gengo_translations(osv.TransientModel):
class BaseGengoTranslations(models.TransientModel):
_inherit = 'base.gengo.translations'
# update GROUPS, that are the groups allowing to access the gengo key.
# this is done here because in the base_gengo module, the various website
@@ -1,13 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="gengo_assets_editor" inherit_id="website.assets_editor" name="Editor Head">
<xpath expr='.' position="inside">
<link rel="stylesheet" href="/website_gengo/static/src/css/website_gengo.css"></link>
<script type="text/javascript" src="/website_gengo/static/src/js/website_gengo.js"></script>
</xpath>
</template>
</data>
</openerp>
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="gengo_assets_editor" inherit_id="website.assets_editor" name="Editor Head">
<xpath expr='.' position="inside">
<link rel="stylesheet" href="/website_gengo/static/src/css/website_gengo.css" />
<script type="text/javascript" src="/website_gengo/static/src/js/website_gengo.js" />
</xpath>
</template>
</odoo>