Skip to content

Commit

Permalink
revise settings to use Enum
Browse files Browse the repository at this point in the history
I think having an enum of various possible deployment
environments (which could hypothetically be extended in the future) is
more elegant than just having an IS_DEVELOPMENT boolean.
  • Loading branch information
zackmdavis committed Feb 20, 2015
1 parent b2670bb commit dfeed00
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@
"""

import os
from enum import Enum

from django.utils.translation import ugettext_lazy as _

BASE_DIR = os.path.dirname(os.path.dirname(__file__))

IS_DEVELOPMENT = os.path.exists('.development')
Environment = Enum('Environment', ("development", "heroku_demo"))

DEBUG = os.environ.get('DEBUG') or IS_DEVELOPMENT
# XXX: surely there must be a better way to detect deployment
# environment at runtime?
ENVIRONMENT = (Environment.development if os.path.exists('.development')
else Environment.heroku_demo)

if IS_DEVELOPMENT:
DEBUG = os.environ.get('DEBUG') or ENVIRONMENT is Environment.development

if ENVIRONMENT is Environment.development:
SECRET_KEY = (os.environ.get('SECRET_KEY')
or "fake_development_unsecret_key")
else:
Expand All @@ -33,7 +39,7 @@
'core',
)

if DEBUG and IS_DEVELOPMENT:
if DEBUG and ENVIRONMENT is Environment.development:
INSTALLED_APPS += ('debug_toolbar',)

MIDDLEWARE_CLASSES = (
Expand All @@ -50,7 +56,7 @@

WSGI_APPLICATION = 'wsgi.application'

if IS_DEVELOPMENT:
if ENVIRONMENT is Environment.development:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
Expand All @@ -66,7 +72,7 @@
AUTH_REDIRECT_URL = "/"
LOGIN_URL = "/login/"

if DEBUG and IS_DEVELOPMENT:
if DEBUG and ENVIRONMENT is Environment.development:
PASSWORD_HASHERS = ('django.contrib.auth.hashers.MD5PasswordHasher',)

LANGUAGE_CODE = 'en-us'
Expand All @@ -81,7 +87,7 @@

LANGUAGES = (
('en', _('English')),
('es', _('Spanish')),
# ('es', _('Spanish')),
)

LOCALE_PATHS = ('translations',)
Expand All @@ -106,7 +112,7 @@
STATICFILES_DIRS = ('static',)

SERVE_STATIC_LIBS_LOCALLY = (os.environ.get('SERVE_STATIC_LIBS_LOCALLY')
or IS_DEVELOPMENT)
or ENVIRONMENT is Environment.development)

STATIC_URL = '/static/'

Expand Down

0 comments on commit dfeed00

Please sign in to comment.