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