fc09fc343292a72f344fe6047f9a3d4cfe7d50a2
[unfold.git] / myslice / settings.py
1 import os.path
2 import logging
3 import subprocess
4
5
6 logger = logging.getLogger('myslice')
7
8 # ROOT
9 try:
10     ROOT = os.path.realpath(os.path.dirname(__file__) + '/..')
11 except:
12     import traceback
13     logger.error(traceback.format_exc())
14
15
16 from myslice.configengine import ConfigEngine
17
18 config = ConfigEngine()
19
20 import myslice.components as components
21
22 # import djcelery
23 # djcelery.setup_loader()
24
25 ### detect if we're in a build environment
26 try:
27     import manifold
28     building=False
29 except:
30     building=True
31
32 if not config.myslice.portal_version:
33     try:
34         PORTAL_VERSION = subprocess.check_output(["git", "describe"])
35     except:
36         PORTAL_VERSION = 'not using git' 
37
38 # DEBUG
39 if config.myslice.debug :
40     DEBUG = True
41     INTERNAL_IPS = ("127.0.0.1","132.227.84.195","132.227.78.191","132.227.84.191")
42 else :
43     DEBUG = False
44
45 # theme
46 if config.myslice.theme :
47     theme = config.myslice.theme
48 else :
49     theme = None
50
51 if config.myslice.theme_label :
52     theme_label = config.myslice.theme_label
53 else :
54     theme_label = theme
55
56 if config.myslice.theme_logo :
57     theme_logo = config.myslice.theme_logo
58 else :
59     theme_logo = theme + '.png'
60
61 # HTTPROOT
62 if config.myslice.httproot :
63     HTTPROOT = config.myslice.httproot
64 else :
65     HTTPROOT = ROOT
66
67 # DATAROOT
68 if config.myslice.httproot :
69     DATAROOT = config.myslice.dataroot
70 else :
71     DATAROOT = ROOT
72
73
74 # dec 2013 - we currently have 2 auxiliary subdirs with various utilities
75 # that we do not wish to package 
76 # * sandbox is for plugin developers
77 # * sample is for various test views
78 # for each of these, if we find a directory of that name under ROOT, it then gets
79 # inserted in INSTALLED_APPS and its urls get included (see urls.py)
80 auxiliaries = [ 'sandbox', 'sample', ]
81
82 ####################
83 ADMINS = (
84     # ('your_name', 'your_email@test.com'),
85 )
86
87 MANAGERS = ADMINS
88
89 # Mail configuration
90 #DEFAULT_FROM_EMAIL = "root@theseus.ipv6.lip6.fr"
91 #EMAIL_HOST_PASSWORD = "mypassword"
92
93 DEFAULT_FROM_EMAIL = "OneLab Support <support@onelab.eu>"
94 EMAIL_HOST = "localhost"
95 EMAIL_PORT = 25
96 EMAIL_USE_TLS = False
97
98 # use the email for debugging purpose
99 # turn on debugging: 
100 # python -m smtpd -n -c DebuggingServer localhost:1025
101
102 #if DEBUG:
103 #    EMAIL_HOST = 'localhost'
104 #    EMAIL_PORT = 1025
105 #    EMAIL_HOST_USER = ''
106 #    EMAIL_HOST_PASSWORD = ''
107 #    EMAIL_USE_TLS = False
108 #    DEFAULT_FROM_EMAIL = 'testing@example.com'
109
110 if config.database.engine : 
111     DATABASES = {
112         'default': {
113             'ENGINE'    : 'django.db.backends.%s' % config.database.engine,
114             'USER'      : config.database.user or '',
115             'PASSWORD'  : config.database.password or '',
116             'HOST'      : config.database.host or '',
117             'PORT'      : config.database.port or '',
118         }
119     }
120     if config.database.engine == 'sqlite3' :
121         DATABASES['default']['NAME'] = os.path.join(DATAROOT,'%s.sqlite3' % config.database.name)
122     else :
123         DATABASES['default']['NAME'] = config.database.name
124 else :
125     # default database is sqlite
126     DATABASES = {
127         'default': {
128             'ENGINE'    : 'django.db.backends.sqlite3',
129             'NAME'      : os.path.join(DATAROOT,'myslice.sqlite3'),
130             'USER'      : '',
131             'PASSWORD'  : '',
132             'HOST'      : '',
133             'PORT'      : '',
134         }
135     }
136
137 # Local time zone for this installation. Choices can be found here:
138 # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
139 # although not all choices may be available on all operating systems.
140 # In a Windows environment this must be set to your system time zone.
141 TIME_ZONE = 'Europe/Paris'
142
143 # Language code for this installation. All choices can be found here:
144 # http://www.i18nguy.com/unicode/language-identifiers.html
145 LANGUAGE_CODE = 'en-us'
146
147 SITE_ID = 1
148
149 # If you set this to False, Django will make some optimizations so as not
150 # to load the internationalization machinery.
151 USE_I18N = True
152
153 # If you set this to False, Django will not format dates, numbers and
154 # calendars according to the current locale.
155 USE_L10N = True
156
157 # If you set this to False, Django will not use timezone-aware datetimes.
158 USE_TZ = True
159
160 # Absolute filesystem path to the directory that will hold user-uploaded files.
161 # Example: "/home/media/media.lawrence.com/media/"
162 MEDIA_ROOT = ''
163
164 # URL that handles the media served from MEDIA_ROOT. Make sure to use a
165 # trailing slash.
166 # Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
167 MEDIA_URL = ''
168
169 # Absolute path to the directory static files should be collected to.
170 # Don't put anything in this directory yourself; store your static files
171 # in apps' "static/" subdirectories and in STATICFILES_DIRS.
172 # Example: "/home/media/media.lawrence.com/static/"
173 STATIC_ROOT = os.path.join(HTTPROOT,'static')
174
175 # Additional locations of static files
176 STATICFILES_DIRS = (
177     # Put strings here, like "/home/html/static" or "C:/www/django/static".
178     # Always use forward slashes, even on Windows.
179     # Don't forget to use absolute paths, not relative paths.
180     # Thierry : we do not need to detail the contents 
181     # of our 'apps' since they're mentioned in INSTALLED_APPS
182 )
183
184 # Needed by PluginFinder
185 PLUGIN_DIR = os.path.join(ROOT,'plugins')
186 # ThirdPartyFinder
187 THIRDPARTY_DIR = os.path.join(ROOT, 'third-party')
188
189 # List of finder classes that know how to find static files in
190 # various locations.
191 STATICFILES_FINDERS = (
192 # Thierry : no need for this one    
193 #    'django.contrib.staticfiles.finders.FileSystemFinder',
194     'django.contrib.staticfiles.finders.AppDirectoriesFinder',
195     'unfold.collectstatic.PluginFinder',
196     'unfold.collectstatic.ThirdPartyFinder',
197 ###    'django.contrib.staticfiles.finders.DefaultStorageFinder',
198 )
199
200 if config.myslice.secret_key:
201     # Make this unique, and don't share it with anybody.
202     SECRET_KEY = config.myslice.secret_key
203 else:
204     raise Exception, "SECRET_KEY Not defined: Please setup a secret_key value in myslice.ini"
205
206 AUTHENTICATION_BACKENDS = ('localauth.manifoldbackend.ManifoldBackend',
207                            'django.contrib.auth.backends.ModelBackend')
208
209 # List of callables that know how to import templates from various sources.
210 TEMPLATE_LOADERS = (
211     'django.template.loaders.filesystem.Loader',
212     'django.template.loaders.app_directories.Loader',
213 #     'django.template.loaders.eggs.Loader',
214 )
215
216 MIDDLEWARE_CLASSES = (
217     'django.middleware.common.CommonMiddleware',
218     'django.contrib.sessions.middleware.SessionMiddleware',
219     'django.middleware.csrf.CsrfViewMiddleware',
220     'django.contrib.auth.middleware.AuthenticationMiddleware',
221     'django.contrib.messages.middleware.MessageMiddleware',
222     # Uncomment the next line for simple clickjacking protection:
223     # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
224 )
225
226 ROOT_URLCONF = 'myslice.urls'
227
228 # Python dotted path to the WSGI application used by Django's runserver.
229 WSGI_APPLICATION = 'unfold.wsgi.application'
230
231 TEMPLATE_DIRS = []
232 # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
233 # Always use forward slashes, even on Windows.
234 # Don't forget to use absolute paths, not relative paths.
235 if theme is not None:
236     TEMPLATE_DIRS.append( os.path.join(HTTPROOT,"portal/templates", theme) )
237 TEMPLATE_DIRS.append( os.path.join(HTTPROOT,"portal/templates") )
238 TEMPLATE_DIRS.append( os.path.join(HTTPROOT,"templates") )
239
240 INSTALLED_APPS = [ 
241     'django.contrib.auth',
242     'django.contrib.contenttypes',
243     'django.contrib.sessions',
244     'django.contrib.sites',
245     'django.contrib.messages',
246     'django.contrib.staticfiles',
247     # handling the {% insert %} and {% container %} tags
248     # see details in devel/django-insert-above-1.0-4
249     'insert_above',
250     # our django project
251     'myslice',
252     # the core of the UI
253     'localauth', 
254     'manifoldapi',
255     'unfold',
256     # plugins
257     'plugins',
258     # views - more or less stable 
259     'ui',
260     # Uncomment the next line to enable the admin:
261      'django.contrib.admin',
262         # FORGE Plugin app
263 #       'djcelery',
264     # Uncomment the next line to enable admin documentation:
265     # 'django.contrib.admindocs',
266     'portal',
267     #'debug_toolbar',
268 ]
269 # with django-1.7 we leave south and use native migrations
270 # managing database migrations
271 import django
272 major, minor, _, _, _ = django.VERSION
273 if major == 1 and minor <= 6:
274     INSTALLED_APPS.append('south')
275
276 # this app won't load in a build environment
277 if not building:
278     INSTALLED_APPS.append ('rest')
279
280 for component in components.list() :
281     INSTALLED_APPS.append(component)
282
283 BROKER_URL = "amqp://myslice:myslice@localhost:5672/myslice"
284
285 for aux in auxiliaries:
286     if os.path.isdir(os.path.join(ROOT,aux)): 
287         logger.info("Using devel auxiliary {}".format(aux))
288         INSTALLED_APPS.append(aux)
289
290 ACCOUNT_ACTIVATION_DAYS = 7 # One-week activation window; you may, of course, use a different value.
291
292 # A sample logging configuration. The only tangible logging
293 # performed by this configuration is to send an email to
294 # the site admins on every HTTP 500 error when DEBUG=False.
295 # See http://docs.djangoproject.com/en/dev/topics/logging for
296 # more details on how to customize your logging configuration.
297 LOGGING = {
298     'version': 1,
299     'disable_existing_loggers': False,
300     'filters': {
301         'require_debug_false': {
302             '()': 'django.utils.log.RequireDebugFalse'
303         }
304     },
305     'handlers': {
306         'mail_admins': {
307             'level': 'ERROR',
308             'filters': ['require_debug_false'],
309             'class': 'django.utils.log.AdminEmailHandler',
310         }
311     },
312     'loggers': {
313         'django.request': {
314             'handlers': ['mail_admins'],
315             'level': 'ERROR',
316             'propagate': True,
317         },
318     }
319 }
320 LOGGING = {
321     'version': 1,
322     'disable_existing_loggers': True,
323     'formatters': {
324         'verbose': {
325             'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
326         },
327         'simple': {
328             'format': '%(levelname)s %(message)s'
329         },
330     },
331     'filters': {
332         
333     },
334     'handlers': {
335         'null': {
336             'level': 'DEBUG',
337             'class': 'django.utils.log.NullHandler',
338         },
339         'debug':{
340             'level': 'DEBUG',
341             'class': 'logging.StreamHandler',
342             'formatter': 'simple'
343         }
344     },
345     'loggers': {
346         'myslice': {
347             'handlers': ['debug'],
348             'propagate': True,
349             'level': 'DEBUG',
350         }
351     }
352 }
353
354 ### the view to redirect malformed (i.e. with a wrong CSRF) incoming requests
355 # without this setting django will return a 403 forbidden error, which is fine
356 # if you need to see the error message then use this setting
357 CSRF_FAILURE_VIEW = 'manifoldapi.manifoldproxy.csrf_failure'
358
359 #################### for insert_above
360 #IA_JS_FORMAT = "<script type='text/javascript' src='{URL}' />"
361 # put stuff under static/
362 # IA_MEDIA_PREFIX = '/code/'
363
364 ####SLA#####
365
366 SLA_COLLECTOR_URL = "http://157.193.215.125:4001/sla-collector/sla"
367 SLA_COLLECTOR_USER = "portal"
368 SLA_COLLECTOR_PASSWORD = "password"
369
370
371 # URL prefix for static files.
372 # Example: "http://media.lawrence.com/static/"
373 STATIC_URL = '/static/'
374
375