Gitlab CSE Unil

Commit 28d93453 authored by Julien Furrer's avatar Julien Furrer
Browse files

Changed settings in TSD way, moved media and static at project level

parent 6ed21432
from split_settings.tools import optional, include
include(
'components/base.py',
'components/database.py',
'components/rest_framework.py',
'components/adim.py',
'components/local_defaults.py',
optional('shib_settings.py'),
optional('local_settings.py'),
'components/urls.py',
'components/auth.py',
'components/paths.py',
scope=locals()
)
\ No newline at end of file
__author__ = 'jfurrer'
"""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',
'DIRS': [],
'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',
'adim_project.context_processors.default',
],
'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
#
def update_urls(base_url=None):
this_module = modules[__name__]
if base_url is None:
base_url = getattr(this_module, 'BASE_URL', "/")
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))
update_urls()
# ---------- 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
"""Shibauth specific settings"""
SHIB_UID_ATTR = 'uniqueID'
SHIB_USERNAME_ATTR = 'mail'
SHIB_ATTR_MAP = {
'user': (
('first_name', 'givenName'),
('last_name', 'surname'),
('email', 'mail'),
),
'profile': (
('homeOrganization', 'homeOrganization'),
('uniqueID', 'uniqueID'),
)
}
SHIB_ATTRIBUTES = {
'affiliation': 'affiliation',
'assurance': 'assurance',
'cardUID': 'cardUID',
'cn': 'cn',
'dateOfBirth': 'dateOfBirth',
'displayName': 'displayName',
'employeeNumber': 'employeeNumber',
'entitlement': 'entitlement',
'gender': 'gender',
'givenName': 'givenName',
'homeOrganization': 'homeOrganization',
'homeOrganizationType': 'homeOrganizationType',
'homePhone': 'homePhone',
'homePostalAddress': 'homePostalAddress',
'isMemberOf': 'isMemberOf',
'mail': 'mail',
'matriculationNumber': 'matriculationNumber',
'mobile': 'mobile',
'nickname': 'nickname',
'org-dn': 'org-dn',
'orgunit-dn': 'orgunit-dn',
'ou': 'ou',
'persistent-id': 'persistent-id',
'postalAddress': 'postalAddress',
'preferredLanguage': 'preferredLanguage',
'primary-orgunit-dn': 'primary-orgunit-dn',
'primaryGroupID': 'primaryGroupID',
'schacHomeOrganization': 'schacHomeOrganization',
'schacHomeOrganizationType': 'schacHomeOrganizationType',
'scoped-affiliation': 'scoped-affiliation',
'staffCategory': 'staffCategory',
'studyBranch1': 'studyBranch1',
'studyBranch2': 'studyBranch2',
'studyBranch3': 'studyBranch3',
'studyLevel': 'studyLevel',
'surname': 'surname',
'targeted-id': 'targeted-id',
'telephoneNumber': 'telephoneNumber',
'uid': 'uid',
'uniqueID': 'uniqueID',
}
SHIB_ATTR_ALIASES = {
'Shib-EP-Affiliation': 'affiliation',
'Shib-EP-Assurance': 'assurance',
'Shib-EP-CommonName': 'cn',
'Shib-EP-DisplayName': 'displayName',
'Shib-EP-Entitlement': 'entitlement',
'Shib-EP-OrgDN': 'org-dn',
'Shib-EP-OrgUnitDN': 'orgunit-dn',
'Shib-InetOrgPerson-employeeNumber': 'employeeNumber',
'Shib-InetOrgPerson-givenName': 'givenName',
'Shib-InetOrgPerson-homePhone': 'homePhone',
'Shib-InetOrgPerson-homePostalAddress': 'homePostalAddress',
'Shib-InetOrgPerson-mail': 'mail',
'Shib-InetOrgPerson-mobile': 'mobile',
'Shib-InetOrgPerson-preferredLanguage': 'preferredLanguage',
'Shib-OrgPerson-postalAddress': 'postalAddress',
'Shib-Person-ou': 'ou',
'Shib-Person-surname': 'surname',
'Shib-Person-telephoneNumber': 'telephoneNumber',
'Shib-Person-uid': 'uid',
'Shib-SCHAC-HomeOrganization': 'schacHomeOrganization',
'Shib-SCHAC-HomeOrganizationType': 'schacHomeOrganizationType',
'Shib-SwissEP-CardUID': 'cardUID',
'Shib-SwissEP-DateOfBirth': 'dateOfBirth',
'Shib-SwissEP-Gender': 'gender',
'Shib-SwissEP-HomeOrganization': 'homeOrganization',
'Shib-SwissEP-HomeOrganizationType': 'homeOrganizationType',
'Shib-SwissEP-MatriculationNumber': 'matriculationNumber',
'Shib-SwissEP-StaffCategory': 'staffCategory',
'Shib-SwissEP-StudyBranch1': 'studyBranch1',
'Shib-SwissEP-StudyBranch2': 'studyBranch2',
'Shib-SwissEP-StudyBranch3': 'studyBranch3',
'Shib-SwissEP-StudyLevel': 'studyLevel',
'Shib-SwissEP-UniqueID': 'uniqueID',
'Shib-SwissEP-swissEduPersonStaffCategory': 'staffCategory',
'Shib-SwissEP-swissEduPersonStudyBranch1': 'studyBranch1',
'Shib-SwissEP-swissEduPersonStudyBranch2': 'studyBranch2',
'Shib-SwissEP-swissEduPersonStudyBranch3': 'studyBranch3',
'Shib-SwissEP-swissEduPersonStudyLevel': 'studyLevel',
'Shib-eduMember-isMemberOf': 'isMemberOf',
'Shib-primaryGroupID': 'primaryGroupID',
'orgDN': 'org-dn',
'orgUnitDN': 'orgunit-dn',
}
"""
Settings for local development
"""
from .base import *
DEBUG = True
TEMPLATE_DEBUG = TEMPLATES[0]['OPTIONS']['debug'] = True
ALLOWED_HOSTS = ['127.0.0.1', ]
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'adim_dev',
'USER': 'adim',
'PASSWORD': 'fsdkuz289r3jhkasdf987',
'HOST': 'localhost',
},
}
SENDFILE_BACKEND = 'sendfile.backends.development'
\ No newline at end of file
from split_settings.tools import optional, include
include(
'components/base.py',
'components/database.py',
'components/rest_framework.py',
'components/adim.py',
'components/local_defaults.py',
optional('shib_settings.py'),
optional('local_settings.py'),
'components/urls.py',
'components/auth.py',
'components/paths.py',
scope=locals()
)
\ No newline at end of file
"""
This file contains confidential data that shouldn't be versioned nor distributed
It SHOULD define at least the SECRET_KEY config value
"""
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ALLOWED_HOSTS = ('127.0.0.1', )
SECRET_KEY = 'k+zjz_dc&6@yrppyzykv3c6qk1z-tmuestnfe=_zt&me@^m8%u'
try:
DATABASES['default']['PASSWORD'] = 'fsdkuz289r3jhkasdf987'
DATABASES['default']['HOST'] = '127.0.0.1'
except NameError:
pass
SENDFILE_BACKEND = 'sendfile.backends.development'
ADIM_DEBUG_JS = True
ADIM_PROD = False
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"
}
}
#INSTALLED_APPS += ( 'debug_toolbar', )
\ No newline at end of file
SHIB_ATTRIBUTES = {
'affiliation': 'affiliation',
'assurance': 'assurance',
'cardUID': 'cardUID',
'cn': 'cn',
'dateOfBirth': 'dateOfBirth',
'displayName': 'displayName',
'employeeNumber': 'employeeNumber',
'entitlement': 'entitlement',
'gender': 'gender',
'givenName': 'givenName',
'homeOrganization': 'homeOrganization',
'homeOrganizationType': 'homeOrganizationType',
'homePhone': 'homePhone',
'homePostalAddress': 'homePostalAddress',
'isMemberOf': 'isMemberOf',
'mail': 'mail',
'matriculationNumber': 'matriculationNumber',
'mobile': 'mobile',
'nickname': 'nickname',
'org-dn': 'org-dn',
'orgunit-dn': 'orgunit-dn',
'ou': 'ou',
'persistent-id': 'persistent-id',
'postalAddress': 'postalAddress',
'preferredLanguage': 'preferredLanguage',
'primary-orgunit-dn': 'primary-orgunit-dn',
'primaryGroupID': 'primaryGroupID',
'schacHomeOrganization': 'schacHomeOrganization',
'schacHomeOrganizationType': 'schacHomeOrganizationType',
'scoped-affiliation': 'scoped-affiliation',
'staffCategory': 'staffCategory',
'studyBranch1': 'studyBranch1',
'studyBranch2': 'studyBranch2',
'studyBranch3': 'studyBranch3',
'studyLevel': 'studyLevel',
'surname': 'surname',
'targeted-id': 'targeted-id',
'telephoneNumber': 'telephoneNumber',
'uid': 'uid',
'uniqueID': 'uniqueID',
}
SHIB_ATTR_ALIASES = {
'Shib-EP-Affiliation': 'affiliation',
'Shib-EP-Assurance': 'assurance',
'Shib-EP-CommonName': 'cn',
'Shib-EP-DisplayName': 'displayName',
'Shib-EP-Entitlement': 'entitlement',
'Shib-EP-OrgDN': 'org-dn',
'Shib-EP-OrgUnitDN': 'orgunit-dn',
'Shib-InetOrgPerson-employeeNumber': 'employeeNumber',
'Shib-InetOrgPerson-givenName': 'givenName',
'Shib-InetOrgPerson-homePhone': 'homePhone',
'Shib-InetOrgPerson-homePostalAddress': 'homePostalAddress',
'Shib-InetOrgPerson-mail': 'mail',
'Shib-InetOrgPerson-mobile': 'mobile',
'Shib-InetOrgPerson-preferredLanguage': 'preferredLanguage',
'Shib-OrgPerson-postalAddress': 'postalAddress',
'Shib-Person-ou': 'ou',
'Shib-Person-surname': 'surname',
'Shib-Person-telephoneNumber': 'telephoneNumber',
'Shib-Person-uid': 'uid',
'Shib-SCHAC-HomeOrganization': 'schacHomeOrganization',
'Shib-SCHAC-HomeOrganizationType': 'schacHomeOrganizationType',
'Shib-SwissEP-CardUID': 'cardUID',
'Shib-SwissEP-DateOfBirth': 'dateOfBirth',
'Shib-SwissEP-Gender': 'gender',
'Shib-SwissEP-HomeOrganization': 'homeOrganization',
'Shib-SwissEP-HomeOrganizationType': 'homeOrganizationType',
'Shib-SwissEP-MatriculationNumber': 'matriculationNumber',
'Shib-SwissEP-StaffCategory': 'staffCategory',
'Shib-SwissEP-StudyBranch1': 'studyBranch1',
'Shib-SwissEP-StudyBranch2': 'studyBranch2',
'Shib-SwissEP-StudyBranch3': 'studyBranch3',
'Shib-SwissEP-StudyLevel': 'studyLevel',
'Shib-SwissEP-UniqueID': 'uniqueID',
'Shib-SwissEP-swissEduPersonStaffCategory': 'staffCategory',
'Shib-SwissEP-swissEduPersonStudyBranch1': 'studyBranch1',
'Shib-SwissEP-swissEduPersonStudyBranch2': 'studyBranch2',
'Shib-SwissEP-swissEduPersonStudyBranch3': 'studyBranch3',
'Shib-SwissEP-swissEduPersonStudyLevel': 'studyLevel',
'Shib-eduMember-isMemberOf': 'isMemberOf',
'Shib-primaryGroupID': 'primaryGroupID',
'orgDN': 'org-dn',
'orgUnitDN': 'orgunit-dn',
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment