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