def db_for_read(self, model, **hints): if model._meta.app_label == 'DomainGroup': return utils.get_default_tenant_name() else: if utils.get_threadlocal().get_tenant_name() == None: return utils.get_default_tenant_name() else: return utils.get_threadlocal().get_tenant_name()
def process_response(self, request, response): # Write cookie with tenant if needed threadlocal = utils.get_threadlocal() if threadlocal.get_write_cookie(): response.set_cookie('tenant', threadlocal.get_tenant_name()) threadlocal.set_write_cookie = False """Clears the database name and cache prefix on response. This is a precaution against the connection being reused without first calling set_dbname. """ threadlocal.reset() return response
def process_request(self, request): mapper = utils.get_mapper() threadlocal = utils.get_threadlocal() tenant_name = mapper.get_tenant_name(request, threadlocal) threadlocal.set_tenant_name(tenant_name) threadlocal.set_dbname('tenant_%s' % tenant_name) threadlocal.set_cache_prefix('tenant_%s' % tenant_name) if 'django.contrib.sites' in settings.INSTALLED_APPS: # Clear the sites framework cache. from django.contrib.sites.models import Site Site.objects.clear_cache()
def process_response(self, request, response): if utils.get_threadlocal().get_write_cookie(): response.set_cookie('tenant', utils.get_threadlocal().get_tenant_name()) utils.get_threadlocal().set_write_cookie = False return response
def process_request(self, request): mapper = utils.get_mapper() #mapper.get_tenant_name(request) threadlocal = utils.get_threadlocal() threadlocal.set_tenant_name( mapper.get_tenant_name(request, threadlocal))