settings can be modified in myslice.ini
[unfold.git] / myslice / settings.py
1 from __future__ import print_function
2
3 import myslice.components
4 from myslice.configengine import ConfigEngine
5
6 import os.path
7
8 # import djcelery
9 # djcelery.setup_loader()
10
11 ### detect if we're in a build environment
12 try:
13     import manifold
14     building=False
15 except:
16     building=True
17
18 config = ConfigEngine()
19
20 if config.myslice.debug :
21     DEBUG = True
22 else :
23     DEBUG = False
24
25 # show the various settings as we go
26 DEBUG_SETTINGS = False
27
28 # but you can redefine ROOT if that's not working for you
29 try:
30     # get the directory where this file is
31     ROOT = os.path.realpath(os.path.dirname(__file__) + '/..')
32 except:
33     # something is badly wrong here
34     ROOT = None
35     import traceback
36     traceback.print_exc()
37
38 #### this is where the problem lies I believe
39 # first try to run manage.py collectstatic without this
40 # themes
41 if config.myslice.theme :
42     theme = config.myslice.theme
43 else :
44     theme = None
45
46 # HTTPROOT
47 if config.myslice.httproot :
48     HTTPROOT = config.myslice.httproot
49 else :
50     HTTPROOT = "/var/myslice-f4f"
51
52 # DATAROOT
53 if config.myslice.httproot :
54     DATAROOT = config.myslice.httproot
55 else :
56     DATAROOT = "/var/unfold"
57
58 if not os.path.isdir(DATAROOT):
59     print("WARNING: {} is a non-existing directory".format(DATAROOT))
60     print("consequently we assume development mode and re-route DATAROOT to {}".format(ROOT))
61     DATAROOT=ROOT
62
63 # if not there, then we assume it's from a devel tree
64 if not os.path.isdir (os.path.join(HTTPROOT,"static")):
65     HTTPROOT=ROOT
66
67 if not os.path.isdir(ROOT): raise Exception,"Cannot find ROOT %s for unfold"%ROOT
68 if not os.path.isdir(HTTPROOT): raise Exception,"Cannot find HTTPROOT %s for unfold"%HTTPROOT
69
70 if DEBUG_SETTINGS:
71     print('ROOT', ROOT)
72     print('DATAROOT', DATAROOT)
73     print('HTTPROOT', HTTPROOT)
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 EMAIL_HOST = "localhost"
95 EMAIL_PORT = 25
96 EMAIL_USE_TLS = False
97
98 # use the email for debugging purpose
99 # turn on debugging: 
100 # python -m smtpd -n -c DebuggingServer localhost:1025
101
102 #if DEBUG:
103 #    EMAIL_HOST = 'localhost'
104 #    EMAIL_PORT = 1025
105 #    EMAIL_HOST_USER = ''
106 #    EMAIL_HOST_PASSWORD = ''
107 #    EMAIL_USE_TLS = False
108 #    DEFAULT_FROM_EMAIL = 'testing@example.com'
109
110 DATABASES = {
111     'default': {
112         'ENGINE'    : 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
113         'NAME'      : os.path.join(DATAROOT,'unfold.sqlite3'), # Or path to database file if using sqlite3.
114         'USER'      : '',                      # Not used with sqlite3.
115         'PASSWORD'  : '',                  # Not used with sqlite3.
116         'HOST'      : '',                      # Set to empty string for localhost. Not used with sqlite3.
117         'PORT'      : '',                      # Set to empty string for default. Not used with sqlite3.
118     }
119 }
120
121 if DEBUG_SETTINGS:
122     print('DATABASE NAME',DATABASES['default']['NAME'])
123
124 # Local time zone for this installation. Choices can be found here:
125 # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
126 # although not all choices may be available on all operating systems.
127 # In a Windows environment this must be set to your system time zone.
128 TIME_ZONE = 'Europe/Paris'
129
130 # Language code for this installation. All choices can be found here:
131 # http://www.i18nguy.com/unicode/language-identifiers.html
132 LANGUAGE_CODE = 'en-us'
133
134 SITE_ID = 1
135
136 # If you set this to False, Django will make some optimizations so as not
137 # to load the internationalization machinery.
138 USE_I18N = True
139
140 # If you set this to False, Django will not format dates, numbers and
141 # calendars according to the current locale.
142 USE_L10N = True
143
144 # If you set this to False, Django will not use timezone-aware datetimes.
145 USE_TZ = True
146
147 # Absolute filesystem path to the directory that will hold user-uploaded files.
148 # Example: "/home/media/media.lawrence.com/media/"
149 MEDIA_ROOT = ''
150
151 # URL that handles the media served from MEDIA_ROOT. Make sure to use a
152 # trailing slash.
153 # Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
154 MEDIA_URL = ''
155
156 # Absolute path to the directory static files should be collected to.
157 # Don't put anything in this directory yourself; store your static files
158 # in apps' "static/" subdirectories and in STATICFILES_DIRS.
159 # Example: "/home/media/media.lawrence.com/static/"
160 STATIC_ROOT = os.path.join(HTTPROOT,'static')
161
162 # URL prefix for static files.
163 # Example: "http://media.lawrence.com/static/"
164 STATIC_URL = '/static/'
165
166 # Additional locations of static files
167 STATICFILES_DIRS = (
168     # Put strings here, like "/home/html/static" or "C:/www/django/static".
169     # Always use forward slashes, even on Windows.
170     # Don't forget to use absolute paths, not relative paths.
171     # Thierry : we do not need to detail the contents 
172     # of our 'apps' since they're mentioned in INSTALLED_APPS
173 )
174
175 # Needed by PluginFinder
176 PLUGIN_DIR = os.path.join(ROOT,'plugins')
177 # ThirdPartyFinder
178 THIRDPARTY_DIR = os.path.join(ROOT, 'third-party')
179
180 # List of finder classes that know how to find static files in
181 # various locations.
182 STATICFILES_FINDERS = (
183 # Thierry : no need for this one    
184 #    'django.contrib.staticfiles.finders.FileSystemFinder',
185     'django.contrib.staticfiles.finders.AppDirectoriesFinder',
186     'unfold.collectstatic.PluginFinder',
187     'unfold.collectstatic.ThirdPartyFinder',
188 ###    'django.contrib.staticfiles.finders.DefaultStorageFinder',
189 )
190
191 #TEMPLATE_CONTEXT_PROCESSORS = (
192 #    'django.contrib.auth.context_processors.auth',
193 #    'django.core.context_processors.debug',
194 #    'django.core.context_processors.i18n',
195 #    'django.core.context_processors.media',
196 #    'django.core.context_processors.static',
197 #    'django.core.context_processors.request',
198 #    'django.contrib.messages.context_processors.messages',
199 #)
200
201 # Make this unique, and don't share it with anybody.
202 SECRET_KEY = 't%n(3h)&r^n8(+8)(sp29t^$c2#t(m3)e2!02l8w1#36tl#t27'
203
204 # List of callables that know how to import templates from various sources.
205 TEMPLATE_LOADERS = (
206     'django.template.loaders.filesystem.Loader',
207     'django.template.loaders.app_directories.Loader',
208 #     'django.template.loaders.eggs.Loader',
209 )
210
211 MIDDLEWARE_CLASSES = (
212     'django.middleware.common.CommonMiddleware',
213     'django.contrib.sessions.middleware.SessionMiddleware',
214     'django.middleware.csrf.CsrfViewMiddleware',
215     'django.contrib.auth.middleware.AuthenticationMiddleware',
216     'django.contrib.messages.middleware.MessageMiddleware',
217     # Uncomment the next line for simple clickjacking protection:
218     # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
219 )
220
221 ROOT_URLCONF = 'myslice.urls'
222
223 # Python dotted path to the WSGI application used by Django's runserver.
224 WSGI_APPLICATION = 'unfold.wsgi.application'
225
226 TEMPLATE_DIRS = [ ]
227 # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
228 # Always use forward slashes, even on Windows.
229 # Don't forget to use absolute paths, not relative paths.
230 if theme is not None:
231     TEMPLATE_DIRS.append ( os.path.join(HTTPROOT,"portal/templates", theme))
232 TEMPLATE_DIRS.append     ( os.path.join(HTTPROOT,"portal/templates"))
233 TEMPLATE_DIRS.append     (  os.path.join(HTTPROOT,"templates"))
234
235 INSTALLED_APPS = [ 
236     'django.contrib.auth',
237     'django.contrib.contenttypes',
238     'django.contrib.sessions',
239     'django.contrib.sites',
240     'django.contrib.messages',
241     'django.contrib.staticfiles',
242     # handling the {% insert %} and {% container %} tags
243     # see details in devel/django-insert-above-1.0-4
244     'insert_above',
245     # our django project
246     'myslice',
247     # the core of the UI
248     'auth', 
249     'manifoldapi',
250     'unfold',
251     # plugins
252     'plugins',
253     # views - more or less stable 
254     'ui',
255     # managing database migrations
256     'south', 
257     # Uncomment the next line to enable the admin:
258      'django.contrib.admin',
259         # FORGE Plugin app
260 #       'djcelery',
261     # Uncomment the next line to enable admin documentation:
262     # 'django.contrib.admindocs',
263     'portal',
264 ]
265 # this app won't load in a build environment
266 if not building: INSTALLED_APPS.append ('rest')
267
268 for component in components.list() :
269     INSTALLED_APPS.append(component)
270
271 BROKER_URL = "amqp://myslice:myslice@localhost:5672/myslice"
272
273 for aux in auxiliaries:
274     if os.path.isdir(os.path.join(ROOT,aux)): 
275         print("Using devel auxiliary",aux)
276         INSTALLED_APPS.append(aux)
277
278 ACCOUNT_ACTIVATION_DAYS = 7 # One-week activation window; you may, of course, use a different value.
279
280 # A sample logging configuration. The only tangible logging
281 # performed by this configuration is to send an email to
282 # the site admins on every HTTP 500 error when DEBUG=False.
283 # See http://docs.djangoproject.com/en/dev/topics/logging for
284 # more details on how to customize your logging configuration.
285 LOGGING = {
286     'version': 1,
287     'disable_existing_loggers': False,
288     'filters': {
289         'require_debug_false': {
290             '()': 'django.utils.log.RequireDebugFalse'
291         }
292     },
293     'handlers': {
294         'mail_admins': {
295             'level': 'ERROR',
296             'filters': ['require_debug_false'],
297             'class': 'django.utils.log.AdminEmailHandler',
298         }
299     },
300     'loggers': {
301         'django.request': {
302             'handlers': ['mail_admins'],
303             'level': 'ERROR',
304             'propagate': True,
305         },
306     }
307 }
308
309 AUTHENTICATION_BACKENDS = ('auth.manifoldbackend.ManifoldBackend',
310                            'django.contrib.auth.backends.ModelBackend')
311
312 ### the view to redirect malformed (i.e. with a wrong CSRF) incoming requests
313 # without this setting django will return a 403 forbidden error, which is fine
314 # if you need to see the error message then use this setting
315 CSRF_FAILURE_VIEW = 'manifoldapi.manifoldproxy.csrf_failure'
316
317 #################### for insert_above
318 #IA_JS_FORMAT = "<script type='text/javascript' src='{URL}' />"
319 # put stuff under static/
320 # IA_MEDIA_PREFIX = '/code/'
321
322 ####SLA#####
323
324 SLA_MANAGER_URL = "http://157.193.215.125:4001/sla-collector/sla"
325 #SLA_MANAGER_URL = "http://172.24.76.28:8000/sla"
326 SLA_MANAGER_USER = "portal"
327 SLA_MANAGER_PASSWORD = "password"