def is_shared_app(app): if has_multi_type_tenants(): _apps = get_tenant_types()[get_public_schema_name()]['APPS'] else: _apps = settings.SHARED_APPS return app["app_label"] in [get_app_label(_app) for _app in _apps]
def is_shared_app(app): if has_multi_type_tenants(): _apps = get_tenant_types()[get_public_schema_name()]['APPS'] else: _apps = settings.SHARED_APPS return app_in_list(app['app_label'], _apps)
def allow_migrate(self, db, app_label, model_name=None, **hints): # the imports below need to be done here else django <1.5 goes crazy # https://code.djangoproject.com/ticket/20704 from django.db import connections from django_tenants.utils import get_public_schema_name, get_tenant_database_alias if db != get_tenant_database_alias(): return False connection = connections[db] public_schema_name = get_public_schema_name() if has_multi_type_tenants(): tenant_types = get_tenant_types() if connection.schema_name == public_schema_name: installed_apps = tenant_types[public_schema_name]['APPS'] else: installed_apps = tenant_types[ connection.tenant.tenant_type]['APPS'] else: if connection.schema_name == public_schema_name: installed_apps = settings.SHARED_APPS else: installed_apps = settings.TENANT_APPS if not self.app_in_list(app_label, installed_apps): return False return None
def is_shared_app(app): if has_multi_type_tenants(): _apps = get_tenant_types()[get_public_schema_name()]['APPS'] else: _apps = settings.SHARED_APPS return app['app_label'] in [ tenant_app.split('.')[-1] for tenant_app in _apps ]
def is_shared_app(app): if has_multi_type_tenants(): _apps = get_tenant_types()[get_public_schema_name()]['APPS'] else: _apps = settings.SHARED_APPS cfg = apps.get_app_config(app['app_label']) return cfg.module.__name__ in _apps
def is_tenant_app(context, app): if has_multi_type_tenants(): if hasattr(context.request, 'tenant') and context.request.tenant is not None: _apps = get_tenant_types()[context.request.tenant.get_tenant_type()]['APPS'] else: return True else: _apps = settings.TENANT_APPS return app_in_list(app['app_label'], _apps)
def is_tenant_app(context, app): if has_multi_type_tenants(): if hasattr(context.request, 'tenant') and context.request.tenant is not None: _apps = get_tenant_types()[context.request.tenant.get_tenant_type()]['APPS'] else: return True else: _apps = settings.TENANT_APPS cfg = apps.get_app_config(app['app_label']) return cfg.module.__name__ in _apps
def get_subfolder_urlconf(tenant): """ Creates and returns a subfolder URLConf for tenant. """ if has_multi_type_tenants(): urlconf = get_tenant_types()[tenant.get_tenant_type()]['URLCONF'] else: urlconf = settings.ROOT_URLCONF dynamic_path = urlconf + "_dynamically_tenant_prefixed" if not sys.modules.get(dynamic_path): sys.modules[dynamic_path] = get_dynamic_tenant_prefixed_urlconf( urlconf, dynamic_path) return dynamic_path
def is_tenant_app(context, app): if has_multi_type_tenants(): if hasattr(context.request, 'tenant') and context.request.tenant is not None: _apps = get_tenant_types()[ context.request.tenant.get_tenant_type()]['APPS'] else: return True else: _apps = settings.TENANT_APPS return app['app_label'] in [ tenant_app.split('.')[-1] for tenant_app in _apps ]
def setup_url_routing(request): """ Sets the correct url conf based on the tenant :param request: """ public_schema_name = get_public_schema_name() if has_multi_type_tenants(): tenant_types = get_tenant_types() if (not hasattr(request, 'tenant') or (request.tenant.schema_name == get_public_schema_name() and 'URLCONF' in tenant_types[public_schema_name])): request.urlconf = get_public_schema_urlconf() else: tenant_type = request.tenant.get_tenant_type() request.urlconf = tenant_types[tenant_type]['URLCONF'] set_urlconf(request.urlconf) else: # Do we have a public-specific urlconf? if hasattr( settings, 'PUBLIC_SCHEMA_URLCONF' ) and request.tenant.schema_name == get_public_schema_name(): request.urlconf = settings.PUBLIC_SCHEMA_URLCONF