Skip to content

Commit 4d84ebd

Browse files
Merge pull request #320 from akretion/14.0-add-sixteen_in_fourteen-with-redirect
[IMP] sixteen_in_fourteen: Backport request.redirect
2 parents 02b36c1 + acdfe30 commit 4d84ebd

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

sixteen_in_fourteen/odoo/http.py

+16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Part of Odoo. See LICENSE file for full copyright and licensing details.
22

3+
from odoo.http import HttpRequest, Response, root, urls
4+
35
import collections.abc
46
from abc import ABC, abstractmethod
57

@@ -83,3 +85,17 @@ def handle_error(self, exc: Exception) -> collections.abc.Callable:
8385
Transform the exception into a valid HTTP response. Called upon
8486
any exception while serving a request.
8587
"""
88+
89+
90+
def redirect16(self, location, code=303, local=True):
91+
# compatibility, Werkzeug support URL as location
92+
if isinstance(location, urls.URL):
93+
location = location.to_url()
94+
if local:
95+
location = "/" + urls.url_parse(location).replace(
96+
scheme="", netloc=""
97+
).to_url().lstrip("/")
98+
return werkzeug.utils.redirect(location, code, Response=Response)
99+
100+
101+
HttpRequest.redirect = redirect16

0 commit comments

Comments
 (0)