0001-settings-changed-to-single-file-with-a-execfile-tack.patch
README | ||
---|---|---|
41 | 41 | |
42 | 42 |
Passerelle is available on http://127.0.0.1:8000/ |
43 | 43 | |
44 |
manage.py options |
|
45 |
----------------- |
|
46 | 44 | |
47 |
--config=/path/to/config.py |
|
48 |
Configuration file. See config_example.py for example. |
|
45 |
Settings |
|
46 |
-------- |
|
49 | 47 | |
50 |
--multitenant |
|
51 |
Activate multi-tenant mode. The python-entrouvert package |
|
52 |
must be installed.
|
|
48 |
Default settings are loaded from settings.py, they can be overloaded by a |
|
49 |
local_settings.py file set in the same directory, or by a file referenced |
|
50 |
in the PASSERELLE_SETTINGS_FILE environment variable.
|
|
53 | 51 | |
54 | 52 | |
55 | 53 |
LICENSES |
manage.py | ||
---|---|---|
3 | 3 |
import sys |
4 | 4 | |
5 | 5 |
if __name__ == "__main__": |
6 |
multitenant = False |
|
7 |
config_file = False |
|
8 | ||
9 |
argv = sys.argv[1:] |
|
10 |
for arg in list(argv): |
|
11 |
if arg.startswith('--'): |
|
12 |
if arg.startswith('--config='): |
|
13 |
config_file = arg.split('=')[1] |
|
14 |
argv.pop(0) |
|
15 |
elif arg == '--multitenant': |
|
16 |
multitenant = True |
|
17 |
argv.pop(0) |
|
18 |
else: |
|
19 |
print >>sys.stderr, 'ERR: Unsupported flag', arg |
|
20 |
sys.exit(1) |
|
21 |
else: |
|
22 |
break |
|
23 | ||
24 |
if config_file: |
|
25 |
os.environ['DJANGO_CONFIG_FILE'] = config_file |
|
26 | ||
27 |
if multitenant: |
|
28 |
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "passerelle.tenant_settings") |
|
29 |
else: |
|
30 |
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "passerelle.settings") |
|
6 |
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "passerelle.settings") |
|
31 | 7 | |
32 | 8 |
from django.core.management import execute_from_command_line |
33 | 9 | |
34 |
execute_from_command_line(sys.argv[:1] + argv) |
|
10 |
execute_from_command_line(sys.argv) |
passerelle/default_settings.py | ||
---|---|---|
1 |
# Django default settings for passerelle project. |
|
2 | ||
3 |
from django.conf import global_settings |
|
4 |
import os |
|
5 |
import logging |
|
6 |
try: |
|
7 |
from logging.handlers import NullHandler |
|
8 |
except ImportError: |
|
9 |
# python < 2.7 |
|
10 |
class NullHandler(logging.Handler): |
|
11 |
def emit(self, record): |
|
12 |
pass |
|
13 | ||
14 |
logging.getLogger('passerelle').addHandler(NullHandler()) |
|
15 | ||
16 |
PACKAGE_PATH = os.path.dirname(__file__) |
|
17 | ||
18 |
### Quick-start development settings - unsuitable for production |
|
19 |
# See https://docs.djangoproject.com/en/dev/howto/deployment/checklist/ |
|
20 | ||
21 |
# SECURITY WARNING: keep the secret key used in production secret! |
|
22 |
SECRET_KEY = 'please-change-me-with-a-very-long-random-string' |
|
23 | ||
24 |
# SECURITY WARNING: don't run with debug turned on in production! |
|
25 |
DEBUG = True |
|
26 |
TEMPLATE_DEBUG = True |
|
27 | ||
28 |
# See https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts |
|
29 |
ALLOWED_HOSTS = [] |
|
30 | ||
31 |
DATABASES = { |
|
32 |
'default': { |
|
33 |
'ENGINE': 'django.db.backends.sqlite3', |
|
34 |
'NAME': 'passerelle.sqlite3', |
|
35 |
} |
|
36 |
} |
|
37 | ||
38 |
### End of "Quick-start development settings" |
|
39 | ||
40 | ||
41 |
# If you set this to False, Django will not format dates, numbers and |
|
42 |
# calendars according to the current locale. |
|
43 |
USE_L10N = True |
|
44 | ||
45 |
# If you set this to False, Django will not use timezone-aware datetimes. |
|
46 |
USE_TZ = True |
|
47 | ||
48 |
# URL that handles the media served from MEDIA_ROOT. Make sure to use a |
|
49 |
# trailing slash. |
|
50 |
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/" |
|
51 |
MEDIA_URL = '/media/' |
|
52 | ||
53 |
# URL prefix for static files. |
|
54 |
# Example: "http://media.lawrence.com/static/" |
|
55 |
STATIC_URL = '/static/' |
|
56 | ||
57 |
# Additional locations of static files |
|
58 |
STATICFILES_DIRS = (os.path.join(PACKAGE_PATH, 'static'),) |
|
59 | ||
60 |
# List of finder classes that know how to find static files in |
|
61 |
# various locations. |
|
62 |
STATICFILES_FINDERS = global_settings.STATICFILES_FINDERS + ('gadjo.finders.XStaticFinder',) |
|
63 | ||
64 |
MIDDLEWARE_CLASSES = global_settings.MIDDLEWARE_CLASSES + ( |
|
65 |
'django.contrib.sessions.middleware.SessionMiddleware', |
|
66 |
'django.middleware.locale.LocaleMiddleware', |
|
67 |
'django.contrib.auth.middleware.AuthenticationMiddleware', |
|
68 |
'django.contrib.messages.middleware.MessageMiddleware', |
|
69 |
'passerelle.base.middleware.SearchApiUser' |
|
70 |
) |
|
71 | ||
72 |
ROOT_URLCONF = 'passerelle.urls' |
|
73 | ||
74 |
# Python dotted path to the WSGI application used by Django's runserver. |
|
75 |
WSGI_APPLICATION = 'passerelle.wsgi.application' |
|
76 | ||
77 |
LOCALE_PATHS = (os.path.join(PACKAGE_PATH, 'locale'),) |
|
78 |
LANGUAGE_CODE = 'fr-fr' |
|
79 | ||
80 |
TEMPLATE_DIRS = (os.path.join(PACKAGE_PATH, 'templates'),) |
|
81 | ||
82 |
TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + ( |
|
83 |
'django.core.context_processors.request', |
|
84 |
'passerelle.base.context_processors.template_vars', |
|
85 |
) |
|
86 | ||
87 |
INSTALLED_APPS = ( |
|
88 |
# system apps |
|
89 |
'django.contrib.auth', |
|
90 |
'django.contrib.contenttypes', |
|
91 |
'django.contrib.sessions', |
|
92 |
'django.contrib.messages', |
|
93 |
'django.contrib.staticfiles', |
|
94 |
'django.contrib.admin', |
|
95 |
'south', |
|
96 |
# base apps |
|
97 |
'passerelle.base', |
|
98 |
'passerelle.datasources', |
|
99 |
'passerelle.repost', |
|
100 |
# connectors |
|
101 |
'clicrdv', |
|
102 |
'gdc', |
|
103 |
'choosit', |
|
104 |
'oxyd', |
|
105 |
'ovh', |
|
106 |
'mobyt', |
|
107 |
'pastell', |
|
108 |
'concerto', |
|
109 |
'bdp', |
|
110 |
# backoffice templates and static |
|
111 |
'gadjo', |
|
112 |
) |
|
113 | ||
114 |
LOGIN_REDIRECT_URL = 'homepage' |
|
115 |
passerelle/settings.py | ||
---|---|---|
1 |
from django.conf.global_settings import * |
|
2 |
from passerelle.default_settings import * |
|
3 |
from django.core.exceptions import ImproperlyConfigured |
|
1 |
# Django default settings for passerelle project. |
|
4 | 2 | |
3 |
from django.conf import global_settings |
|
5 | 4 |
import os |
6 | 5 |
import logging |
6 |
try: |
|
7 |
from logging.handlers import NullHandler |
|
8 |
except ImportError: |
|
9 |
# python < 2.7 |
|
10 |
class NullHandler(logging.Handler): |
|
11 |
def emit(self, record): |
|
12 |
pass |
|
7 | 13 | |
8 |
if 'DJANGO_CONFIG_FILE' in os.environ: |
|
9 |
logging.getLogger('passerelle').debug('Loading setting file %r', os.environ['DJANGO_CONFIG_FILE']) |
|
10 |
execfile(os.environ['DJANGO_CONFIG_FILE']) |
|
14 |
logging.getLogger('passerelle').addHandler(NullHandler()) |
|
11 | 15 | |
12 |
if 'DATABASES' not in globals(): |
|
13 |
logging.getLogger('passerelle').error('Unable to boot: You must define a DATABASES in your settings') |
|
14 |
raise ImproperlyConfigured('You must define a DATABASES variable in your settings') |
|
16 |
PACKAGE_PATH = os.path.dirname(__file__) |
|
17 | ||
18 |
### Quick-start development settings - unsuitable for production |
|
19 |
# See https://docs.djangoproject.com/en/dev/howto/deployment/checklist/ |
|
20 | ||
21 |
# SECURITY WARNING: keep the secret key used in production secret! |
|
22 |
SECRET_KEY = 'please-change-me-with-a-very-long-random-string' |
|
23 | ||
24 |
# SECURITY WARNING: don't run with debug turned on in production! |
|
25 |
DEBUG = True |
|
26 |
TEMPLATE_DEBUG = True |
|
27 | ||
28 |
# See https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts |
|
29 |
ALLOWED_HOSTS = [] |
|
30 | ||
31 |
DATABASES = { |
|
32 |
'default': { |
|
33 |
'ENGINE': 'django.db.backends.sqlite3', |
|
34 |
'NAME': 'passerelle.sqlite3', |
|
35 |
} |
|
36 |
} |
|
37 | ||
38 |
### End of "Quick-start development settings" |
|
39 | ||
40 | ||
41 |
# If you set this to False, Django will not format dates, numbers and |
|
42 |
# calendars according to the current locale. |
|
43 |
USE_L10N = True |
|
44 | ||
45 |
# If you set this to False, Django will not use timezone-aware datetimes. |
|
46 |
USE_TZ = True |
|
47 | ||
48 |
# URL that handles the media served from MEDIA_ROOT. Make sure to use a |
|
49 |
# trailing slash. |
|
50 |
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/" |
|
51 |
MEDIA_URL = '/media/' |
|
52 | ||
53 |
# URL prefix for static files. |
|
54 |
# Example: "http://media.lawrence.com/static/" |
|
55 |
STATIC_URL = '/static/' |
|
56 | ||
57 |
# Additional locations of static files |
|
58 |
STATICFILES_DIRS = (os.path.join(PACKAGE_PATH, 'static'),) |
|
59 | ||
60 |
# List of finder classes that know how to find static files in |
|
61 |
# various locations. |
|
62 |
STATICFILES_FINDERS = global_settings.STATICFILES_FINDERS + ('gadjo.finders.XStaticFinder',) |
|
63 | ||
64 |
MIDDLEWARE_CLASSES = global_settings.MIDDLEWARE_CLASSES + ( |
|
65 |
'django.contrib.sessions.middleware.SessionMiddleware', |
|
66 |
'django.middleware.locale.LocaleMiddleware', |
|
67 |
'django.contrib.auth.middleware.AuthenticationMiddleware', |
|
68 |
'django.contrib.messages.middleware.MessageMiddleware', |
|
69 |
'passerelle.base.middleware.SearchApiUser' |
|
70 |
) |
|
71 | ||
72 |
ROOT_URLCONF = 'passerelle.urls' |
|
73 | ||
74 |
# Python dotted path to the WSGI application used by Django's runserver. |
|
75 |
WSGI_APPLICATION = 'passerelle.wsgi.application' |
|
76 | ||
77 |
LOCALE_PATHS = (os.path.join(PACKAGE_PATH, 'locale'),) |
|
78 |
LANGUAGE_CODE = 'fr-fr' |
|
79 | ||
80 |
TEMPLATE_DIRS = (os.path.join(PACKAGE_PATH, 'templates'),) |
|
81 | ||
82 |
TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + ( |
|
83 |
'django.core.context_processors.request', |
|
84 |
'passerelle.base.context_processors.template_vars', |
|
85 |
) |
|
86 | ||
87 |
INSTALLED_APPS = ( |
|
88 |
# system apps |
|
89 |
'django.contrib.auth', |
|
90 |
'django.contrib.contenttypes', |
|
91 |
'django.contrib.sessions', |
|
92 |
'django.contrib.messages', |
|
93 |
'django.contrib.staticfiles', |
|
94 |
'django.contrib.admin', |
|
95 |
'south', |
|
96 |
# base apps |
|
97 |
'passerelle.base', |
|
98 |
'passerelle.datasources', |
|
99 |
'passerelle.repost', |
|
100 |
# connectors |
|
101 |
'clicrdv', |
|
102 |
'gdc', |
|
103 |
'choosit', |
|
104 |
'oxyd', |
|
105 |
'ovh', |
|
106 |
'mobyt', |
|
107 |
'pastell', |
|
108 |
'concerto', |
|
109 |
'bdp', |
|
110 |
# backoffice templates and static |
|
111 |
'gadjo', |
|
112 |
) |
|
113 | ||
114 |
LOGIN_REDIRECT_URL = 'homepage' |
|
115 | ||
116 | ||
117 |
local_settings_file = os.environ.get('PASSERELLE_SETTINGS_FILE', |
|
118 |
os.path.join(os.path.dirname(__file__), 'local_settings.py')) |
|
119 |
if os.path.exists(local_settings_file): |
|
120 |
execfile(local_settings_file) |
passerelle/tenant_settings.py | ||
---|---|---|
1 |
from django.conf.global_settings import * |
|
2 |
from passerelle.default_settings import * |
|
3 |
from django.core.exceptions import ImproperlyConfigured |
|
4 | ||
5 |
import os |
|
6 |
import logging |
|
7 | ||
8 |
try: |
|
9 |
import entrouvert |
|
10 |
except ImportError: |
|
11 |
raise ImproperlyConfigured('python-entrouvert MUST be installed for the multitenant mode to work') |
|
12 | ||
13 |
SOUTH_TESTS_MIGRATE = False |
|
14 |
TEMPLATE_LOADERS = ('entrouvert.djommon.multitenant.template_loader.FilesystemLoader',) + TEMPLATE_LOADERS |
|
15 |
DEFAULT_FILE_STORAGE = 'entrouvert.djommon.multitenant.storage.TenantFileSystemStorage' |
|
16 |
MIDDLEWARE_CLASSES = ( |
|
17 |
'entrouvert.djommon.multitenant.middleware.TenantMiddleware', |
|
18 |
'entrouvert.djommon.multitenant.middleware.JSONSettingsMiddleware', |
|
19 |
'entrouvert.djommon.multitenant.middleware.PythonSettingsMiddleware', |
|
20 |
) + MIDDLEWARE_CLASSES |
|
21 |
INSTALLED_APPS = INSTALLED_APPS + ('entrouvert.djommon.multitenant',) |
|
22 |
TENANT_APPS = INSTALLED_APPS |
|
23 | ||
24 |
TENANT_MODEL = 'multitenant.Tenant' |
|
25 |
SOUTH_DATABASE_ADAPTERS = { |
|
26 |
'default': 'south.db.postgresql_psycopg2', |
|
27 |
} |
|
28 |
SHARED_APPS = ( |
|
29 |
'django.contrib.staticfiles', |
|
30 |
'django.contrib.auth', |
|
31 |
'django.contrib.contenttypes', |
|
32 |
'django.contrib.sessions', |
|
33 |
'django.contrib.messages', |
|
34 |
) |
|
35 | ||
36 |
if 'DJANGO_CONFIG_FILE' in os.environ: |
|
37 |
logging.getLogger('passerelle').debug('Loading setting file %r', os.environ['DJANGO_CONFIG_FILE']) |
|
38 |
execfile(os.environ['DJANGO_CONFIG_FILE']) |
|
39 | ||
40 |
if 'TENANT_BASE' not in globals(): |
|
41 |
logging.getLogger('passerelle').error('Unable to boot: You must define a TENANT_BASE in your settings') |
|
42 |
raise ImproperlyConfigured('You must define a TENANT_BASE in your settings') |
|
43 | ||
44 |
if 'DATABASES' not in globals(): |
|
45 |
logging.getLogger('passerelle').error('Unable to boot: You must define a DATABASES in your settings') |
|
46 |
raise ImproperlyConfigured('You must define a DATABASES variable in your settings') |
|
47 | ||
48 |
if DATABASES['default']['ENGINE'] != 'django.db.backends.postgresql_psycopg2': |
|
49 |
raise ImproperlyConfigured('MULTITENANT only work with a postgresql database') |
|
50 |
DATABASES['default']['ENGINE'] = 'tenant_schemas.postgresql_backend' |
|
51 |
- |