Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0] cms_form: add FormRedirect exception #138

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cms_form/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from odoo import _, http
from odoo.http import request

from ..exceptions import FormRedirect


class FormControllerMixin(object):

Expand Down Expand Up @@ -96,7 +98,10 @@ def make_response(self, model, model_id=None, **kw):
form = self.get_form(model, model_id=model_id, **kw)
form.form_check_permission()
# pass only specific extra args, to not pollute form render values
form.form_process(extra_args={"page": kw.get("page")})
try:
form.form_process(extra_args={"page": kw.get("page")})
except FormRedirect as exc:
return werkzeug.utils.redirect(exc.next_url, code=303)
# search forms do not need these attrs
if getattr(form, "form_success", None) and getattr(form, "form_redirect", None):
# anything went fine, redirect to next url
Expand Down
10 changes: 10 additions & 0 deletions cms_form/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright 2024 Simone Orsi
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).


class FormRedirect(Exception):
"""Triggers a redirect to given URL."""

def __init__(self, message, next_url):
super().__init__(message)
self.next_url = next_url
Loading