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