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