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