streamline settings
- use get_env_variable and other two scoops best practice - add managemails to INSTALLED_APPS
This commit is contained in:
parent
b0e5727b90
commit
46a65b5624
4 changed files with 45 additions and 90 deletions
|
@ -1,9 +1,30 @@
|
|||
# -*- python -*-
|
||||
# pymode:lint_ignore=E501
|
||||
"""Common settings and globals."""
|
||||
|
||||
|
||||
from os import environ
|
||||
from os.path import abspath, basename, dirname, join, normpath
|
||||
from sys import path
|
||||
|
||||
# Normally you should not import ANYTHING from Django directly
|
||||
# into your settings, but ImproperlyConfigured is an exception.
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
||||
|
||||
def get_env_variable(var_name):
|
||||
"""
|
||||
Get a setting from an environment variable.
|
||||
|
||||
:param str var_name: variable name
|
||||
|
||||
"""
|
||||
try:
|
||||
return environ[var_name]
|
||||
except KeyError:
|
||||
error_msg = "Set the %s environment variable" % var_name
|
||||
raise ImproperlyConfigured(error_msg)
|
||||
|
||||
|
||||
########## PATH CONFIGURATION
|
||||
# Absolute filesystem path to the Django project directory:
|
||||
|
@ -33,7 +54,7 @@ TEMPLATE_DEBUG = DEBUG
|
|||
########## MANAGER CONFIGURATION
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#admins
|
||||
ADMINS = (
|
||||
('Your Name', 'your_email@example.com'),
|
||||
(get_env_variable('GVA_ADMIN_NAME'), get_env_variable('GVA_ADMIN_EMAIL')),
|
||||
)
|
||||
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#managers
|
||||
|
@ -45,12 +66,12 @@ MANAGERS = ADMINS
|
|||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.',
|
||||
'NAME': '',
|
||||
'USER': '',
|
||||
'PASSWORD': '',
|
||||
'HOST': '',
|
||||
'PORT': '',
|
||||
'ENGINE': 'django.db.backends.postgresql_psycopg2',
|
||||
'NAME': get_env_variable('GVA_PGSQL_DATABASE'),
|
||||
'USER': get_env_variable('GVA_PGSQL_USER'),
|
||||
'PASSWORD': get_env_variable('GVA_PGSQL_PASSWORD'),
|
||||
'HOST': get_env_variable('GVA_PGSQL_HOSTNAME'),
|
||||
'PORT': get_env_variable('GVA_PGSQL_PORT'),
|
||||
}
|
||||
}
|
||||
########## END DATABASE CONFIGURATION
|
||||
|
@ -58,13 +79,15 @@ DATABASES = {
|
|||
|
||||
########## GENERAL CONFIGURATION
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#time-zone
|
||||
TIME_ZONE = 'America/Los_Angeles'
|
||||
TIME_ZONE = 'Europe/Berlin'
|
||||
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#language-code
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
LANGUAGE_CODE = 'de-de'
|
||||
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#site-id
|
||||
SITE_ID = 1
|
||||
SITES_DOMAIN_NAME = get_env_variable('GVA_DOMAIN_NAME')
|
||||
SITES_SITE_NAME = get_env_variable('GVA_SITE_NAME')
|
||||
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-i18n
|
||||
USE_I18N = True
|
||||
|
@ -109,7 +132,7 @@ STATICFILES_FINDERS = (
|
|||
########## SECRET CONFIGURATION
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
|
||||
# Note: This key should only be used for development and testing.
|
||||
SECRET_KEY = r"2_9idi1%8##(2(85$*!3ag*-*9wy@u1kj0s5^q$ox!477n+s)0"
|
||||
SECRET_KEY = get_env_variable('GVA_SITE_SECRET')
|
||||
########## END SECRET CONFIGURATION
|
||||
|
||||
|
||||
|
@ -163,6 +186,8 @@ MIDDLEWARE_CLASSES = (
|
|||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
# uncomment next line to enable translation to browser locale
|
||||
'django.middleware.locale.LocaleMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
)
|
||||
########## END MIDDLEWARE CONFIGURATION
|
||||
|
@ -185,7 +210,7 @@ DJANGO_APPS = (
|
|||
'django.contrib.staticfiles',
|
||||
|
||||
# Useful template tags:
|
||||
# 'django.contrib.humanize',
|
||||
'django.contrib.humanize',
|
||||
|
||||
# Admin panel and documentation:
|
||||
'django.contrib.admin',
|
||||
|
@ -194,6 +219,7 @@ DJANGO_APPS = (
|
|||
|
||||
# Apps specific for this project go here.
|
||||
LOCAL_APPS = (
|
||||
'managemails',
|
||||
)
|
||||
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
# -*- python -*-
|
||||
# pymode:lint_ignore=W0401,E501
|
||||
"""Development settings and globals."""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from os.path import join, normpath
|
||||
|
||||
from .base import *
|
||||
|
||||
|
||||
|
@ -22,21 +22,6 @@ EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
|
|||
########## END EMAIL CONFIGURATION
|
||||
|
||||
|
||||
########## DATABASE CONFIGURATION
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': normpath(join(DJANGO_ROOT, 'default.db')),
|
||||
'USER': '',
|
||||
'PASSWORD': '',
|
||||
'HOST': '',
|
||||
'PORT': '',
|
||||
}
|
||||
}
|
||||
########## END DATABASE CONFIGURATION
|
||||
|
||||
|
||||
########## CACHE CONFIGURATION
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#caches
|
||||
CACHES = {
|
||||
|
@ -60,5 +45,5 @@ MIDDLEWARE_CLASSES += (
|
|||
DEBUG_TOOLBAR_PATCH_SETTINGS = False
|
||||
|
||||
# http://django-debug-toolbar.readthedocs.org/en/latest/installation.html
|
||||
INTERNAL_IPS = ('127.0.0.1',)
|
||||
INTERNAL_IPS = ('127.0.0.1', '10.0.2.2')
|
||||
########## END TOOLBAR CONFIGURATION
|
||||
|
|
|
@ -1,67 +1,28 @@
|
|||
# -*- python -*-
|
||||
# pymode:lint_ignore=W0401,E501
|
||||
"""Production settings and globals."""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from os import environ
|
||||
|
||||
from .base import *
|
||||
|
||||
# Normally you should not import ANYTHING from Django directly
|
||||
# into your settings, but ImproperlyConfigured is an exception.
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
||||
|
||||
def get_env_setting(setting):
|
||||
""" Get the environment setting or return exception """
|
||||
try:
|
||||
return environ[setting]
|
||||
except KeyError:
|
||||
error_msg = "Set the %s env variable" % setting
|
||||
raise ImproperlyConfigured(error_msg)
|
||||
|
||||
########## HOST CONFIGURATION
|
||||
# See: https://docs.djangoproject.com/en/1.5/releases/1.5/#allowed-hosts-required-in-production
|
||||
ALLOWED_HOSTS = []
|
||||
ALLOWED_HOSTS = [SITES_DOMAIN_NAME]
|
||||
########## END HOST CONFIGURATION
|
||||
|
||||
########## EMAIL CONFIGURATION
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-backend
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
||||
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-host
|
||||
EMAIL_HOST = environ.get('EMAIL_HOST', 'smtp.gmail.com')
|
||||
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-host-password
|
||||
EMAIL_HOST_PASSWORD = environ.get('EMAIL_HOST_PASSWORD', '')
|
||||
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-host-user
|
||||
EMAIL_HOST_USER = environ.get('EMAIL_HOST_USER', 'your_email@example.com')
|
||||
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-port
|
||||
EMAIL_PORT = environ.get('EMAIL_PORT', 587)
|
||||
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-subject-prefix
|
||||
EMAIL_SUBJECT_PREFIX = '[%s] ' % SITE_NAME
|
||||
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-use-tls
|
||||
EMAIL_USE_TLS = True
|
||||
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#server-email
|
||||
SERVER_EMAIL = EMAIL_HOST_USER
|
||||
SERVER_EMAIL = get_env_variable('GVA_SITE_ADMINMAIL')
|
||||
########## END EMAIL CONFIGURATION
|
||||
|
||||
########## DATABASE CONFIGURATION
|
||||
DATABASES = {}
|
||||
########## END DATABASE CONFIGURATION
|
||||
|
||||
|
||||
########## CACHE CONFIGURATION
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#caches
|
||||
CACHES = {}
|
||||
#CACHES = {}
|
||||
########## END CACHE CONFIGURATION
|
||||
|
||||
|
||||
########## SECRET CONFIGURATION
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
|
||||
SECRET_KEY = get_env_setting('SECRET_KEY')
|
||||
########## END SECRET CONFIGURATION
|
||||
|
|
|
@ -1,20 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
from .base import *
|
||||
|
||||
########## TEST SETTINGS
|
||||
TEST_RUNNER = 'discover_runner.DiscoverRunner'
|
||||
TEST_DISCOVER_TOP_LEVEL = SITE_ROOT
|
||||
TEST_DISCOVER_ROOT = SITE_ROOT
|
||||
TEST_DISCOVER_PATTERN = "test_*.py"
|
||||
########## IN-MEMORY TEST DATABASE
|
||||
DATABASES = {
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.sqlite3",
|
||||
"NAME": ":memory:",
|
||||
"USER": "",
|
||||
"PASSWORD": "",
|
||||
"HOST": "",
|
||||
"PORT": "",
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue