Beispiel #1
0
 def __init__(self, *args, **kwargs):
     super(DatabaseWrapper, self).__init__(*args, **kwargs)
     self.threadlocal = MultiTenantThreadlocal()
     if not self.threadlocal.get_dbname():
         self.threadlocal.set_dbname(self.settings_dict['NAME'])
Beispiel #2
0
 def __init__(self, *args, **kwargs):
     super(DatabaseWrapper, self).__init__(*args, **kwargs)
     self.threadlocal = MultiTenantThreadlocal()
Beispiel #3
0
try:
    # Django versions >= 1.9
    from django.utils.module_loading import import_module
except ImportError:
    # Django versions < 1.9
    from django.utils.importlib import import_module

from db_multitenant.mapper import TenantMapper

_CACHED_MAPPER = None

import os

from django.db import connection
from db_multitenant.threadlocal import MultiTenantThreadlocal
my_local_global = MultiTenantThreadlocal()

def get_mode():
    return getattr(settings, 'MULTI_TENANT_MODE', "SCHEMA")

def get_threadlocal():
    if get_mode() == "SCHEMA":
        return connection.get_threadlocal()
    else: # mode == "DATABASE":
        return my_local_global

def get_default_tenant_name():
    return getattr(settings, 'DEFAULT_TENANT_NAME', "devnull")

def update_database_from_env(db_dict):
    from django.db import connection