From acdfe30193ecfa809b24688a0c6bd4ed44fd451c Mon Sep 17 00:00:00 2001 From: Florian Mounier Date: Fri, 13 Dec 2024 09:29:29 +0100 Subject: [PATCH] [IMP] sixteen_in_fourteen: Backport request.redirect --- sixteen_in_fourteen/odoo/http.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sixteen_in_fourteen/odoo/http.py b/sixteen_in_fourteen/odoo/http.py index e585ddc4..be32691e 100644 --- a/sixteen_in_fourteen/odoo/http.py +++ b/sixteen_in_fourteen/odoo/http.py @@ -1,5 +1,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. +from odoo.http import HttpRequest, Response, root, urls + import collections.abc from abc import ABC, abstractmethod @@ -83,3 +85,17 @@ def handle_error(self, exc: Exception) -> collections.abc.Callable: Transform the exception into a valid HTTP response. Called upon any exception while serving a request. """ + + +def redirect16(self, location, code=303, local=True): + # compatibility, Werkzeug support URL as location + if isinstance(location, urls.URL): + location = location.to_url() + if local: + location = "/" + urls.url_parse(location).replace( + scheme="", netloc="" + ).to_url().lstrip("/") + return werkzeug.utils.redirect(location, code, Response=Response) + + +HttpRequest.redirect = redirect16