Esempio n. 1
0
    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)
Esempio n. 2
0
 def login(self, login, password, db=None):
     if db and db != request.db:
         raise Exception(_("Could not select database '%s'") % db)
     uid = request.session.authenticate(request.db, login, password)
     if not uid:
         return Response(response="Wrong login/password", status=401)
     self.check_user(uid)
     return Response(headers={
         'X-CSRF-TOKEN': request.csrf_token(),
     })
Esempio n. 3
0
 def perform_flashing_create_partition(self):
     try:
         response = subprocess.check_output(['sudo', 'bash', '-c', '. /home/pi/flectra/addons/point_of_sale/tools/posbox/configuration/upgrade.sh; create_partition']).decode().split('\n')[-2]
         if response in ['Error_Card_Size', 'Error_Upgrade_Already_Started']:
             raise Exception(response)
         return Response('success', status=200)
     except subprocess.CalledProcessError as e:
         raise Exception(e.output)
     except Exception as e:
         _logger.error('A error encountered : %s ' % e)
         return Response(str(e), status=500)
Esempio n. 4
0
 def perform_flashing_copy_raspios(self):
     try:
         response = subprocess.check_output(['sudo', 'bash', '-c', '. /home/pi/flectra/addons/point_of_sale/tools/posbox/configuration/upgrade.sh; copy_raspios']).decode().split('\n')[-2]
         if response == 'Error_Iotbox_Download':
             raise Exception(response)
         return Response('success', status=200)
     except subprocess.CalledProcessError as e:
         raise Exception(e.output)
     except Exception as e:
         self.clean_partition()
         _logger.error('A error encountered : %s ' % e)
         return Response(str(e), status=500)
Esempio n. 5
0
    def portal_my_purchase_order_update_dates(self,
                                              order_id=None,
                                              access_token=None,
                                              **kw):
        """User update scheduled date on purchase order line.
        """
        try:
            order_sudo = self._document_check_access('purchase.order',
                                                     order_id,
                                                     access_token=access_token)
        except (AccessError, MissingError):
            return request.redirect('/my')

        updated_dates = []
        for id_str, date_str in kw.items():
            try:
                line_id = int(id_str)
            except ValueError:
                return request.redirect(order_sudo.get_portal_url())
            line = order_sudo.order_line.filtered(lambda l: l.id == line_id)
            if not line:
                return request.redirect(order_sudo.get_portal_url())

            try:
                updated_date = line._convert_to_middle_of_day(
                    datetime.strptime(date_str, '%Y-%m-%d'))
            except ValueError:
                continue

            updated_dates.append((line, updated_date))

        if updated_dates:
            order_sudo._update_date_planned_for_lines(updated_dates)
        return Response(status=204)
Esempio n. 6
0
        def response_wrap(*args, **kw):
            response = f(*args, **kw)
            if isinstance(response,
                          Response) or f.routing_type in ("apijson", "json"):
                return response

            if isinstance(response, (bytes, str)):
                return Response(response)

            if isinstance(response, werkzeug.exceptions.HTTPException):
                response = response.get_response(request.httprequest.environ)
            if isinstance(response, werkzeug.wrappers.BaseResponse):
                response = Response.force_type(response)
                response.set_default()
                return response

            _logger.warn(
                "<function %s.%s> returns an invalid response type for an http request"
                % (f.__module__, f.__name__))
            return response
Esempio n. 7
0
    def _json_response(self, result=None, error=None):

        response = {}
        if error is not None:
            response["error"] = error

        mime = "application/json"
        status = error and error.pop("code") or result.status_code
        body = (response
                and json.dumps(response, default=date_utils.json_default)
                or result.data)

        return Response(
            body,
            status=status,
            headers=[("Content-Type", mime), ("Content-Length", len(body))],
        )
Esempio n. 8
0
 def _make_parse_response(self, url, message, attachment):
     if attachment:
         for file in message["attachments"]:
             if file.fname and file.fname == attachment:
                 return self._make_attachment_response(
                     file.content, file.fname)
     else:
         attachments = []
         for file in message["attachments"]:
             mimetype = mimetypes.guess_type(
                 urllib.request.pathname2url(file.fname))[0]
             extension = os.path.splitext(file.fname)[1]
             link = self._set_query_parameter(url, "attachment", file.fname)
             attachments.append(
                 self._Attachment(file.fname, mimetype, extension, link,
                                  file.info))
         message["attachments"] = attachments
         return Response(json.dumps(message),
                         content_type='application/json;charset=utf-8',
                         status=200)
Esempio n. 9
0
 def wrap(*args, **kw):
     try:
         return f(*args, **kw)
     except Exception as e:
         return Response(response=str(e), status=500)