Skip to content

Commit

Permalink
Inclusion of python-decouple to read the env file
Browse files Browse the repository at this point in the history
  • Loading branch information
Anselmo Rossiello authored and Anselmo Rossiello committed Aug 21, 2019
1 parent 2b31990 commit 829b5dc
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 59 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ python-dateutil
django-timezone-field
pygments
psycopg2
python-decouple

### Apache Configuration
In terms of codebase, there appears to be a common codebase that serves out the Whatcom and the BC version of the app. The legacy app already had a 'BC-specific' side to the app :
Expand Down
117 changes: 58 additions & 59 deletions app/backend/arm/settings.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#from importlib import import_module
from threading import Lock
#import warnings
import os, sys
import socket
from decouple import config
import logging
logger = logging.getLogger( __file__ )

logger = logging.getLogger(__file__)

# Debugging flags:
DEBUG = True #os.environ.get( 'DEBUG' )
DEBUG = config('DEBUG', default='False', cast=bool)

# Absolute filesystem path to the project.
ABSOLUTE_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

ADMIN_EMAIL=os.environ.get( 'ADMIN_EMAIL' )
ADMIN_EMAIL = config('ADMIN_EMAIL', default='')
ADMINS = (
('Admin', ADMIN_EMAIL),
)

ALLOWED_HOSTS = [ 'localhost', '127.0.0.1', socket.gethostname(), 'arm-orig.azurewebsites.net' ]
ALLOWED_HOSTS = ['localhost', '127.0.0.1', socket.gethostname(), 'arm-orig.azurewebsites.net']

AUTH_USER_MODEL = 'admins.Admin'

Expand All @@ -26,9 +26,9 @@
)
MANAGERS = ADMINS

DATABASE_NAME = os.environ.get( 'DATABASE_NAME' )
DATABASE_USER = os.environ.get( 'DATABASE_USER' )
DATABASE_PASSWORD = os.environ.get( 'DATABASE_PASSWORD' )
DATABASE_NAME = config('DATABASE_NAME')
DATABASE_USER = config('DATABASE_USER')
DATABASE_PASSWORD = config('DATABASE_PASSWORD')

# DATABASES = {
# 'default': {
Expand All @@ -47,24 +47,23 @@
DATE_FORMAT = 'N j, Y'
DATE_TIME_FORMAT = 'N j, Y, P'

DEFAULT_FROM_EMAIL = os.environ.get( 'DEFAULT_FROM_EMAIL' )
DEFAULT_FROM_EMAIL = config('DEFAULT_FROM_EMAIL')

TIME_FORMAT = 'H:i P'

# Mail Server info
EMAIL_HOST='localhost'
EMAIL_PORT=25
EMAIL_HOST = 'localhost'
EMAIL_PORT = 25

EMAIL_TO = os.environ.get( 'EMAIL_TO' )
EMAIL_TO = config('EMAIL_TO')

ENVIRONMENT=os.environ.get( 'ENVIRONMENT' )
ENVIRONMENT = config('ENVIRONMENT')

FIXTURE_DIRS = ( os.path.join( os.path.dirname( __file__ ), 'fixtures', 'dev' ), )
FIXTURE_DIRS = (os.path.join(os.path.dirname(__file__), 'fixtures', 'dev'),)

# FORCE_SCRIPT_NAME='arm'
USE_X_FORWARDED_HOST = True


INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
Expand All @@ -86,24 +85,24 @@
# For admin functionality
'admins',

'arm', # for management commands
#'arm.calc' ,
'arm', # for management commands
# 'arm.calc' ,
)

LANGUAGE_CODE = 'en-us'

# Lock implementation
LOCK=Lock()
LOCK = Lock()

LOGIN_URL='/admin/'
LOGIN_REDIRECT_URL='/'
LOGIN_URL = '/admin/'
LOGIN_REDIRECT_URL = '/'

# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGER_LEVEL = os.environ.get( 'LOGGER_LEVEL' )
LOGGER_LEVEL = config('LOGGER_LEVEL', default='WARNING')
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
Expand Down Expand Up @@ -134,18 +133,18 @@
},
'loggers': {
'': {
'handlers': [ 'console', 'file_logging' ],
'handlers': ['console', 'file_logging'],
'level': LOGGER_LEVEL,
'propogate': True,
},
'django' : {
'django': {
'handlers': ['file_logging'],
'level' : LOGGER_LEVEL,
'propagate' : True,
'level': LOGGER_LEVEL,
'propagate': True,
},
'django.db' : {
'handlers' : ['db_logging'],
'level' : LOGGER_LEVEL,
'django.db': {
'handlers': ['db_logging'],
'level': LOGGER_LEVEL,
'propagate': False,
},
'django.request': {
Expand All @@ -166,39 +165,39 @@
},
'mail_admins': {
'level': 'ERROR',
'filters': [ 'require_debug_false' ],
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
},
'file_logging': {
'level' : LOGGER_LEVEL,
'class' : 'logging.handlers.RotatingFileHandler',
'backupCount' : 5,
'maxBytes': 1024 * 1024 * 5, # 5 mb
'filename': os.path.join( ABSOLUTE_PATH, 'logs', 'django.log'),
'level': LOGGER_LEVEL,
'class': 'logging.handlers.RotatingFileHandler',
'backupCount': 5,
'maxBytes': 1024 * 1024 * 5, # 5 mb
'filename': os.path.join(ABSOLUTE_PATH, 'logs', 'django.log'),
'formatter': 'verbose',
},
'db_logging': {
'level' : LOGGER_LEVEL,
'class' : 'logging.handlers.RotatingFileHandler',
'backupCount' : 5,
'maxBytes': 1024 * 1024 * 5, # 5 mb
'filename': os.path.join( ABSOLUTE_PATH, 'logs', 'django-db.log'),
'level': LOGGER_LEVEL,
'class': 'logging.handlers.RotatingFileHandler',
'backupCount': 5,
'maxBytes': 1024 * 1024 * 5, # 5 mb
'filename': os.path.join(ABSOLUTE_PATH, 'logs', 'django-db.log'),
},
'audit_logging': {
'level' : 'INFO',
'level': 'INFO',
'filters': ['audit_true'],
'class' : 'logging.handlers.RotatingFileHandler',
'class': 'logging.handlers.RotatingFileHandler',
'formatter': 'audit_format',
'backupCount' : 5,
'maxBytes': 1024 * 1024 * 5, # 5 mb
'filename': os.path.join( ABSOLUTE_PATH, 'logs', 'audit.log'),
'backupCount': 5,
'maxBytes': 1024 * 1024 * 5, # 5 mb
'filename': os.path.join(ABSOLUTE_PATH, 'logs', 'audit.log'),
},
},
}

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = os.path.join( ABSOLUTE_PATH, 'media')
MEDIA_ROOT = os.path.join(ABSOLUTE_PATH, 'media')

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
Expand All @@ -209,18 +208,18 @@
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
#'common.classes.SessionExpiryMiddleware',
# 'common.classes.SessionExpiryMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

# MOBILE keys
APNS_CERT='full_path'
APNS_SANDBOX=True
APNS_CERT = 'full_path'
APNS_SANDBOX = True

GCM_API_KEY='<>'
GCM_API_KEY = '<>'

PASSWORD_HASHERS = (
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
Expand Down Expand Up @@ -250,11 +249,11 @@
# 600 seconds is 10 min expirey
# 259200 three day expirey
#
SESSION_EXPIRY = ( 259200 * 20 )
SESSION_EXPIRY = (259200 * 20)

SESSION_SAVE_EVERY_REQUEST = True

SERVER_EMAIL = os.environ.get( 'SERVER_EMAIL' )
SERVER_EMAIL = config('SERVER_EMAIL')

SITE_ID = 4

Expand All @@ -267,21 +266,21 @@
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
os.path.join( ABSOLUTE_PATH, 'static/' ),
os.path.join(ABSOLUTE_PATH, 'static/'),
)

SUPPORT_EMAIL = os.environ.get( 'SUPPORT_EMAIL' )
SUPPORT_EMAIL = config('SUPPORT_EMAIL')

#TIME_ZONE = 'UTC'
# TIME_ZONE = 'UTC'
TIME_ZONE = 'America/Los_Angeles'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join( ABSOLUTE_PATH, 'templates', 'html' ),
os.path.join( ABSOLUTE_PATH, 'templates', 'emails' ),
],
os.path.join(ABSOLUTE_PATH, 'templates', 'html'),
os.path.join(ABSOLUTE_PATH, 'templates', 'emails'),
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
Expand All @@ -308,7 +307,7 @@
USE_TZ = True

# Where imports are uploaded to
UPLOAD_DIR = os.path.join( ABSOLUTE_PATH, 'media', 'uploads' )
UPLOAD_DIR = os.path.join(ABSOLUTE_PATH, 'media', 'uploads')

# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'arm.wsgi.application'
1 change: 1 addition & 0 deletions app/backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ python-dateutil
django-timezone-field
pygments
psycopg2
python-decouple

0 comments on commit 829b5dc

Please sign in to comment.