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