def process_response(self, request, response): """ Standard Middleware entry point """ # See if we are running in a Microsite *AND* we have a custom SESSION_COOKIE_DOMAIN defined # in configuration if microsite.has_override_value('SESSION_COOKIE_DOMAIN'): # define wrapper function for the standard set_cookie() def _set_cookie_wrapper(key, value='', max_age=None, expires=None, path='/', domain=None, secure=None, httponly=False): # only override if we are setting the cookie name to be the one the Django Session Middleware uses # as defined in settings.SESSION_COOKIE_NAME if key == settings.SESSION_COOKIE_NAME: domain = microsite.get_value('SESSION_COOKIE_DOMAIN', domain) # then call down into the normal Django set_cookie method return response.set_cookie_wrapped_func( key, value, max_age=max_age, expires=expires, path=path, domain=domain, secure=secure, httponly=httponly ) # then point the HttpResponse.set_cookie to point to the wrapper and keep # the original around response.set_cookie_wrapped_func = response.set_cookie response.set_cookie = _set_cookie_wrapper return response
def has_override_value(name): """ Returns True/False whether configuration has a definition for the specified key. Args: name (str): Name of the configuration dict to retrieve. Returns: (bool): True if given key is present in the configuration. """ if is_site_configuration_enabled(): return has_configuration_override(name) else: return microsite.has_override_value(name)
def test_has_override_value(self): """ Tests microsite.has_override_value works as expected. """ microsite.set_by_domain(self.microsite_subdomain) self.assertTrue(microsite.has_override_value('platform_name'))