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