Files
odoo_source/addons/utm/models/ir_http.py
T
Julien Castiaux ad71d6d3ee [REM] website_utm: website depends on utm already
`_post_dispatch` is a late addition to the httpocalypse. It can be used
to alter the response object e.g. to inject headers or cookies. The
function is automatically called for regular, fallback and error
responses. On the other hand, `_dispatch` is only called when an
endpoint is matched and might not return a response in case of error.

task-2839031

closes odoo/odoo#96651

Related: odoo/upgrade#3710
Signed-off-by: Julien Castiaux <juc@odoo.com>
2022-08-01 10:55:29 +02:00

25 lines
829 B
Python

# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models
from odoo.http import request
class IrHttp(models.AbstractModel):
_inherit = 'ir.http'
@classmethod
def get_utm_domain_cookies(cls):
return request.httprequest.host
@classmethod
def _set_utm(cls, response):
domain = cls.get_utm_domain_cookies()
for url_parameter, __, cookie_name in request.env['utm.mixin'].tracking_fields():
if url_parameter in request.params and request.httprequest.cookies.get(cookie_name) != request.params[url_parameter]:
response.set_cookie(cookie_name, request.params[url_parameter], domain=domain)
@classmethod
def _post_dispatch(cls, response):
cls._set_utm(response)
super()._post_dispatch(response)