2018-01-16 06:58:15 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2018-01-16 11:34:37 +01:00
|
|
|
from flectra.http import request
|
|
|
|
from flectra import models
|
2018-01-16 06:58:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
class IrHttp(models.AbstractModel):
|
|
|
|
_inherit = 'ir.http'
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get_utm_domain_cookies(cls):
|
|
|
|
return request.httprequest.host
|
|
|
|
|
|
|
|
@classmethod
|
2018-04-05 10:25:40 +02:00
|
|
|
def _set_utm(cls, response):
|
|
|
|
if isinstance(response, Exception):
|
|
|
|
return response
|
|
|
|
|
|
|
|
domain = cls.get_utm_domain_cookies()
|
2018-01-16 06:58:15 +01:00
|
|
|
for var, dummy, cook in request.env['utm.mixin'].tracking_fields():
|
|
|
|
if var in request.params and request.httprequest.cookies.get(var) != request.params[var]:
|
2018-04-05 10:25:40 +02:00
|
|
|
response.set_cookie(cook, request.params[var], domain=domain)
|
|
|
|
return response
|
2018-01-16 06:58:15 +01:00
|
|
|
|
2018-04-05 10:25:40 +02:00
|
|
|
@classmethod
|
|
|
|
def _dispatch(cls):
|
2018-01-16 06:58:15 +01:00
|
|
|
response = super(IrHttp, cls)._dispatch()
|
2018-04-05 10:25:40 +02:00
|
|
|
return cls._set_utm(response)
|
2018-01-16 06:58:15 +01:00
|
|
|
|
2018-04-05 10:25:40 +02:00
|
|
|
@classmethod
|
|
|
|
def _handle_exception(cls, exc):
|
|
|
|
response = super(IrHttp, cls)._handle_exception(exc)
|
|
|
|
return cls._set_utm(response)
|