ir_http.py 980 B

123456789101112131415161718192021222324252627
  1. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  2. from odoo import models
  3. from odoo.http import request, Response
  4. class IrHttp(models.AbstractModel):
  5. _inherit = 'ir.http'
  6. @classmethod
  7. def get_utm_domain_cookies(cls):
  8. return request.httprequest.host
  9. @classmethod
  10. def _set_utm(cls, response):
  11. # Make sure response is an odoo Response.
  12. response = Response.load(response)
  13. domain = cls.get_utm_domain_cookies()
  14. for url_parameter, __, cookie_name in request.env['utm.mixin'].tracking_fields():
  15. if url_parameter in request.params and request.httprequest.cookies.get(cookie_name) != request.params[url_parameter]:
  16. response.set_cookie(cookie_name, request.params[url_parameter], max_age=31 * 24 * 3600, domain=domain, cookie_type='optional')
  17. @classmethod
  18. def _post_dispatch(cls, response):
  19. cls._set_utm(response)
  20. super()._post_dispatch(response)