Commit 7dae59bf authored by David Haynes's avatar David Haynes

First draft of new settings model

- All sensitive information relies on env vars
- local and prod inherit base and make additional modifications
parent 1f197932
Pipeline #1189 passed with stage
in 59 seconds
"""
settings/base.py
Base Settings
"""
# Future Imports
from __future__ import (absolute_import, division, print_function,
unicode_literals)
# Python stdlib Imports
import os
import sys
# STANDALONE VARS
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/
# export SECRET_KEY=$(dd if=/dev/urandom count=100 | tr -dc "A-Za-z0-9" | fold -w 60 | head -n1 2>/dev/null)
# assert 'SECRET_KEY' in os.environ, 'You need to set the SECRET_KEY enviornment variable!'
SECRET_KEY = os.environ['GO_SECRET_KEY']
# Peoplefinder API
PF_URL = "https://api.srct.gmu.edu/pf/v1/"
# The domains this application will be deployed on
# e.g. Which domains this app should listen to requests from.
# ALLOWED_HOSTS = ['127.0.0.1']
ALLOWED_HOSTS = [os.environ['GO_ALLOWED_HOSTS']]
ADMINS = ()
MANAGERS = ADMINS
# TIME
TIME_ZONE = 'America/New_York'
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
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/'),
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
# TEMPLATING
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'templates')
],
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.request'
],
'loaders': [
'django.template.loaders.app_directories.Loader'
],
'debug': DEBUG
}
}
]
########## DATABASE CONFIGURATION
# 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'],
}
}
# MIDDLEWARE
MIDDLEWARE_CLASSES = (
'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',
)
# URL CONF
ROOT_URLCONF = 'settings.urls'
WSGI_APPLICATION = 'settings.wsgi.application'
# APPS
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'go',
'qrcode',
'crispy_forms',
'bootstrap3_datetime',
'cas',
)
CRISPY_TEMPLATE_PACK = 'bootstrap3'
# LOGGING
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
},
}
}
# CAS AUTH
LOGIN_URL = '/login'
LOGOUT_URL = '/logout'
LOGIN_REDIRECT_URL = '/'
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'cas.backends.CASBackend',
)
CAS_SERVER_URL = os.environ['GO_CAS_URL']
CAS_LOGOUT_COMPLETELY = True
CAS_PROVIDE_URL_TO_LOGOUT = True
CAS_RESPONSE_CALLBACKS = (
'go.cas_callbacks.create_user',
)
# MAIL
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']
# example@example.com
EMAIL_FROM = os.environ['GO_EMAIL_FROM']
# to@example.com
EMAIL_TO = os.environ['GO_EMAIL_TO']
# Domain used to email to users. See implementation in views.py
# ie. in Mason's case '@masonlive.gmu.edu'
EMAIL_DOMAIN = os.environ['GO_EMAIL_DOMAIN']
"""
settings/local.py
Development settings and globals.
"""
# Future Imports
from __future__ import (absolute_import, division, print_function,
unicode_literals)
# Base Settings Import
from .base import *
# DEBUG mode is used to view more details when errors occur
# Do not have set True in production
DEBUG = True
CAS_SERVER_URL = "https://cas.srct.gmu.edu"
"""
settings/production.py
Production settings and globals.
"""
# Future Imports
from __future__ import (absolute_import, division, print_function,
unicode_literals)
# Base Settings Import
from .base import *
# DEBUG mode is used to view more details when errors occur
# Do not have set True in production
DEBUG = False
CAS_SERVER_URL = "https://login.gmu.edu"
CACHES = {
'default': {
'BACKEND': 'redis_cache.RedisCache',
'LOCATION': 'localhost:6379',
},
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment