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