Gitlab CSE Unil

base.py 5.88 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""Common settings and globals."""
from os.path import abspath, basename, dirname, join, normpath
from sys import path, modules
from django.core.exceptions import ImproperlyConfigured


# ========== PATH CONFIGURATION
#
# Absolute filesystem path to the Django project directory:
DJANGO_ROOT = dirname(dirname(abspath(__file__)))

# Absolute filesystem path to the top-level project folder:
SITE_ROOT = dirname(DJANGO_ROOT)

# Site name:
SITE_NAME = basename(DJANGO_ROOT)

# Add our project to our pythonpath, this way we don't need to type our project
# name in our dotted import paths:
path.append(DJANGO_ROOT)
# ---------- END PATH CONFIGURATION


# ========== LOAD SECRETS
try:
    from .components.private import *
except ImportError:
    raise ImproperlyConfigured("Unable to load private configuration. "
                               "Please add a SECRET_KEY in {}/settings/components/private.py".format(SITE_NAME))


# ========== DJANGO GENERAL CONFIGURATIONS
#
# ..... MANAGEMENT
DEBUG = False
ALLOWED_HOSTS = []
ADMINS = (
    ('Julien Furrer', 'julien.furrer@unil.ch'),
)
MANAGERS = ADMINS

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': '127.0.0.1:11211',
    }
}


# ..... TEMPLATES CONFIG
TEMPLATES = [{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
Julien Furrer's avatar
Julien Furrer committed
62
    'DIRS': (normpath(join(SITE_ROOT, 'templates')), ),
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
    'OPTIONS': {
        'debug': False,
        'loaders': (
            'django.template.loaders.filesystem.Loader',
            'django.template.loaders.app_directories.Loader'
        ),
        'context_processors': [
            'django.contrib.auth.context_processors.auth',
            'django.core.context_processors.debug',
            'django.core.context_processors.i18n',
            'django.core.context_processors.media',
            'django.core.context_processors.static',
            'django.core.context_processors.request',
            'django.core.context_processors.tz',
            'django.contrib.messages.context_processors.messages',
Julien Furrer's avatar
Julien Furrer committed
78
            'adim_utils.context_processors.default',
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
        ],
        'string_if_invalid': "",
    }
}]

# backward compatibility
TEMPLATE_DIRS = TEMPLATES[0]['DIRS']
TEMPLATE_CONTEXT_PROCESSORS = TEMPLATES[0]['OPTIONS']['context_processors']
TEMPLATE_DEBUG = TEMPLATES[0]['OPTIONS']['debug']
TEMPLATE_LOADERS = TEMPLATES[0]['OPTIONS']['loaders']
TEMPLATE_STRING_IF_INVALID = TEMPLATES[0]['OPTIONS']['string_if_invalid']


# ..... MEDIA AND STATICS PATHS
MEDIA_ROOT = normpath(join(SITE_ROOT, 'media'))
STATIC_ROOT = normpath(join(SITE_ROOT, 'static'))


# ..... Localization
LANGUAGE_CODE = 'fr-ch'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
SITE_ID = 1


# ..... Application
ROOT_URLCONF = '%s.urls' % SITE_NAME
WSGI_APPLICATION = '%s.wsgi.application' % SITE_NAME

# ---------- END DJANGO GENERAL CONFIGURATION


# ========== URL CONFIGURATION
#
Julien Furrer's avatar
Julien Furrer committed
115
116
def update_urls(base_url=None, name=__name__):
    this_module = modules[name]
117
118
    if base_url is None:
        base_url = getattr(this_module, 'BASE_URL', "/")
119
    setattr(this_module, 'BASE_URL', base_url)
120
121
122
123
124
    setattr(this_module, 'SESSION_COOKIE_PATH', base_url)
    setattr(this_module, 'CSRF_COOKIE_PATH', base_url)
    setattr(this_module, 'MEDIA_URL', '{}media/'.format(base_url))
    setattr(this_module, 'STATIC_URL', '{}static/'.format(base_url))

Julien Furrer's avatar
Julien Furrer committed
125
update_urls("/")
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# ---------- END URL CONFIGURATION


# ========== AUTHENTICATION
#
AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
)

LOGIN_REDIRECT_URL = "adim.app:annotate-new"
LOGIN_URL = "adim.app:home"

SESSION_EXPIRE_AT_BROWSER_CLOSE = True
# ---------- END AUTHENTICATION


# ========== LOCAL APPS CONFIGURATION
#
LOCAL_APPS = ('django_extensions',)

# ..... MISC
SENDFILE_BACKEND = 'sendfile.backends.xsendfile'


# ..... REST FRAMEWORK
LOCAL_APPS += ('rest_framework',)
REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.SessionAuthentication',
        'rest_framework.authentication.TokenAuthentication',
    ),
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.IsAuthenticated'
    ]
}

# ..... SHIBAUTH
LOCAL_APPS += ('shibauth', )
AUTHENTICATION_BACKENDS = ('shibauth.shibbolethbackends.ShibbolethBackend',) + AUTHENTICATION_BACKENDS

try:
    from .components.shibbauth import *
except ImportError:
    raise ImproperlyConfigured("Unable to import SHIBAUTH configurations")


# ..... ADIM
LOCAL_APPS += ('adim', 'adim_app',)
# Max file size in Mb
ADIM_UPLOAD_MAX_FILESIZE = 50

# Size of the Thumbnail
ADIM_THUMB_SIZE = (150, 150)

# When in PROD, DEBUG_JS if False and uses prod ready css too
ADIM_PROD = True

# If True load the non-minified version of adim js
ADIM_DEBUG_JS = False

# If the number of suggested adim-user is less than this value,
# the ldap will be queried too
ADIM_SUGGESTION = {
    'LIMIT': 7,
    'LDAP': {
        'URL': "ldap://ldap.unil.ch:389",
        'BASE': "o=universite de lausanne, c=ch",
        'TIMEOUT': 3
    }
}

AAI = {
    'SLO': True,
    # Not yet used
    'URLS': {
        'SP_LOGOUT': "https://jabba.unil.ch/Shibboleth.sso/Logout",
        'idp_LOGOUT': "https://aai.unil.ch/idp/logout.jsp"
    }
}

# ---------- END LOCAL APPS CONFIGURATION


# ========== APPS CONFIGURATION
#
DJANGO_APPS = (
    'django.contrib.sites',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
)
INSTALLED_APPS = DJANGO_APPS + LOCAL_APPS
# ---------- END APPS CONFIGURATION