settings.py 3.44 KB
Newer Older
Marcus Przyklink's avatar
Marcus Przyklink committed
1 2 3 4 5 6 7 8 9 10 11 12 13
"""
Django settings for dal project.

Generated by 'django-admin startproject' using Django 1.10.7.

For more information on this file, see
https://docs.djangoproject.com/en/1.10/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.10/ref/settings/
"""

import os
Nico Schottelius's avatar
Cleanup  
Nico Schottelius committed
14
import dotenv
Marcus Przyklink's avatar
Marcus Przyklink committed
15 16 17
import ldap
from django_auth_ldap.config import LDAPSearch, LDAPSearchUnion

Nico Schottelius's avatar
Cleanup  
Nico Schottelius committed
18 19
# get config
dotenv.read_dotenv()
Marcus Przyklink's avatar
Marcus Przyklink committed
20

Nico Schottelius's avatar
Cleanup  
Nico Schottelius committed
21 22 23 24
# LDAP setup
AUTH_LDAP_SERVER_URI = os.environ['LDAPSERVER']
AUTH_LDAP_BIND_DN = os.environ['LDAPSEARCHUSER']
AUTH_LDAP_BIND_PASSWORD = os.environ['LDAPSEARCHUSERPASSWORD']
Marcus Przyklink's avatar
Marcus Przyklink committed
25

Nico Schottelius's avatar
Cleanup  
Nico Schottelius committed
26 27 28 29
# Search union over OUs
search_base = os.environ['LDAPSEARCH'].split()
search_base_ldap = [ LDAPSearch(x, ldap.SCOPE_SUBTREE, "(uid=%(user)s)") for x in search_base ]
AUTH_LDAP_USER_SEARCH = LDAPSearchUnion(*search_base_ldap)
Marcus Przyklink's avatar
Marcus Przyklink committed
30

PCoder's avatar
PCoder committed
31
AUTH_LDAP_START_TLS = os.environ.get('LDAP_USE_TLS', False)
Marcus Przyklink's avatar
Marcus Przyklink committed
32 33 34

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

PCoder's avatar
PCoder committed
35 36 37
ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS', 'localhost')

DEBUG = os.environ.get('DEBUG', False)
Marcus Przyklink's avatar
Marcus Przyklink committed
38 39 40 41 42 43 44 45

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
46
    'dal',
Marcus Przyklink's avatar
Marcus Przyklink committed
47 48 49 50 51 52 53 54 55 56 57 58
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    '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',
]

59 60 61
AUTHENTICATION_BACKENDS = (
    'django_auth_ldap.backend.LDAPBackend',
)
Marcus Przyklink's avatar
Marcus Przyklink committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 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 115 116 117 118 119 120


ROOT_URLCONF = 'dal.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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',
            ],
        },
    },
]

WSGI_APPLICATION = 'dal.wsgi.application'

# Password validation
# https://docs.djangoproject.com/en/1.10/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.10/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/

STATIC_URL = '/static/'
Nico Schottelius's avatar
Cleanup  
Nico Schottelius committed
121 122 123

############################# To be fixed

PCoder's avatar
PCoder committed
124
STATIC_ROOT= os.path.join(BASE_DIR, 'static/')
Nico Schottelius's avatar
Cleanup  
Nico Schottelius committed
125 126 127 128 129 130 131 132 133 134

# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}
PCoder's avatar
PCoder committed
135
SECRET_KEY = os.environ.get('SECRET_KEY')