hobo/hobo/tenant_settings.py

74 lines
2.4 KiB
Python

from django.conf.global_settings import *
from hobo.default_settings import *
from django.core.exceptions import ImproperlyConfigured
import os
import logging
try:
import entrouvert
except ImportError:
raise ImproperlyConfigured('python-entrouvert MUST be installed for the multitenant mode to work')
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'portail_admin',
},
}
TENANT_BASE = None
TENANT_TEMPLATE_DIRS = ( TENANT_BASE, )
TENANT_MODEL = 'multitenant.Tenant'
SOUTH_TESTS_MIGRATE = False
SOUTH_DATABASE_ADAPTERS = {
'default': 'south.db.postgresql_psycopg2',
}
DEFAULT_FILE_STORAGE = 'entrouvert.djommon.multitenant.storage.TenantFileSystemStorage'
MIDDLEWARE_CLASSES = (
'entrouvert.djommon.multitenant.middleware.TenantMiddleware',
'entrouvert.djommon.multitenant.middleware.JSONSettingsMiddleware',
'entrouvert.djommon.multitenant.middleware.PythonSettingsMiddleware',
) + MIDDLEWARE_CLASSES
TEMPLATE_LOADERS = (
'entrouvert.djommon.multitenant.template_loader.FilesystemLoader',
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
PUBLIC_SCHEMA_URLCONF = 'hobo.manager_urls'
SHARED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
)
INSTALLED_APPS = INSTALLED_APPS + ('entrouvert.djommon.multitenant',)
TENANT_APPS = INSTALLED_APPS
if 'DJANGO_CONFIG_FILE' in os.environ:
logging.getLogger('hobo').debug('Loading setting file %r', os.environ['DJANGO_CONFIG_FILE'])
execfile(os.environ['DJANGO_CONFIG_FILE'])
if not TENANT_BASE:
logging.getLogger('hobo').error('Unable to boot: You must define a TENANT_BASE in your settings')
raise ImproperlyConfigured('You must define a TENANT_BASE in your settings')
if 'DATABASES' not in globals():
logging.getLogger('hobo').error('Unable to boot: You must define a DATABASES in your settings')
raise ImproperlyConfigured('You must define a DATABASES variable in your settings')
if DATABASES['default']['ENGINE'] != 'django.db.backends.postgresql_psycopg2':
raise ImproperlyConfigured('MULTITENANT only work with django.db.backends.postgresql_psycopg2 Django db backend')
DATABASES['default']['ENGINE'] = 'tenant_schemas.postgresql_backend'