settings.py 5.13 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
# DEV vs PROD
11
if os.environ["GO_ENV"] != "production":
12 13
    DEBUG = True
    # dummy cache for development-- doesn't actually cache things
14
    CACHES = {"default": {"BACKEND": "django.core.cache.backends.dummy.DummyCache"}}
15 16 17
else:
    DEBUG = False
    CACHES = {
18
        "default": {"BACKEND": "redis_cache.RedisCache", "LOCATION": "localhost:6379"}
19 20
    }

21
# STANDALONE VARS
David Haynes's avatar
David Haynes committed
22 23

# /go/go
24 25 26 27
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/
28
SECRET_KEY = os.environ["GO_SECRET_KEY"]
29 30

# Peoplefinder API
David Haynes's avatar
David Haynes committed
31
PF_URL = "https://api.srct.gmu.edu/peoplefinder/v1/"
32 33 34

# The domains this application will be deployed on
# e.g. Which domains this app should listen to requests from.
35
ALLOWED_HOSTS = [os.environ["GO_ALLOWED_HOSTS"]]
36 37 38 39

ADMINS = ()
MANAGERS = ADMINS

40 41 42
# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/

43 44
LANGUAGE_CODE = "en-us"
TIME_ZONE = "UTC"
45 46 47 48 49
USE_I18N = True
USE_L10N = True
USE_TZ = True

# MEDIA/STATIC FILE CONFIGURATION
50 51 52
MEDIA_URL = "/media/"
MEDIA_ROOT = ""
MEDIAFILES_DIRS = (os.path.join(BASE_DIR, "media/"),)
53

54 55 56
STATIC_URL = "/static/"
STATIC_ROOT = ""
STATICFILES_DIRS = (os.path.join(BASE_DIR, "static/"), "./go/static/")
57 58

STATICFILES_FINDERS = (
59 60
    "django.contrib.staticfiles.finders.FileSystemFinder",
    "django.contrib.staticfiles.finders.AppDirectoriesFinder",
61 62 63 64 65
)

# TEMPLATING
TEMPLATES = [
    {
66 67 68 69 70 71 72 73 74 75
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "DIRS": [os.path.join(BASE_DIR, "templates"), "./go/go_ahead/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",
            ]
76
        },
77 78 79 80 81 82
    }
]

# Use the same DB everywhere.
# See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = {
83 84 85 86 87 88 89 90
    "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"],
        "OPTIONS": {"charset": "utf8mb4"},
91 92 93
    }
}

David Haynes's avatar
David Haynes committed
94
MIDDLEWARE = [
95 96 97 98 99 100
    "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
101
]
102

103 104
ROOT_URLCONF = "settings.urls"
WSGI_APPLICATION = "settings.wsgi.application"
105 106

INSTALLED_APPS = (
David Haynes's avatar
David Haynes committed
107
    # Django apps
108 109 110 111 112 113 114 115 116
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.sites",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "django.contrib.admin",
    "go_back",
    "go_ahead",
David Haynes's avatar
David Haynes committed
117
    # Third party
118 119 120 121
    "crispy_forms",
    "cas",
    "rest_framework",
    "rest_framework.authtoken",
122 123
)

124
CRISPY_TEMPLATE_PACK = "bootstrap4"
125 126

LOGGING = {
127 128 129 130 131 132 133 134
    "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",
135
        },
136 137 138 139
        "console": {
            "level": "INFO",
            "class": "logging.StreamHandler",
            "stream": sys.stdout,
140
        },
141 142 143 144 145 146
    },
    "loggers": {
        "django.request": {
            "handlers": ["mail_admins"],
            "level": "ERROR",
            "propagate": True,
147
        },
148 149
        "django": {"handlers": ["console"], "level": "INFO", "propogate": True},
    },
150 151
}

David Haynes's avatar
David Haynes committed
152 153 154
"""
CAS Authentication Settings
"""
155 156 157
LOGIN_URL = "/login"
LOGOUT_URL = "/logout"
LOGIN_REDIRECT_URL = "/"
158 159

AUTHENTICATION_BACKENDS = (
160 161
    "django.contrib.auth.backends.ModelBackend",
    "cas.backends.CASBackend",
162 163 164 165 166
)

CAS_LOGOUT_COMPLETELY = True
CAS_PROVIDE_URL_TO_LOGOUT = True

167
CAS_RESPONSE_CALLBACKS = ("go_back.cas_callbacks.create_user",)
168

169
CAS_SERVER_URL = "https://login.gmu.edu"
170

David Haynes's avatar
David Haynes committed
171 172 173
"""
Mail Settings
"""
174 175 176 177 178 179
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"]
180 181

# Domain used to email to users. See implementation in views.py
David Haynes's avatar
David Haynes committed
182
# ie. '@gmu.edu'
183
EMAIL_DOMAIN = os.environ["GO_EMAIL_DOMAIN"]
184 185 186 187 188

"""
Django Rest Framework Settings
"""
REST_FRAMEWORK = {
189 190 191 192
    "DEFAULT_PERMISSION_CLASSES": ["rest_framework.permissions.IsAuthenticated"],
    "DEFAULT_AUTHENTICATION_CLASSES": [
        "rest_framework.authentication.TokenAuthentication",
        "rest_framework.authentication.SessionAuthentication",
193 194
    ],
}
David Haynes's avatar
wtf  
David Haynes committed
195 196

SITE_ID = 1