307 lines
8.2 KiB
Python
307 lines
8.2 KiB
Python
"""
|
|
Django settings for medinf project.
|
|
|
|
Generated by 'django-admin startproject' using Django 1.11.2.
|
|
|
|
For more information on this file, see
|
|
https://docs.djangoproject.com/en/1.11/topics/settings/
|
|
|
|
For the full list of settings and their values, see
|
|
https://docs.djangoproject.com/en/1.11/ref/settings/
|
|
"""
|
|
|
|
from datetime import timedelta
|
|
import os
|
|
import re
|
|
import socket
|
|
|
|
# Development or Production
|
|
r = re.search(r"^172.17", socket.gethostbyname(socket.gethostname()))
|
|
DEVELOPMENT = r == None
|
|
|
|
DEBUG = True
|
|
|
|
|
|
# SECURITY WARNING: don't run with debug turned on in production!
|
|
DEBUG = DEVELOPMENT
|
|
|
|
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
# Log Configuration
|
|
|
|
if DEBUG:
|
|
LOGLEVEL = "DEBUG"
|
|
else:
|
|
LOGLEVEL = "INFO"
|
|
|
|
LOGGING = {
|
|
"version": 1,
|
|
"disable_existing_loggers": False,
|
|
"formatters": {
|
|
"standard": {
|
|
"format": "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
|
|
"datefmt": "%d/%b/%Y %H:%M:%S",
|
|
},
|
|
},
|
|
"handlers": {
|
|
"null": {
|
|
"level": "DEBUG",
|
|
"class": "logging.NullHandler",
|
|
},
|
|
"logfile": {
|
|
"level": "DEBUG",
|
|
"class": "logging.handlers.RotatingFileHandler",
|
|
"filename": os.path.join(BASE_DIR, "log/log.txt"),
|
|
"maxBytes": 1024 * 1024 * 5,
|
|
"backupCount": 5,
|
|
"formatter": "standard",
|
|
},
|
|
"console": {
|
|
"level": "DEBUG",
|
|
"class": "logging.StreamHandler",
|
|
"formatter": "standard",
|
|
},
|
|
},
|
|
"loggers": {
|
|
"": {
|
|
"level": "WARNING",
|
|
"handlers": ["logfile"],
|
|
},
|
|
"django.db.backends": {
|
|
"handlers": ["console"],
|
|
"level": "INFO", # set DEBUG if needed
|
|
"propagate": False,
|
|
},
|
|
"medinf": {
|
|
"handlers": ["console"],
|
|
"level": LOGLEVEL,
|
|
"propagate": True,
|
|
},
|
|
"studis": {
|
|
"handlers": ["console"],
|
|
"level": LOGLEVEL,
|
|
"propagate": True,
|
|
},
|
|
"authstuff": {
|
|
"handlers": ["console"],
|
|
"level": "INFO",
|
|
"propagate": True,
|
|
},
|
|
},
|
|
}
|
|
|
|
|
|
# SECURITY WARNING: keep the secret key used in production secret!
|
|
SECRET_KEY = "XXXXXn!i2lx(&)gq7l!art_pr	et*$r)r&ogu&j-+wm0^ni5"
|
|
|
|
|
|
USE_X_FORWARDED_HOST = True
|
|
|
|
ALLOWED_HOSTS = [
|
|
"medinf.efi.th-nuernberg.de",
|
|
"api.efi.th-nuernberg.de",
|
|
"localhost",
|
|
"127.0.0.1",
|
|
]
|
|
|
|
# Application definition
|
|
|
|
INSTALLED_APPS = [
|
|
"django.contrib.admin",
|
|
"django.contrib.auth",
|
|
"django.contrib.contenttypes",
|
|
"django.contrib.sessions",
|
|
"django.contrib.messages",
|
|
"django.contrib.staticfiles",
|
|
# Custom Apps
|
|
"authstuff.apps.AuthStuffConfig",
|
|
"pruefplan_viewer.apps.PruefplanViewerConfig",
|
|
"pruefplan_parser.apps.PruefplanParserConfig",
|
|
# Third Party Apps
|
|
"rest_framework",
|
|
"rest_framework_simplejwt.token_blacklist",
|
|
"rest_framework.authtoken",
|
|
"corsheaders",
|
|
]
|
|
|
|
MIDDLEWARE = [
|
|
"django.middleware.security.SecurityMiddleware",
|
|
"corsheaders.middleware.CorsMiddleware",
|
|
"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",
|
|
]
|
|
|
|
ROOT_URLCONF = "medinf.urls"
|
|
|
|
TEMPLATES = [
|
|
{
|
|
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
|
"DIRS": [os.path.join(BASE_DIR, "templates")],
|
|
"APP_DIRS": True,
|
|
"OPTIONS": {
|
|
"context_processors": [
|
|
"django.template.context_processors.debug",
|
|
"django.template.context_processors.request",
|
|
"django.contrib.auth.context_processors.auth",
|
|
"django.contrib.messages.context_processors.messages",
|
|
"medinf.context_processors.logout_redirect",
|
|
],
|
|
},
|
|
},
|
|
]
|
|
|
|
WSGI_APPLICATION = "medinf.wsgi.application"
|
|
|
|
|
|
# Database
|
|
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
|
|
|
|
if DEVELOPMENT:
|
|
DATABASES = {
|
|
"default": {
|
|
"ENGINE": "django.db.backends.sqlite3",
|
|
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
|
|
}
|
|
}
|
|
else:
|
|
DATABASES = {
|
|
"default": {
|
|
"ENGINE": "django.db.backends.mysql",
|
|
"NAME": "django-app",
|
|
"USER": "django-app",
|
|
"PASSWORD": "8TFXHv9X",
|
|
"HOST": "mysql",
|
|
"PORT": "3306",
|
|
"OPTIONS": {"init_command": "SET sql_mode='STRICT_TRANS_TABLES'"},
|
|
}
|
|
}
|
|
|
|
|
|
# Password validation
|
|
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
|
|
|
|
AUTH_PASSWORD_VALIDATORS = [
|
|
{
|
|
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
|
|
},
|
|
{
|
|
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
|
|
},
|
|
{
|
|
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
|
|
},
|
|
{
|
|
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
|
|
},
|
|
]
|
|
|
|
|
|
# Internationalization
|
|
# https://docs.djangoproject.com/en/1.11/topics/i18n/
|
|
|
|
LANGUAGE_CODE = "de-de"
|
|
|
|
TIME_ZONE = "Europe/Berlin"
|
|
|
|
USE_I18N = True
|
|
|
|
USE_L10N = True
|
|
|
|
USE_TZ = True
|
|
|
|
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
|
|
|
|
|
|
# Static files (CSS, JavaScript, Images)
|
|
# https://docs.djangoproject.com/en/1.11/howto/static-files/
|
|
|
|
|
|
# Nach dem Deployment werden die statischen Inhalte von medinf geholt.
|
|
# Sie müssen in das Verzeichnis <HTMLROOT>/static kopiert werden
|
|
|
|
|
|
STATIC_ROOT = os.path.join("/tmp", "static")
|
|
|
|
STATIC_URL = "/static/"
|
|
|
|
STATICFILES_DIRS = [
|
|
os.path.join(BASE_DIR, "static"),
|
|
]
|
|
|
|
# Konfiguration des Auth-Systems
|
|
REST_FRAMEWORK = {
|
|
'DEFAULT_AUTHENTICATION_CLASSES': [
|
|
'rest_framework.authentication.TokenAuthentication',
|
|
],
|
|
}
|
|
|
|
LDAP_DOMAIN = "ADS1"
|
|
LDAP_SERVER = "gso1.ads1.fh-nuernberg.de"
|
|
LDAP_FORCE_UPDATE = False
|
|
LDAP_UPDATE_TIMEOUT_DAYS = 2
|
|
|
|
if DEVELOPMENT:
|
|
LOGIN_REDIRECT_URL = "/"
|
|
LOGOUT_REDIRECT_URL = "/"
|
|
LOGIN_URL = "/accounts/login/"
|
|
else:
|
|
LOGIN_REDIRECT_URL = "/app/"
|
|
LOGOUT_REDIRECT_URL = "/app/"
|
|
LOGIN_URL = "/app/accounts/login/"
|
|
|
|
|
|
if DEVELOPMENT:
|
|
AUTHENTICATION_BACKENDS = [
|
|
"django.contrib.auth.backends.ModelBackend",
|
|
]
|
|
else:
|
|
AUTHENTICATION_BACKENDS = [
|
|
"django.contrib.auth.backends.ModelBackend",
|
|
"medinf.ldap_backend.LdapBackend",
|
|
]
|
|
|
|
|
|
# Config the JWT Token with static settings -> from docs
|
|
# https://django-rest-framework-simplejwt.readthedocs.io/en/latest/
|
|
SIMPLE_JWT = {
|
|
"ACCESS_TOKEN_LIFETIME": timedelta(minutes=15),
|
|
"REFRESH_TOKEN_LIFETIME": timedelta(days=50),
|
|
"ROTATE_REFRESH_TOKENS": True,
|
|
"BLACKLIST_AFTER_ROTATION": True,
|
|
"UPDATE_LAST_LOGIN": False,
|
|
"ALGORITHM": "HS256",
|
|
"VERIFYING_KEY": None,
|
|
"AUDIENCE": None,
|
|
"ISSUER": None,
|
|
"JWK_URL": None,
|
|
"LEEWAY": 0,
|
|
"AUTH_HEADER_TYPES": ("Bearer",),
|
|
"AUTH_HEADER_NAME": "HTTP_AUTHORIZATION",
|
|
"USER_ID_FIELD": "id",
|
|
"USER_ID_CLAIM": "user_id",
|
|
"USER_AUTHENTICATION_RULE": "rest_framework_simplejwt.authentication.default_user_authentication_rule",
|
|
"AUTH_TOKEN_CLASSES": ("rest_framework_simplejwt.tokens.AccessToken",),
|
|
"TOKEN_TYPE_CLAIM": "token_type",
|
|
"TOKEN_USER_CLASS": "rest_framework_simplejwt.models.TokenUser",
|
|
"JTI_CLAIM": "jti",
|
|
"SLIDING_TOKEN_REFRESH_EXP_CLAIM": "refresh_exp",
|
|
"SLIDING_TOKEN_LIFETIME": timedelta(minutes=5),
|
|
"SLIDING_TOKEN_REFRESH_LIFETIME": timedelta(days=1),
|
|
}
|
|
|
|
# Set coresheader to allow all origin
|
|
CORS_ALLOW_ALL_ORIGINS = True
|
|
|
|
# Konfiguration Prüfungsplan
|
|
PP_UPLOAD_DIR = os.path.join(BASE_DIR, "pruefplan_parser", "data")
|
|
PP_TEACHER_FILE = os.path.join(PP_UPLOAD_DIR, "Dozenten.json")
|
|
PP_SUBJECT_FILE = os.path.join(PP_UPLOAD_DIR, "Faecher.json")
|
|
PP_ATTENDANCE_FILE = os.path.join(PP_UPLOAD_DIR, "Praesenzen.json")
|
|
PP_EXAM_FILE = os.path.join(PP_UPLOAD_DIR, "Pruefungen.json")
|
|
PP_STUDENT_FILE = os.path.join(PP_UPLOAD_DIR, "Saaleinteilung.json")
|