File: main.py

package info (click to toggle)
oca-core 11.0.20180730-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 509,684 kB
  • sloc: xml: 258,806; python: 164,081; sql: 217; sh: 92; makefile: 16
file content (46 lines) | stat: -rw-r--r-- 1,936 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

import json

from odoo.http import Controller, Response, request, route


class website_gengo(Controller):

    @route('/website/gengo_callback', type='http', auth='none', csrf=False)
    def gengo_callback(self, **post):
        IrTranslationSudo = request.env['ir.translation'].sudo()
        if post and post.get('job') and post.get('pgk'):
            if post.get('pgk') != request.env['base.gengo.translation'].sudo().get_gengo_key():
                return Response("Bad authentication", status=104)
            job = json.loads(post['job'], 'utf-8')
            tid = job.get('custom_data', False)
            if (job.get('status') == 'approved') and tid:
                term = IrTranslationSudo.browse(int(tid))
                if term.src != job.get('body_src'):
                    return Response("Text Altered - Not saved", status=418)
                domain = [
                    '|',
                    ('id', "=", int(tid)),
                    '&', '&', '&', '&', '&',
                    ('state', '=', term.state),
                    ('gengo_translation', '=', term.gengo_translation),
                    ('src', "=", term.src),
                    ('type', "=", term.type),
                    ('name', "=", term.name),
                    ('lang', "=", term.lang),
                    #('order_id', "=", term.order_id),
                ]

                all_ir_tanslations = IrTranslationSudo.search(domain)

                if all_ir_tanslations:
                    all_ir_tanslations.write({
                        'state': 'translated',
                        'value': job.get('body_tgt')
                    })
                    return Response("OK", status=200)
                else:
                    return Response("No terms found", status=412)
        return Response("Not saved", status=418)