Skip to content

Commit

Permalink
Merge pull request #320 from akretion/14.0-add-sixteen_in_fourteen-wi…
Browse files Browse the repository at this point in the history
…th-redirect

[IMP] sixteen_in_fourteen: Backport request.redirect
  • Loading branch information
paradoxxxzero authored Jan 13, 2025
2 parents 02b36c1 + acdfe30 commit 4d84ebd
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions sixteen_in_fourteen/odoo/http.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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

0 comments on commit 4d84ebd

Please sign in to comment.