Replace django-configuration with django-environ

- makes it compatible with django 1.8
- removes magic
This commit is contained in:
Saurabh Kumar 2015-04-20 02:39:00 +05:30
parent b007a8e0ac
commit 89c0fb3ff8
9 changed files with 370 additions and 393 deletions

View File

@ -24,7 +24,7 @@ Features
* For Django 1.7 * For Django 1.7
* Twitter Bootstrap_ 3 * Twitter Bootstrap_ 3
* AngularJS_ * AngularJS_
* Settings management via django-configurations_ * Settings management via django-environ_
* Registration via django-allauth_ * Registration via django-allauth_
* User avatars via django-avatar_ * User avatars via django-avatar_
* Procfile_ for deploying to Heroku * Procfile_ for deploying to Heroku
@ -35,7 +35,7 @@ Features
.. _Bootstrap: https://github.com/twbs/bootstrap .. _Bootstrap: https://github.com/twbs/bootstrap
.. _AngularJS: https://github.com/angular/angular.js .. _AngularJS: https://github.com/angular/angular.js
.. _django-configurations: https://github.com/jezdez/django-configurations .. _django-environ: https://github.com/joke2k/django-environ
.. _django-allauth: https://github.com/pennersr/django-allauth .. _django-allauth: https://github.com/pennersr/django-allauth
.. _django-avatar: https://github.com/jezdez/django-avatar/ .. _django-avatar: https://github.com/jezdez/django-avatar/
.. _Procfile: https://devcenter.heroku.com/articles/procfile .. _Procfile: https://devcenter.heroku.com/articles/procfile

View File

@ -19,8 +19,8 @@ Environment Variable Django Setting Development
DJANGO_AWS_ACCESS_KEY_ID AWS_ACCESS_KEY_ID n/a raises error DJANGO_AWS_ACCESS_KEY_ID AWS_ACCESS_KEY_ID n/a raises error
DJANGO_AWS_SECRET_ACCESS_KEY AWS_SECRET_ACCESS_KEY n/a raises error DJANGO_AWS_SECRET_ACCESS_KEY AWS_SECRET_ACCESS_KEY n/a raises error
DJANGO_AWS_STORAGE_BUCKET_NAME AWS_STORAGE_BUCKET_NAME n/a raises error DJANGO_AWS_STORAGE_BUCKET_NAME AWS_STORAGE_BUCKET_NAME n/a raises error
DJANGO_CACHES CACHES locmem memcached DJANGO_CACHES CACHES (default) locmem memcached
DJANGO_DATABASES DATABASES See code See code DJANGO_DATABASES DATABASES (default) See code See code
DJANGO_DEBUG DEBUG True False DJANGO_DEBUG DEBUG True False
DJANGO_EMAIL_BACKEND EMAIL_BACKEND django.core.mail.backends.console.EmailBackend django.core.mail.backends.smtp.EmailBackend DJANGO_EMAIL_BACKEND EMAIL_BACKEND django.core.mail.backends.console.EmailBackend django.core.mail.backends.smtp.EmailBackend
DJANGO_SECRET_KEY SECRET_KEY CHANGEME!!! raises error DJANGO_SECRET_KEY SECRET_KEY CHANGEME!!! raises error
@ -99,7 +99,6 @@ Run these commands to deploy the project to Heroku:
heroku addons:add sendgrid:starter heroku addons:add sendgrid:starter
heroku addons:add memcachier:dev heroku addons:add memcachier:dev
heroku pg:promote DATABASE_URL heroku pg:promote DATABASE_URL
heroku config:set DJANGO_CONFIGURATION=Production
heroku config:set DJANGO_SECRET_KEY=RANDOM_SECRET_KEY_HERE heroku config:set DJANGO_SECRET_KEY=RANDOM_SECRET_KEY_HERE
heroku config:set DJANGO_AWS_ACCESS_KEY_ID=YOUR_AWS_ID_HERE heroku config:set DJANGO_AWS_ACCESS_KEY_ID=YOUR_AWS_ID_HERE
heroku config:set DJANGO_AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_ACCESS_KEY_HERE heroku config:set DJANGO_AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_ACCESS_KEY_HERE
@ -139,7 +138,6 @@ You can then deploy by running the following commands.
ssh -t dokku@yourservername.com dokku memcached:link {{cookiecutter.repo_name}}-memcached {{cookiecutter.repo_name}} ssh -t dokku@yourservername.com dokku memcached:link {{cookiecutter.repo_name}}-memcached {{cookiecutter.repo_name}}
ssh -t dokku@yourservername.com dokku postgres:create {{cookiecutter.repo_name}}-postgres ssh -t dokku@yourservername.com dokku postgres:create {{cookiecutter.repo_name}}-postgres
ssh -t dokku@yourservername.com dokku postgres:link {{cookiecutter.repo_name}}-postgres {{cookiecutter.repo_name}} ssh -t dokku@yourservername.com dokku postgres:link {{cookiecutter.repo_name}}-postgres {{cookiecutter.repo_name}}
ssh -t dokku@yourservername.com dokku config:set {{cookiecutter.repo_name}} DJANGO_CONFIGURATION=Production
ssh -t dokku@yourservername.com dokku config:set {{cookiecutter.repo_name}} DJANGO_SECRET_KEY=RANDOM_SECRET_KEY_HERE ssh -t dokku@yourservername.com dokku config:set {{cookiecutter.repo_name}} DJANGO_SECRET_KEY=RANDOM_SECRET_KEY_HERE
ssh -t dokku@yourservername.com dokku config:set {{cookiecutter.repo_name}} DJANGO_AWS_ACCESS_KEY_ID=YOUR_AWS_ID_HERE ssh -t dokku@yourservername.com dokku config:set {{cookiecutter.repo_name}} DJANGO_AWS_ACCESS_KEY_ID=YOUR_AWS_ID_HERE
ssh -t dokku@yourservername.com dokku config:set {{cookiecutter.repo_name}} DJANGO_AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_ACCESS_KEY_HERE ssh -t dokku@yourservername.com dokku config:set {{cookiecutter.repo_name}} DJANGO_AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_ACCESS_KEY_HERE

View File

@ -2,10 +2,8 @@
django>=1.7.7,<1.8 django>=1.7.7,<1.8
# Configuration # Configuration
django-configurations==0.8 django-environ==0.3.0
django-secure==1.0.1 django-secure==1.0.1
django-cache-url==0.8.0
dj-database-url==0.3.0
# Forms # Forms
django-braces==1.4.0 django-braces==1.4.0

View File

@ -1,5 +1 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import
from .local import Local # noqa
from .production import Production # noqa

View File

@ -8,267 +8,254 @@ https://docs.djangoproject.com/en/dev/topics/settings/
For the full list of settings and their values, see For the full list of settings and their values, see
https://docs.djangoproject.com/en/dev/ref/settings/ https://docs.djangoproject.com/en/dev/ref/settings/
""" """
from __future__ import absolute_import, unicode_literals
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) import environ
import os
from os.path import join, dirname
from configurations import Configuration, values APPS_DIR = environ.Path(__file__) - 1 # one folder back (/a/b/ - 2 = /a/)
ROOT_DIR = APPS_DIR - 1
BASE_DIR = dirname(dirname(__file__)) env = environ.Env()
# APP CONFIGURATION
# ------------------------------------------------------------------------------
DJANGO_APPS = (
# Default Django apps:
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Useful template tags:
# 'django.contrib.humanize',
# Admin
'django.contrib.admin',
)
THIRD_PARTY_APPS = (
'crispy_forms', # Form layouts
'avatar', # for user avatars
'allauth', # registration
'allauth.account', # registration
'allauth.socialaccount', # registration
)
# Apps specific for this project go here.
LOCAL_APPS = (
'users', # custom users app
# Your stuff: custom apps go here
)
# See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
# MIDDLEWARE CONFIGURATION
# ------------------------------------------------------------------------------
MIDDLEWARE_CLASSES = (
# Make sure djangosecure.middleware.SecurityMiddleware is listed first
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
# MIGRATIONS CONFIGURATION
# ------------------------------------------------------------------------------
MIGRATION_MODULES = {
'sites': 'contrib.sites.migrations'
}
# DEBUG
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
DEBUG = env.bool("DJANGO_DEBUG", False)
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug
TEMPLATE_DEBUG = DEBUG
# SECRET CONFIGURATION
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
# Raises ImproperlyConfigured exception if DJANO_SECRET_KEY not in os.environ
SECRET_KEY = env("DJANGO_SECRET_KEY")
# FIXTURE CONFIGURATION
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS
FIXTURE_DIRS = (
str(APPS_DIR.path('fixtures')),
)
# EMAIL CONFIGURATION
# ------------------------------------------------------------------------------
EMAIL_BACKEND = env('DJANGO_EMAIL_BACKEND', default='django.core.mail.backends.smtp.EmailBackend')
# END EMAIL CONFIGURATION
# MANAGER CONFIGURATION
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#admins
ADMINS = (
("""{{cookiecutter.author_name}}""", '{{cookiecutter.email}}'),
)
# See: https://docs.djangoproject.com/en/dev/ref/settings/#managers
MANAGERS = ADMINS
# DATABASE CONFIGURATION
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = {
# Raises ImproperlyConfigured exception if DATABASE_URL not in os.environ
'default': env.db("DATABASE_URL", default="postgres://localhost/{{cookiecutter.repo_name}}"),
}
DATABASES['default']['ATOMIC_REQUESTS'] = True
class Common(Configuration): # GENERAL CONFIGURATION
# ------------------------------------------------------------------------------
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = '{{ cookiecutter.timezone }}'
# APP CONFIGURATION # See: https://docs.djangoproject.com/en/dev/ref/settings/#language-code
DJANGO_APPS = ( LANGUAGE_CODE = 'en-us'
# Default Django apps:
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Useful template tags: # See: https://docs.djangoproject.com/en/dev/ref/settings/#site-id
# 'django.contrib.humanize', SITE_ID = 1
# Admin # See: https://docs.djangoproject.com/en/dev/ref/settings/#use-i18n
'django.contrib.admin', USE_I18N = True
)
THIRD_PARTY_APPS = (
'crispy_forms', # Form layouts
'avatar', # for user avatars
'allauth', # registration
'allauth.account', # registration
'allauth.socialaccount', # registration
)
# Apps specific for this project go here. # See: https://docs.djangoproject.com/en/dev/ref/settings/#use-l10n
LOCAL_APPS = ( USE_L10N = True
'users', # custom users app
# Your stuff: custom apps go here
)
# See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps # See: https://docs.djangoproject.com/en/dev/ref/settings/#use-tz
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS USE_TZ = True
# END APP CONFIGURATION # END GENERAL CONFIGURATION
# MIDDLEWARE CONFIGURATION # TEMPLATE CONFIGURATION
MIDDLEWARE_CLASSES = ( # ------------------------------------------------------------------------------
# Make sure djangosecure.middleware.SecurityMiddleware is listed first # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
'django.contrib.sessions.middleware.SessionMiddleware', TEMPLATE_CONTEXT_PROCESSORS = (
'django.middleware.common.CommonMiddleware', 'django.contrib.auth.context_processors.auth',
'django.middleware.csrf.CsrfViewMiddleware', 'allauth.account.context_processors.account',
'django.contrib.auth.middleware.AuthenticationMiddleware', 'allauth.socialaccount.context_processors.socialaccount',
'django.contrib.messages.middleware.MessageMiddleware', 'django.core.context_processors.debug',
'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.core.context_processors.i18n',
) 'django.core.context_processors.media',
# END MIDDLEWARE CONFIGURATION 'django.core.context_processors.static',
'django.core.context_processors.tz',
'django.contrib.messages.context_processors.messages',
'django.core.context_processors.request',
# Your stuff: custom template context processors go here
)
# MIGRATIONS CONFIGURATION # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
MIGRATION_MODULES = { TEMPLATE_DIRS = (
'sites': 'contrib.sites.migrations' str(APPS_DIR.path('templates')),
} )
# END MIGRATIONS CONFIGURATION
# DEBUG TEMPLATE_LOADERS = (
# See: https://docs.djangoproject.com/en/dev/ref/settings/#debug 'django.template.loaders.filesystem.Loader',
DEBUG = values.BooleanValue(False) 'django.template.loaders.app_directories.Loader',
)
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug # See: http://django-crispy-forms.readthedocs.org/en/latest/install.html#template-packs
TEMPLATE_DEBUG = DEBUG CRISPY_TEMPLATE_PACK = 'bootstrap3'
# END DEBUG
# SECRET CONFIGURATION # STATIC FILE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key # ------------------------------------------------------------------------------
# Note: This key only used for development and testing. # See: https://docs.djangoproject.com/en/dev/ref/settings/#static-root
# In production, this is changed to a values.SecretValue() setting STATIC_ROOT = str(ROOT_DIR('staticfiles'))
SECRET_KEY = 'CHANGEME!!!'
# END SECRET CONFIGURATION
# FIXTURE CONFIGURATION # See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url
# See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS STATIC_URL = '/static/'
FIXTURE_DIRS = (
join(BASE_DIR, 'fixtures'),
)
# END FIXTURE CONFIGURATION
# EMAIL CONFIGURATION # See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
EMAIL_BACKEND = values.Value('django.core.mail.backends.smtp.EmailBackend') STATICFILES_DIRS = (
# END EMAIL CONFIGURATION str(APPS_DIR.path('static')),
)
# MANAGER CONFIGURATION # See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders
# See: https://docs.djangoproject.com/en/dev/ref/settings/#admins STATICFILES_FINDERS = (
ADMINS = ( 'django.contrib.staticfiles.finders.FileSystemFinder',
("""{{cookiecutter.author_name}}""", '{{cookiecutter.email}}'), 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
) )
# See: https://docs.djangoproject.com/en/dev/ref/settings/#managers # MEDIA CONFIGURATION
MANAGERS = ADMINS # ------------------------------------------------------------------------------
# END MANAGER CONFIGURATION # See: https://docs.djangoproject.com/en/dev/ref/settings/#media-root
MEDIA_ROOT = str(APPS_DIR('media'))
# DATABASE CONFIGURATION # See: https://docs.djangoproject.com/en/dev/ref/settings/#media-url
# See: https://docs.djangoproject.com/en/dev/ref/settings/#databases MEDIA_URL = '/media/'
DATABASES = values.DatabaseURLValue('postgres://localhost/{{cookiecutter.repo_name}}')
# END DATABASE CONFIGURATION
# CACHING # URL Configuration
# Do this here because thanks to django-pylibmc-sasl and pylibmc # ------------------------------------------------------------------------------
# memcacheify (used on heroku) is painful to install on windows. ROOT_URLCONF = 'urls'
CACHES = {
'default': { # See: https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', WSGI_APPLICATION = 'wsgi.application'
'LOCATION': ''
# AUTHENTICATION CONFIGURATION
# ------------------------------------------------------------------------------
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
)
# Some really nice defaults
ACCOUNT_AUTHENTICATION_METHOD = 'username'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
# END AUTHENTICATION CONFIGURATION
# Custom user app defaults
# Select the correct user model
AUTH_USER_MODEL = 'users.User'
LOGIN_REDIRECT_URL = 'users:redirect'
LOGIN_URL = 'account_login'
# SLUGLIFIER
AUTOSLUG_SLUGIFY_FUNCTION = 'slugify.slugify'
# LOGGING CONFIGURATION
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#logging
# 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 when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
} }
} },
# END CACHING 'handlers': {
'mail_admins': {
# GENERAL CONFIGURATION 'level': 'ERROR',
'filters': ['require_debug_false'],
# Local time zone for this installation. Choices can be found here: 'class': 'django.utils.log.AdminEmailHandler'
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = '{{ cookiecutter.timezone }}'
# See: https://docs.djangoproject.com/en/dev/ref/settings/#language-code
LANGUAGE_CODE = 'en-us'
# See: https://docs.djangoproject.com/en/dev/ref/settings/#site-id
SITE_ID = 1
# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-i18n
USE_I18N = True
# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-l10n
USE_L10N = True
# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-tz
USE_TZ = True
# END GENERAL CONFIGURATION
# TEMPLATE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'allauth.account.context_processors.account',
'allauth.socialaccount.context_processors.socialaccount',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.core.context_processors.tz',
'django.contrib.messages.context_processors.messages',
'django.core.context_processors.request',
# Your stuff: custom template context processors go here
)
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
TEMPLATE_DIRS = (
join(BASE_DIR, 'templates'),
)
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
# See: http://django-crispy-forms.readthedocs.org/en/latest/install.html#template-packs
CRISPY_TEMPLATE_PACK = 'bootstrap3'
# END TEMPLATE CONFIGURATION
# STATIC FILE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-root
STATIC_ROOT = join(os.path.dirname(BASE_DIR), 'staticfiles')
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url
STATIC_URL = '/static/'
# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
STATICFILES_DIRS = (
join(BASE_DIR, 'static'),
)
# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
# END STATIC FILE CONFIGURATION
# MEDIA CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-root
MEDIA_ROOT = join(BASE_DIR, 'media')
# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-url
MEDIA_URL = '/media/'
# END MEDIA CONFIGURATION
# URL Configuration
ROOT_URLCONF = 'urls'
# See: https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application
WSGI_APPLICATION = 'wsgi.application'
# End URL Configuration
# AUTHENTICATION CONFIGURATION
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
)
# Some really nice defaults
ACCOUNT_AUTHENTICATION_METHOD = 'username'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
# END AUTHENTICATION CONFIGURATION
# Custom user app defaults
# Select the correct user model
AUTH_USER_MODEL = 'users.User'
LOGIN_REDIRECT_URL = 'users:redirect'
LOGIN_URL = 'account_login'
# END Custom user app defaults
# SLUGLIFIER
AUTOSLUG_SLUGIFY_FUNCTION = 'slugify.slugify'
# END SLUGLIFIER
# LOGGING CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#logging
# 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 when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
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,
},
} }
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
} }
# END LOGGING CONFIGURATION }
@classmethod # Your common stuff: Below this line define 3rd party library settings
def post_setup(cls):
cls.DATABASES['default']['ATOMIC_REQUESTS'] = True
# Your common stuff: Below this line define 3rd party library settings

View File

@ -1,44 +1,54 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
''' '''
Local Configurations Local settings
- Runs in Debug mode - Runs in Debug mode
- Uses console backend for emails - Uses console backend for emails
- Use Django Debug Toolbar - Use Django Debug Toolbar
''' '''
from configurations import values
from .common import Common from .common import *
# DEBUG
# ------------------------------------------------------------------------------
DEBUG = env.bool('DJANGO_DEBUG', default=True)
TEMPLATE_DEBUG = DEBUG
# SECRET CONFIGURATION
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
# Note: This key only used for development and testing.
SECRET_KEY = env("DJANGO_SECRET_KEY", 'CHANGEME!!!')
# Mail settings
# ------------------------------------------------------------------------------
EMAIL_HOST = 'localhost'
EMAIL_PORT = 1025
EMAIL_BACKEND = env('DJANGO_EMAIL_BACKEND',
default='django.core.mail.backends.console.EmailBackend')
class Local(Common): # CACHING
# ------------------------------------------------------------------------------
# DEBUG CACHES = {
DEBUG = values.BooleanValue(True) 'default': {
TEMPLATE_DEBUG = DEBUG 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
# END DEBUG 'LOCATION': ''
# INSTALLED_APPS
INSTALLED_APPS = Common.INSTALLED_APPS
# END INSTALLED_APPS
# Mail settings
EMAIL_HOST = 'localhost'
EMAIL_PORT = 1025
EMAIL_BACKEND = values.Value('django.core.mail.backends.console.EmailBackend')
# End mail settings
# django-debug-toolbar
MIDDLEWARE_CLASSES = Common.MIDDLEWARE_CLASSES + ('debug_toolbar.middleware.DebugToolbarMiddleware',)
INSTALLED_APPS += ('debug_toolbar', 'django_extensions',)
INTERNAL_IPS = ('127.0.0.1', '10.0.2.2',)
DEBUG_TOOLBAR_CONFIG = {
'DISABLE_PANELS': [
'debug_toolbar.panels.redirects.RedirectsPanel',
],
'SHOW_TEMPLATE_CONTEXT': True,
} }
# end django-debug-toolbar }
# Your local stuff: Below this line define 3rd party library settings # django-debug-toolbar
# ------------------------------------------------------------------------------
MIDDLEWARE_CLASSES += ('debug_toolbar.middleware.DebugToolbarMiddleware',)
INSTALLED_APPS += ('debug_toolbar', 'django_extensions',)
INTERNAL_IPS = ('127.0.0.1', '10.0.2.2',)
DEBUG_TOOLBAR_CONFIG = {
'DISABLE_PANELS': [
'debug_toolbar.panels.redirects.RedirectsPanel',
],
'SHOW_TEMPLATE_CONTEXT': True,
}
# Your local stuff: Below this line define 3rd party library settings

View File

@ -7,124 +7,114 @@ Production Configurations
- Use sendgrid to send emails - Use sendgrid to send emails
- Use MEMCACHIER on Heroku - Use MEMCACHIER on Heroku
''' '''
from configurations import values from __future__ import absolute_import, unicode_literals
from .common import Common
class Production(Common): from boto.s3.connection import OrdinaryCallingFormat
# This ensures that Django will be able to detect a secure connection from .common import *
# properly on Heroku.
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# INSTALLED_APPS # This ensures that Django will be able to detect a secure connection
INSTALLED_APPS = Common.INSTALLED_APPS # properly on Heroku.
# END INSTALLED_APPS SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# SECRET KEY # django-secure
SECRET_KEY = values.SecretValue() # ------------------------------------------------------------------------------
# END SECRET KEY INSTALLED_APPS += ("djangosecure", )
# django-secure MIDDLEWARE_CLASSES = (
INSTALLED_APPS += ("djangosecure", ) # Make sure djangosecure.middleware.SecurityMiddleware is listed first
'djangosecure.middleware.SecurityMiddleware',
) + MIDDLEWARE_CLASSES
# MIDDLEWARE CONFIGURATION # set this to 60 seconds and then to 518400 when you can prove it works
MIDDLEWARE_CLASSES = ( SECURE_HSTS_SECONDS = 60
# Make sure djangosecure.middleware.SecurityMiddleware is listed first SECURE_HSTS_INCLUDE_SUBDOMAINS = env.bool("DJANGO_SECURE_HSTS_INCLUDE_SUBDOMAINS", default=True)
'djangosecure.middleware.SecurityMiddleware', SECURE_FRAME_DENY = env.bool("DJANGO_SECURE_FRAME_DENY", default=True)
) SECURE_CONTENT_TYPE_NOSNIFF = env.bool("DJANGO_SECURE_CONTENT_TYPE_NOSNIFF", default=True)
SECURE_BROWSER_XSS_FILTER = True
SESSION_COOKIE_SECURE = False
SESSION_COOKIE_HTTPONLY = True
SECURE_SSL_REDIRECT = env.bool("DJANGO_SECURE_SSL_REDIRECT", default=True)
MIDDLEWARE_CLASSES += Common.MIDDLEWARE_CLASSES # SITE CONFIGURATION
# END MIDDLEWARE CONFIGURATION # ------------------------------------------------------------------------------
# Hosts/domain names that are valid for this site
# See https://docs.djangoproject.com/en/1.6/ref/settings/#allowed-hosts
ALLOWED_HOSTS = ["*"]
# END SITE CONFIGURATION
# set this to 60 seconds and then to 518400 when you can prove it works INSTALLED_APPS += ("gunicorn", )
SECURE_HSTS_SECONDS = 60
SECURE_HSTS_INCLUDE_SUBDOMAINS = values.BooleanValue(True)
SECURE_FRAME_DENY = values.BooleanValue(True)
SECURE_CONTENT_TYPE_NOSNIFF = values.BooleanValue(True)
SECURE_BROWSER_XSS_FILTER = values.BooleanValue(True)
SESSION_COOKIE_SECURE = values.BooleanValue(False)
SESSION_COOKIE_HTTPONLY = values.BooleanValue(True)
SECURE_SSL_REDIRECT = values.BooleanValue(True)
# end django-secure
# SITE CONFIGURATION # STORAGE CONFIGURATION
# Hosts/domain names that are valid for this site # ------------------------------------------------------------------------------
# See https://docs.djangoproject.com/en/1.6/ref/settings/#allowed-hosts # See: http://django-storages.readthedocs.org/en/latest/index.html
ALLOWED_HOSTS = ["*"] INSTALLED_APPS += (
# END SITE CONFIGURATION 'storages',
)
INSTALLED_APPS += ("gunicorn", ) STATICFILES_STORAGE = DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
# STORAGE CONFIGURATION AWS_ACCESS_KEY_ID = env("DJANGO_AWS_ACCESS_KEY_ID")
# See: http://django-storages.readthedocs.org/en/latest/index.html AWS_SECRET_ACCESS_KEY = env("DJANGO_AWS_SECRET_ACCESS_KEY")
INSTALLED_APPS += ( AWS_STORAGE_BUCKET_NAME = env("DJANGO_AWS_STORAGE_BUCKET_NAME")
'storages', AWS_AUTO_CREATE_BUCKET = True
) AWS_QUERYSTRING_AUTH = False
AWS_S3_CALLING_FORMAT = OrdinaryCallingFormat()
# See: http://django-storages.readthedocs.org/en/latest/backends/amazon-S3.html#settings # See: https://github.com/antonagestam/collectfast
STATICFILES_STORAGE = DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage' # For Django 1.7+, 'collectfast' should come before 'django.contrib.staticfiles'
AWS_PRELOAD_METADATA = True
INSTALLED_APPS = ('collectfast', ) + INSTALLED_APPS
# See: http://django-storages.readthedocs.org/en/latest/backends/amazon-S3.html#settings # AWS cache settings, don't change unless you know what you're doing:
AWS_ACCESS_KEY_ID = values.SecretValue() AWS_EXPIRY = 60 * 60 * 24 * 7
AWS_SECRET_ACCESS_KEY = values.SecretValue() AWS_HEADERS = {
AWS_STORAGE_BUCKET_NAME = values.SecretValue() 'Cache-Control': 'max-age=%d, s-maxage=%d, must-revalidate' % (
AWS_AUTO_CREATE_BUCKET = True AWS_EXPIRY, AWS_EXPIRY)
AWS_QUERYSTRING_AUTH = False }
# See: https://github.com/antonagestam/collectfast # See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url
# For Django 1.7+, 'collectfast' should come before 'django.contrib.staticfiles' STATIC_URL = 'https://s3.amazonaws.com/%s/' % AWS_STORAGE_BUCKET_NAME
AWS_PRELOAD_METADATA = True
INSTALLED_APPS = ('collectfast', ) + INSTALLED_APPS
# AWS cache settings, don't change unless you know what you're doing: # EMAIL
AWS_EXPIRY = 60 * 60 * 24 * 7 # ------------------------------------------------------------------------------
AWS_HEADERS = { DEFAULT_FROM_EMAIL = env('DJANGO_DEFAULT_FROM_EMAIL',
'Cache-Control': 'max-age=%d, s-maxage=%d, must-revalidate' % ( default='{{cookiecutter.project_name}} <noreply@{{cookiecutter.domain_name}}>')
AWS_EXPIRY, AWS_EXPIRY) EMAIL_HOST = env("DJANGO_EMAIL_HOST", default='smtp.sendgrid.com')
} EMAIL_HOST_PASSWORD = env("SENDGRID_PASSWORD")
# See: http://django-storages.readthedocs.org/en/latest/backends/amazon-S3.html EMAIL_HOST_USER = env('SENDGRID_USERNAME')
try: EMAIL_PORT = env.int("EMAIL_PORT", default=587)
from boto.s3.connection import OrdinaryCallingFormat EMAIL_SUBJECT_PREFIX = env("EMAIL_SUBJECT_PREFIX", default='[{{cookiecutter.project_name}}] ')
AWS_S3_CALLING_FORMAT = OrdinaryCallingFormat() EMAIL_USE_TLS = True
except ImportError: SERVER_EMAIL = EMAIL_HOST_USER
pass
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url # TEMPLATE CONFIGURATION
STATIC_URL = 'https://s3.amazonaws.com/%s/' % AWS_STORAGE_BUCKET_NAME # ------------------------------------------------------------------------------
# END STORAGE CONFIGURATION # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
TEMPLATE_LOADERS = (
('django.template.loaders.cached.Loader', (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)),
)
# EMAIL # DATABASE CONFIGURATION
DEFAULT_FROM_EMAIL = values.Value('{{cookiecutter.project_name}} <noreply@{{cookiecutter.domain_name}}>') # ------------------------------------------------------------------------------
EMAIL_HOST = values.Value('smtp.sendgrid.com') # Raises ImproperlyConfigured exception if DATABASE_URL not in os.environ
EMAIL_HOST_PASSWORD = values.SecretValue(environ_prefix="", environ_name="SENDGRID_PASSWORD") DATABASES['defalut'] = env.db("DATABASE_URL")
EMAIL_HOST_USER = values.SecretValue(environ_prefix="", environ_name="SENDGRID_USERNAME")
EMAIL_PORT = values.IntegerValue(587, environ_prefix="", environ_name="EMAIL_PORT")
EMAIL_SUBJECT_PREFIX = values.Value('[{{cookiecutter.project_name}}] ', environ_name="EMAIL_SUBJECT_PREFIX")
EMAIL_USE_TLS = True
SERVER_EMAIL = EMAIL_HOST_USER
# END EMAIL
# TEMPLATE CONFIGURATION # CACHING
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs # ------------------------------------------------------------------------------
TEMPLATE_LOADERS = ( try:
('django.template.loaders.cached.Loader', (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)),
)
# END TEMPLATE CONFIGURATION
# CACHING
# Only do this here because thanks to django-pylibmc-sasl and pylibmc # Only do this here because thanks to django-pylibmc-sasl and pylibmc
# memcacheify is painful to install on windows. # memcacheify is painful to install on windows.
try: # See: https://github.com/rdegges/django-heroku-memcacheify
# See: https://github.com/rdegges/django-heroku-memcacheify from memcacheify import memcacheify
from memcacheify import memcacheify CACHES = memcacheify()
CACHES = memcacheify() except ImportError:
except ImportError: CACHES = {
CACHES = values.CacheURLValue(default="memcached://127.0.0.1:11211") 'default': env.cache_url("DJANGO_CACHE_URL", default="memcache://127.0.0.1:11211"),
# END CACHING }
# Your production stuff: Below this line define 3rd party library settings # Your production stuff: Below this line define 3rd party library settings

View File

@ -3,9 +3,8 @@ import os
import sys import sys
if __name__ == "__main__": if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.local")
os.environ.setdefault("DJANGO_CONFIGURATION", "Local")
from configurations.management import execute_from_command_line from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv) execute_from_command_line(sys.argv)

View File

@ -19,13 +19,12 @@ import os
# if running multiple sites in the same mod_wsgi process. To fix this, use # if running multiple sites in the same mod_wsgi process. To fix this, use
# mod_wsgi daemon mode with each site in its own daemon process, or use # mod_wsgi daemon mode with each site in its own daemon process, or use
# os.environ["DJANGO_SETTINGS_MODULE"] = "{{ repo_name }}.settings" # os.environ["DJANGO_SETTINGS_MODULE"] = "{{ repo_name }}.settings"
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.production")
os.environ.setdefault("DJANGO_CONFIGURATION", "Production")
# This application object is used by any WSGI server configured to use this # This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION # file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here. # setting points here.
from configurations.wsgi import get_wsgi_application # noqa from django.core.wsgi import get_wsgi_application # noqa
application = get_wsgi_application() application = get_wsgi_application()
# Apply WSGI middleware here. # Apply WSGI middleware here.