settings.py 5.33 KB
Newer Older
1
"""
2
settings/settings.py
3

4
Settings that are applied project wide. 
5 6 7 8 9
"""
# Python stdlib Imports
import os
import sys

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
# DEV vs PROD
if os.environ['GO_ENV'] != 'production':
    DEBUG = True
    # dummy cache for development-- doesn't actually cache things
    CACHES = {
        'default': {
            'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
        }
    }
else:
    DEBUG = False
    CACHES = {
        'default': {
            'BACKEND': 'redis_cache.RedisCache',
            'LOCATION': 'localhost:6379',
        },
    }

28
# STANDALONE VARS
David Haynes's avatar
David Haynes committed
29 30

# /go/go
31 32 33 34 35 36 37
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

# You can generate a secret key from the following link:
# http://www.miniwebtool.com/django-secret-key-generator/
SECRET_KEY = os.environ['GO_SECRET_KEY']

# Peoplefinder API
David Haynes's avatar
David Haynes committed
38
PF_URL = "https://api.srct.gmu.edu/peoplefinder/v1/"
39 40 41 42 43 44 45 46

# The domains this application will be deployed on
# e.g. Which domains this app should listen to requests from.
ALLOWED_HOSTS = [os.environ['GO_ALLOWED_HOSTS']]

ADMINS = ()
MANAGERS = ADMINS

47 48 49
# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/

50
LANGUAGE_CODE = 'en-us'
51
TIME_ZONE = 'UTC'
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
USE_I18N = True
USE_L10N = True
USE_TZ = True

# MEDIA/STATIC FILE CONFIGURATION
MEDIA_URL = '/media/'
MEDIA_ROOT = ''
MEDIAFILES_DIRS = (
    os.path.join(BASE_DIR, 'media/'),
)

STATIC_URL = '/static/'
STATIC_ROOT = ''
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static/'),
67
    './go/static/'
68 69 70 71 72 73 74 75 76 77 78 79
)

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

# TEMPLATING
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
David Haynes's avatar
David Haynes committed
80
            os.path.join(BASE_DIR, 'templates'),
David Haynes's avatar
David Haynes committed
81
            './go/go_ahead/templates/'
82
        ],
83
        'APP_DIRS': True,
84 85
        'OPTIONS': {
            'context_processors': [
86 87
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
88
                'django.contrib.auth.context_processors.auth',
89
                'django.contrib.messages.context_processors.messages',
90
            ],
91
        },
92 93 94 95 96 97 98 99 100 101 102 103 104
    }
]

# Use the same DB everywhere.
# See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': os.environ['GO_DB_NAME'],
        'USER': os.environ['GO_DB_USER'],
        'PASSWORD': os.environ['GO_DB_PASSWORD'],
        'HOST': os.environ['GO_DB_HOST'],
        'PORT': os.environ['GO_DB_PORT'],
David Haynes's avatar
David Haynes committed
105
        'OPTIONS': {'charset': 'utf8mb4'}
106 107 108
    }
}

David Haynes's avatar
David Haynes committed
109
MIDDLEWARE = [
110 111 112 113 114 115
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'cas.middleware.CASMiddleware',
David Haynes's avatar
David Haynes committed
116
]
117 118 119 120 121

ROOT_URLCONF = 'settings.urls'
WSGI_APPLICATION = 'settings.wsgi.application'

INSTALLED_APPS = (
David Haynes's avatar
David Haynes committed
122
    # Django apps
123 124 125 126 127 128 129
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admin',
David Haynes's avatar
David Haynes committed
130 131
    'go_back',
    'go_ahead',
David Haynes's avatar
David Haynes committed
132
    # Third party
133 134
    'crispy_forms',
    'cas',
135 136
    'rest_framework',
    'rest_framework.authtoken'
137 138
)

David Haynes's avatar
David Haynes committed
139
CRISPY_TEMPLATE_PACK = 'bootstrap4'
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

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse'
        }
    },
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler'
        },
        'console': {
            'level': 'INFO',
            'class': 'logging.StreamHandler',
            'stream': sys.stdout
        }
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
        'django': {
            'handlers': ['console'],
            'level': 'INFO',
            'propogate': True
        },
    }
}

David Haynes's avatar
David Haynes committed
175 176 177
"""
CAS Authentication Settings
"""
178 179 180 181 182 183 184 185 186 187 188 189 190
LOGIN_URL = '/login'
LOGOUT_URL = '/logout'
LOGIN_REDIRECT_URL = '/'

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    'cas.backends.CASBackend',
)

CAS_LOGOUT_COMPLETELY = True
CAS_PROVIDE_URL_TO_LOGOUT = True

CAS_RESPONSE_CALLBACKS = (
191
    'go_back.cas_callbacks.create_user',
192 193
)

194
CAS_SERVER_URL = "https://login.gmu.edu"
195

David Haynes's avatar
David Haynes committed
196 197 198
"""
Mail Settings
"""
199 200 201 202 203 204 205 206
EMAIL_HOST = os.environ['GO_EMAIL_HOST']
EMAIL_PORT = os.environ['GO_EMAIL_PORT']
EMAIL_HOST_USER = os.environ['GO_EMAIL_HOST_USER']
EMAIL_HOST_PASSWORD = os.environ['GO_EMAIL_HOST_PASSWORD']
EMAIL_FROM = os.environ['GO_EMAIL_FROM']
EMAIL_TO = os.environ['GO_EMAIL_TO']

# Domain used to email to users. See implementation in views.py
David Haynes's avatar
David Haynes committed
207
# ie. '@gmu.edu'
208
EMAIL_DOMAIN = os.environ['GO_EMAIL_DOMAIN']
209 210 211 212 213 214 215 216 217 218 219 220 221

"""
Django Rest Framework Settings
"""
REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.IsAuthenticated'
    ],
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework.authentication.TokenAuthentication',
        'rest_framework.authentication.SessionAuthentication',
    ],
}