diff --git a/cms_form/controllers/main.py b/cms_form/controllers/main.py index 268589ae..e28c3aa5 100644 --- a/cms_form/controllers/main.py +++ b/cms_form/controllers/main.py @@ -8,6 +8,8 @@ from odoo import _, http from odoo.http import request +from ..exceptions import FormRedirect + class FormControllerMixin(object): @@ -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 diff --git a/cms_form/exceptions.py b/cms_form/exceptions.py new file mode 100644 index 00000000..a9930800 --- /dev/null +++ b/cms_form/exceptions.py @@ -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