# *-* encoding: utf-8 *-* """Common settings and globals.""" # from __future__ import unicode_literals 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': (normpath(join(SITE_ROOT, 'templates')), ), '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_utils.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, name=__name__): this_module = modules[name] if base_url is None: base_url = getattr(this_module, 'BASE_URL', "/") setattr(this_module, 'BASE_URL', 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)) setattr(this_module, 'CORS_URLS_REGEX', r'^{}api/.*$'.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 SESSION_COOKIE_NAME = "adim_sessid" # ---------- END AUTHENTICATION # ========== LOCAL APPS CONFIGURATION # LOCAL_APPS = ('django_extensions',) # ..... MISC SENDFILE_BACKEND = 'sendfile.backends.xsendfile' # ..... REST FRAMEWORK LOCAL_APPS += ('rest_framework', 'rest_framework.authtoken') REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework.authentication.SessionAuthentication', 'rest_framework.authentication.TokenAuthentication', 'adim_ttp.authentication.TTPAuthentication', ), 'DEFAULT_PERMISSION_CLASSES': [ 'rest_framework.permissions.IsAuthenticated' ] } # ..... CORS HEADERS (https://github.com/ottoyiu/django-cors-headers/) LOCAL_APPS += ('corsheaders',) MIDDLEWARE_CLASSES = list(MIDDLEWARE_CLASSES) MIDDLEWARE_CLASSES.insert( MIDDLEWARE_CLASSES.index('django.middleware.common.CommonMiddleware'), 'corsheaders.middleware.CorsMiddleware' ) MIDDLEWARE_CLASSES += ('corsheaders.middleware.CorsMiddleware', ) CORS_ORIGIN_ALLOW_ALL = True # CORS_URLS_REGEX = r'^.*/api/.*$' # ..... ADIM LOCAL_APPS += ('adim', 'adim_app', 'adim_ttp') # 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 } } ADIM_ENV = { 'cimaf': {}, 'anodate': { 'categories': { 'default': [{ 'id': 'cat_1', 'label': "Marqueur", 'color': "#54848E" }, { 'id': 'cat_2', 'label': "Changement", 'color': "#4B7F5C" }, { 'id': 'cat_3', 'label': "Chronologie", 'color': "#6D557F" }, { 'id': 'cat_4', 'label': "Absolu", 'color': "#D80918" }, { 'id': 'cat_5', 'label': "Relatif", 'color': "#71B800" }, { 'id': 'cat_6', 'label': "Cycle", 'color': "#EFC300" }, { 'id': 'cat_7', 'label': "Durée", 'color': "#FF8B00" }, { 'id': 'cat_8', 'label': "Contexte", 'color': "#25BFD1" }] } } } 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" } } # ATTP = { # 'OPTIONS': { # 'CACHE_TIMEOUT': # }, # '': { # 'CHECK_URL' : # 'MODE_ID': 15 # } # } # # CAUTION: when adding a ttp service, update the template (templates/adim/aom-modal.inc.html) with MODE_ID where needed # ATTP = { 'OPTIONS': { 'CACHE_TIMEOUT': 20, # 30, }, 'moodle': { 'CHECK_URL': "http://tstmoodle.unil.ch/29/mod/adim/checkAccess.php?uuid={uuid}", 'MODE_ID': 16 }, 'toto': { 'CHECK_URL': "http://localhost/tests/phpupload/toto.php?a={uuid}", 'MODE_ID': 24 }, 'my_ttp': { 'CHECK_URL': "http://my-ttp:8001/ttp/check/{uuid}/", 'MODE_ID': 32 } } # ..... 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") # ---------- 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 # ========== LOGGING CONFIGURATION # def add_remote_info(record): req = getattr(record, 'request', None) record.remote_addr = req.META.get('REMOTE_ADDR', '-') if req else '-' record.forwarded_for = req.META.get('HTTP_X_FORWARDED_FOR', '-') if req else '-' return True LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'filters': { 'require_debug_false': { '()': 'django.utils.log.RequireDebugFalse' }, 'require_debug_true': { '()': 'django.utils.log.RequireDebugTrue' }, 'add_remote_info': { '()': 'django.utils.log.CallbackFilter', 'callback': add_remote_info, } }, 'formatters': { 'verbose': { 'format': '%(levelname)s %(asctime)s %(name)s.%(funcName)s %(message)s', }, 'verbose_with_remote': { 'format': '%(levelname)s %(asctime)s %(name)s.%(funcName)s %(remote_addr)s %(forwarded_for)s %(message)s', }, 'simple': { 'format': '%(levelname)s %(message)s' } }, 'handlers': { 'mail_admins': { 'level': 'ERROR', 'filters': ['require_debug_false'], 'class': 'django.utils.log.AdminEmailHandler' }, 'console': { 'filters': ['require_debug_true', ], 'class': 'logging.StreamHandler', }, 'file': { 'level': 'INFO', 'class': 'logging.FileHandler', 'filters': ['add_remote_info', ], 'formatter': 'verbose_with_remote', 'filename': '{}/log/debug.log'.format(dirname(SITE_ROOT)), }, }, 'loggers': { 'django.request': { 'handlers': ['mail_admins', 'file', ], 'level': 'WARNING', 'propagate': True, }, 'adim.permissions': { 'handlers': ['console'], 'level': 'DEBUG', # 'NOTSET', 'propagate': True, }, 'adim_app': { 'handlers': ['console', 'file'], 'level': 'DEBUG', 'propagate': True, }, 'adim_ttp': { 'handlers': ['console', 'file'], 'level': 'DEBUG', 'propagate': True, }, 'shibauth': { 'handlers': ['console', 'file'], 'level': 'DEBUG', 'propagate': True, }, } } ########## END LOGGING CONFIGURATION