Commit 2e9ae027 authored by David Haynes's avatar David Haynes 🙆

Merge branch '107-split-settings' into '2.2-dev'

Resolve "Break up settings files into multiple files that inherit from each other"

See merge request !83
parents 1f197932 89296255
Pipeline #1221 passed with stage
in 1 minute and 4 seconds
......@@ -15,4 +15,5 @@ venv
htmlcov/
.idea
__pycache__/
.vscode
\ No newline at end of file
.vscode
go/sourceme.sh
......@@ -14,15 +14,21 @@ before_script:
- pip install -r requirements/ci.txt
- nohup redis-server &
- cd go/
- cp settings/settings.py.template settings/settings.py
- cp settings/secret.py.template settings/secret.py
- export SECRET_KEY=$(dd if=/dev/urandom count=100 | tr -dc "A-Za-z0-9" | fold -w 60 | head -n1 2>/dev/null)
- export DJANGO_DEBUG="True"
- sed -i settings/secret.py -e 's/DB_NAME.*/DB_NAME = \"go\"/'
- sed -i settings/secret.py -e 's/DB_USER.*/DB_USER = \"root\"/'
- sed -i settings/secret.py -e 's/DB_PASSWORD.*/DB_PASSWORD = \"root\"/'
- sed -i settings/secret.py -e 's/DB_HOST.*/DB_HOST = \"mysql\"/'
- sed -i settings/secret.py -e 's/SECRET_KEY.*/SECRET_KEY = \"${SECRET_KEY}\"/'
- export GO_SECRET_KEY=$(dd if=/dev/urandom count=100 | tr -dc "A-Za-z0-9" | fold -w 60 | head -n1 2>/dev/null)
- export GO_DB_NAME="go"
- export GO_DB_USER="root"
- export GO_DB_PASSWORD="root"
- export GO_DB_HOST="mysql"
- export GO_DB_PORT=3306
- export GO_ALLOWED_HOSTS="*"
- export GO_EMAIL_DOMAIN="@masonlive.gmu.edu"
- export GO_CAS_URL="https://cas.srct.gmu.edu/"
- export GO_EMAIL_HOST=
- export GO_EMAIL_PORT=
- export GO_EMAIL_HOST_USER=
- export GO_EMAIL_HOST_PASSWORD=
- export GO_EMAIL_FROM=
- export GO_EMAIL_TO=
- python manage.py makemigrations
- python manage.py makemigrations go
- python manage.py migrate
......
......@@ -202,6 +202,7 @@ it set up, open a merge request and I'll merge it in.
cd /vagrant
source venv/bin/activate
cd go
source sourceme.sh
python manage.py test
#### Manual Setup
......
......@@ -95,7 +95,7 @@ Vagrant.configure(2) do |config|
venv_path: "/vagrant/venv",
cas_url: "https://cas.srct.gmu.edu/",
app_path: "/vagrant/go",
settings_path: "/vagrant/go/settings",
sourceme_dest: "/vagrant/go/",
superuser: "dhaynes3"
}
}
......
......@@ -11,20 +11,22 @@ services:
depends_on:
- db
environment:
- debug=True
- host=*
- email_domain=@masonlive.gmu.edu
- cas_url=https://cas.srct.gmu.edu/
- GO_ALLOWED_HOSTS=*
- GO_EMAIL_DOMAIN=@masonlive.gmu.edu
- GO_CAS_URL=https://cas.srct.gmu.edu/
- GO_DB_NAME=go
- GO_DB_USER=go
- GO_DB_PASSWORD=go
- GO_DB_HOST=db
- GO_DB_PORT=3306
- GO_EMAIL_HOST=
- GO_EMAIL_PORT=
- GO_EMAIL_HOST_USER=
- GO_EMAIL_HOST_PASSWORD=
- GO_EMAIL_FROM=
- GO_EMAIL_TO=
- superuser=dhaynes3
- DB_NAME=go
- DB_USER=go
- DB_PASSWORD=go
- DB_HOST=db
- PIWIK_URL=
- EMAIL_HOST=
- EMAIL_PORT=
- EMAIL_HOST_USER=
- EMAIL_HOST_PASSWORD=
db:
image: mysql
environment:
......
......@@ -3,7 +3,7 @@ import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.local")
from django.core.management import execute_from_command_line
......
# Create a new file 'settings.py' and copy these contents into that file
from . import secret
"""
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__))
# DEBUG mode is used to view more details when errors occur
# Do not have set True in production
DEBUG = False
ADMINS = ()
MANAGERS = ADMINS
# 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']
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': secret.DB_NAME,
'USER': secret.DB_USER,
'PASSWORD': secret.DB_PASSWORD,
'HOST': secret.DB_HOST,
'PORT': '',
}
}
# 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 = ['127.0.0.1']
ALLOWED_HOSTS = [os.environ['GO_ALLOWED_HOSTS']]
# Peoplefinder API
PF_URL = "https://api.srct.gmu.edu/pf/v1/"
ADMINS = ()
MANAGERS = ADMINS
# TIME
TIME_ZONE = 'America/New_York'
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
......@@ -37,16 +40,17 @@ 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/'),
os.path.join(BASE_DIR, 'media/'),
)
STATIC_URL = '/static/'
STATIC_ROOT = ''
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static/'),
os.path.join(BASE_DIR, 'static/'),
)
STATICFILES_FINDERS = (
......@@ -54,8 +58,7 @@ STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
SECRET_KEY = secret.SECRET_KEY
# TEMPLATING
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
......@@ -70,39 +73,58 @@ TEMPLATES = [
'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',
'go',
'django.contrib.admin',
'qrcode',
'crispy_forms',
'bootstrap3_datetime',
'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',
)
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer'
CRISPY_TEMPLATE_PACK = 'bootstrap3'
# LOGGING
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
......@@ -137,56 +159,35 @@ LOGGING = {
}
}
# CAS AUTH
LOGIN_URL = '/login'
LOGOUT_URL = '/logout'
LOGIN_REDIRECT_URL = '/'
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'cas.backends.CASBackend',
)
CAS_SERVER_URL = "https://login.gmu.edu"
CAS_SERVER_URL = os.environ['GO_CAS_URL']
CAS_LOGOUT_COMPLETELY = True
CAS_PROVIDE_URL_TO_LOGOUT = True
AUTHENTICATION_BACKENDS += (
'cas.backends.CASBackend',
)
CAS_RESPONSE_CALLBACKS = (
'go.cas_callbacks.create_user',
)
INSTALLED_APPS += (
'cas',
)
MIDDLEWARE_CLASSES += (
'cas.middleware.CASMiddleware',
)
CRISPY_TEMPLATE_PACK = 'bootstrap3'
# Mail settings
EMAIL_HOST = secret.EMAIL_HOST
EMAIL_PORT = secret.EMAIL_PORT
EMAIL_HOST_USER = secret.EMAIL_HOST_USER
EMAIL_HOST_PASSWORD = secret.EMAIL_HOST_PASSWORD
EMAIL_FROM = "example@example.com"
EMAIL_TO = "to@example.com"
# 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 line 231 in views.py
# Domain used to email to users. See implementation in views.py
# ie. in Mason's case '@masonlive.gmu.edu'
EMAIL_DOMAIN = "@example.com"
# Use redis cache when not in local development
if DEBUG:
pass
else:
CACHES = {
'default': {
'BACKEND': 'redis_cache.RedisCache',
'LOCATION': 'localhost:6379',
},
}
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',
},
}
import os
# Create a new file 'secret.py' and copy these contents into that file
# Please be sure to keep these variables secret in production
# You can generate a secret key from the following link: http://www.miniwebtool.com/django-secret-key-generator/
SECRET_KEY = os.environ['SECRET_KEY']
# Use the values from the database configuration
DB_NAME = os.environ['DB_NAME']
DB_USER = os.environ['DB_USER']
# Remember to use a strong password in production
DB_PASSWORD = os.environ['DB_PASSWORD']
# Often left blank
DB_HOST = os.environ['DB_HOST']
# Set piwik server site id (piwik can track multiple websites)
#PIWIK_SITE_ID = os.environ['PIWIK_SITE_ID']
# Point to the piwik url
#PIWIK_URL = os.environ['PIWIK_URL']
# Email configuration, if necessary
EMAIL_HOST = os.environ['EMAIL_HOST']
EMAIL_PORT = os.environ['EMAIL_PORT']
EMAIL_HOST_USER = os.environ['EMAIL_HOST_USER']
EMAIL_HOST_PASSWORD = os.environ['EMAIL_HOST_PASSWORD']
# Create a new file 'secret.py' and copy these contents into that file
# Please be sure to keep these variables secret in production
# You can generate a secret key from the following link: http://www.miniwebtool.com/django-secret-key-generator/
SECRET_KEY = ""
# Use the values from the database configuration
DB_NAME = ""
DB_USER = ""
# Remember to use a strong password in production
DB_PASSWORD = ""
# Often left blank
DB_HOST = ""
# Email configuration, if necessary
EMAIL_HOST = ""
EMAIL_PORT = ""
EMAIL_HOST_USER = ""
EMAIL_HOST_PASSWORD = ""
#Create a new file 'settings.py' and copy these contents into that file
from . import secret
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# DEBUG mode is used to view more details when errors occur
# Do not have set True in production
DEBUG = os.environ['debug']
ADMINS = ()
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': secret.DB_NAME,
'USER': secret.DB_USER,
'PASSWORD': secret.DB_PASSWORD,
'HOST': secret.DB_HOST,
'PORT': '3306',
}
}
# The domains this application will be deployed on
# e.g. Which domains this app should listen to requests from.
ALLOWED_HOSTS = [os.environ['host']]
# Peoplefinder API
PF_URL = "https://api.srct.gmu.edu/pf/v1/"
TIME_ZONE = 'America/New_York'
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
USE_I18N = True
USE_L10N = True
USE_TZ = True
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',
)
SECRET_KEY = secret.SECRET_KEY
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
}
}
]
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',
)
ROOT_URLCONF = 'settings.urls'
WSGI_APPLICATION = 'settings.wsgi.application'
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'go',
'django.contrib.admin',
'qrcode',
'crispy_forms',
'bootstrap3_datetime',
)
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer'
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'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}
LOGIN_URL = '/login'
LOGOUT_URL = '/logout'
LOGIN_REDIRECT_URL = '/'
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
)
CAS_SERVER_URL = os.environ['cas_url']
CAS_LOGOUT_COMPLETELY = True
CAS_PROVIDE_URL_TO_LOGOUT = True
AUTHENTICATION_BACKENDS += (
'cas.backends.CASBackend',
)
CAS_RESPONSE_CALLBACKS = (
'go.cas_callbacks.create_user',
)
INSTALLED_APPS += (
'cas',
)
MIDDLEWARE_CLASSES += (
'cas.middleware.CASMiddleware',
)
CRISPY_TEMPLATE_PACK = 'bootstrap3'
# Mail settings
EMAIL_HOST = secret.EMAIL_HOST
EMAIL_PORT = secret.EMAIL_PORT
EMAIL_HOST_USER = secret.EMAIL_HOST_USER
EMAIL_HOST_PASSWORD = secret.EMAIL_HOST_PASSWORD
EMAIL_FROM = "example@example.com"
EMAIL_TO = "to@example.com"
# Domain used to email to users. See line 231 in views.py
# ie. in Mason's case '@masonlive.gmu.edu'
EMAIL_DOMAIN = os.environ['email_domain']
# dummy cache for development-- doesn't actually cache things
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
}
}
......@@ -166,7 +166,7 @@ class UrlsTest(TestCase):
url = reverse('useradmin')
self.assertEqual(url, '/useradmin')
def test_useradmin(self):
def test_login(self):
"""
/login - login portal
"""
......@@ -174,7 +174,7 @@ class UrlsTest(TestCase):
url = reverse('go_login')
self.assertEqual(url, '/login')
def test_useradmin(self):
def test_logout(self):
"""
/logout - logout portal
"""
......
......@@ -8,7 +8,7 @@ https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/
"""
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.production")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
......@@ -8,6 +8,23 @@
# - Django
- hosts: all
environment: