Changeset - 5723046a01dc
[Not reviewed]
1 1 6
Branko Majic (branko) - 10 years ago 2015-09-05 17:39:22
branko@majic.rs
MDT-1: Ignore the credentials file. Restructured the settings to support multiple environments, defaulting to development environment execution.
7 files changed with 233 insertions and 50 deletions:
0 comments (0 inline, 0 general)
.gitignore
Show inline comments
 
@@ -8,3 +8,6 @@ docs/_build
 

	
 
# Ignore local tmp directory.
 
tmp/
 

	
 
# Ignore the file with credentials.
 
credentials.py
 
\ No newline at end of file
project/project_name/settings/__init__.py
Show inline comments
 
new file 100644
 
# Run the development site by default.
 
from .development import *
project/project_name/settings/base.py
Show inline comments
 
file renamed from project/project_name/settings.py to project/project_name/settings/base.py
 
"""
 
Django settings for {{ project_name }} project.
 
# Common Django settings for all environments for project {{ project_name }}.
 

	
 
Generated by 'django-admin startproject' using Django {{ django_version }}.
 
#
 
# This file contains common settings shared amongst all environments of a
 
# project. Do not put any environment-specific settings here.
 
#
 

	
 
For more information on this file, see
 
https://docs.djangoproject.com/en/{{ docs_version }}/topics/settings/
 

	
 
For the full list of settings and their values, see
 
https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/
 
"""
 

	
 
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
 
import os
 

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

	
 

	
 
# Quick-start development settings - unsuitable for production
 
# See https://docs.djangoproject.com/en/{{ docs_version }}/howto/deployment/checklist/
 

	
 
# SECURITY WARNING: keep the secret key used in production secret!
 
SECRET_KEY = '{{ secret_key }}'
 

	
 
# SECURITY WARNING: don't run with debug turned on in production!
 
DEBUG = True
 

	
 
ALLOWED_HOSTS = []
 

	
 

	
 
# Application definition
 
# Determine the root and assets project directories.
 
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 
ASSETS_ROOT = os.path.normpath(os.path.join(PROJECT_ROOT, "assets"))
 

	
 
# Applications installed in the project.
 
INSTALLED_APPS = (
 
    'django.contrib.admin',
 
    'django.contrib.auth',
 
@@ -39,6 +21,7 @@ INSTALLED_APPS = (
 
    'django.contrib.staticfiles',
 
)
 

	
 
# Middleware classes enabled in the project.
 
MIDDLEWARE_CLASSES = (
 
    'django.contrib.sessions.middleware.SessionMiddleware',
 
    'django.middleware.common.CommonMiddleware',
 
@@ -50,8 +33,10 @@ MIDDLEWARE_CLASSES = (
 
    'django.middleware.security.SecurityMiddleware',
 
)
 

	
 
# URL configuration for the project.
 
ROOT_URLCONF = '{{ project_name }}.urls'
 

	
 
# Templates configuration for the project.
 
TEMPLATES = [
 
    {
 
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
 
@@ -68,35 +53,29 @@ TEMPLATES = [
 
    },
 
]
 

	
 
# Python dotted path to the WSGI application used by Django's runserver command.
 
WSGI_APPLICATION = '{{ project_name }}.wsgi.application'
 

	
 

	
 
# Database
 
# https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/#databases
 

	
 
DATABASES = {
 
    'default': {
 
        'ENGINE': 'django.db.backends.sqlite3',
 
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
 
    }
 
}
 

	
 

	
 
# Internationalization
 
# https://docs.djangoproject.com/en/{{ docs_version }}/topics/i18n/
 

	
 
# Language, internationalisation, and time configuration
 
LANGUAGE_CODE = 'en-us'
 

	
 
TIME_ZONE = 'UTC'
 

	
 
USE_I18N = True
 

	
 
USE_L10N = True
 

	
 
USE_TZ = True
 

	
 
# URLs for serving the static and media files.
 
STATIC_URL = '/static/'
 
MEDIA_URL = '/media/'
 

	
 
# Static files (CSS, JavaScript, Images)
 
# https://docs.djangoproject.com/en/{{ docs_version }}/howto/static-files/
 
# Absolute filesystem path to the directory that will hold user-uploaded
 
# files. Calculated based on assets root.
 
MEDIA_ROOT = os.path.normpath(os.path.join(ASSETS_ROOT, "media"))
 

	
 
STATIC_URL = '/static/'
 
# Absolute path to the directory static files should be collected to. Calculated
 
# based on project assets root.
 
STATIC_ROOT = os.path.normpath(os.path.join(ASSETS_ROOT, "static"))
 

	
 
# Additional locations for static files. Useful for project-wide overrides of
 
# default static files.
 
STATICFILES_DIRS = (
 
    os.path.normpath(os.path.join(PROJECT_ROOT, "static")),
 
)
project/project_name/settings/development.py
Show inline comments
 
new file 100644
 
# Development environment settings for project {{ project_name }}.
 

	
 
#
 
# This configuration file is used to define settings for the development
 
# environment.
 
#
 

	
 
# Import the exception for signaling invalid configuration. No other
 
# Django-specific definitions should be imported here.
 
from django.core.exceptions import ImproperlyConfigured
 

	
 
# Import the base settings.
 
from .base import *
 

	
 
# Import the credentials.
 
try:
 
    from .credentials import DATABASE_PASSWORDS
 
except ImportError:
 
    raise ImproperlyConfigured("Please configure the DATABASE_PASSWORDS in credentials.py.")
 

	
 
try:
 
    from .credentials import SECRET_KEY
 
except ImportError:
 
    raise ImproperlyConfigured("Please configure the SECRET_KEY in credentials.py.")
 

	
 
# Debugging is useful for development.
 
DEBUG = True
 
for template_config in TEMPLATES:
 
    template_config['OPTIONS']['debug']=True
 

	
 
# Site administrators and managers.
 
ADMINS = (
 
    # ('Your Name', 'your_email@example.com'),
 
)
 
MANAGERS = ADMINS
 

	
 
# Database configuration. sqlite3 is used for development for convenience. See
 
# testing/production environment settings and official Django documentation if a
 
# proper database should be used.
 
DATABASES = {
 
    'default': {
 
        'ENGINE': 'django.db.backends.sqlite3',
 
        'NAME': 'development.sqlite3',
 
    }
 
}
 

	
 
# Hosts that are valid for accessing this site. For development, empty list is
 
# sufficient.
 
ALLOWED_HOSTS = []
 

	
 
# Local time zone for development environment.
 
TIME_ZONE = 'Europe/Stockholm'
project/project_name/settings/production.py
Show inline comments
 
new file 100644
 
# Production environment settings for project {{ project_name }}.
 

	
 
#
 
# This configuration file is used to define settins for the production
 
# environment.
 
#
 

	
 
# Import the exception for signaling invalid configuration. No other
 
# Django-specific definitions should be imported here.
 
from django.core.exceptions import ImproperlyConfigured
 

	
 
# Import the base settings.
 
from .base import *
 

	
 
# Import the credentials.
 
try:
 
    from .credentials import DATABASE_PASSWORDS
 
except ImportError:
 
    raise ImproperlyConfigured("Please configure the DATABASE_PASSWORDS in credentials.py.")
 

	
 
try:
 
    from .credentials import SECRET_KEY
 
except ImportError:
 
    raise ImproperlyConfigured("Please configure the SECRET_KEY in credentials.py.")
 

	
 
# Debugging should normally be disabled in production environment, but may be
 
# necessary in case of serious issues that cannot be reproduced in test
 
# environment.
 
DEBUG = False
 
for template_config in TEMPLATES:
 
    template_config['OPTIONS']['debug']=False
 

	
 
# Site administrators and managers.
 
ADMINS = (
 
    # ('Your Name', 'your_email@example.com'),
 
)
 
MANAGERS = ADMINS
 

	
 
# Database configuration. Avoid using sqlite3 for production environments.
 
DATABASES = {
 
    'default': {
 
        # Database engine to use. Set it to 'postgresql_psycopg2', 'mysql',
 
        # 'sqlite3' or 'oracle' (keep the django.db.backends prefix).
 
        'ENGINE': 'django.db.backends.',
 
        # Name of database, or path to database file if using sqlite3.
 
        'NAME': '',
 
        # Username for logging-in into database server. Not required for
 
        # sqlite3.
 
        'USER': '',
 
        # Password for logging-in into database server. Should be read from
 
        # credentials.py.
 
        'PASSWORD': DATABASE_PASSWORDS['default'],
 
        # IP or resolvable name of the database server.
 
        'HOST': '127.0.0.1',
 
        # Port on which the database server accepts incoming connections. If not
 
        # specified, engine-specific port is set automatically.
 
        'PORT': '',
 
    }
 
}
 

	
 
# Hosts that are valid for accessing this site. Must be set for production
 
# environment.
 
ALLOWED_HOSTS = []
 

	
 
# Local time zone for production environment.
 
TIME_ZONE = 'Europe/Stockholm'
project/project_name/settings/sample_credentials.py
Show inline comments
 
new file 100644
 
# Sample credentials.py file.
 

	
 
#
 
# This file contains a sample of how the site-specific credentials.py file
 
# should look like.
 
#
 

	
 
# Secret key should be unique and kept secret. It should also be sufficiently
 
# complex to prevent brute-forcing.
 
SECRET_KEY = ''
 

	
 
# Passwords for one or more databases used by the site.
 
DATABASE_PASSWORDS = {
 
    'default': '',
 
    }
project/project_name/settings/testing.py
Show inline comments
 
new file 100644
 
# Testing environment settings for project {{ project_name }}.
 

	
 
#
 
# This configuration file is used to define settings for the testing
 
# environment.
 
#
 

	
 
# Import the exception for signaling invalid configuration. No other
 
# Django-specific definitions should be imported here.
 
from django.core.exceptions import ImproperlyConfigured
 

	
 
# Import the base settings.
 
from .base import *
 

	
 
# Import the credentials.
 
try:
 
    from .credentials import DATABASE_PASSWORDS
 
except ImportError:
 
    raise ImproperlyConfigured("Please configure the DATABASE_PASSWORDS in credentials.py.")
 

	
 
try:
 
    from .credentials import SECRET_KEY
 
except ImportError:
 
    raise ImproperlyConfigured("Please configure the SECRET_KEY in credentials.py.")
 

	
 
# Debugging should normally be disabled in test environment, but may be
 
# necessary in some cases.
 
DEBUG = False
 
for template_config in TEMPLATES:
 
    template_config['OPTIONS']['debug']=False
 

	
 
# Site administrators and managers.
 
ADMINS = (
 
    # ('Your Name', 'your_email@example.com'),
 
)
 
MANAGERS = ADMINS
 

	
 
# Database configuration. Testing environment should use database configuration
 
# as similar to production as possible.
 
DATABASES = {
 
    'default': {
 
        # Database engine to use. Set it to 'postgresql_psycopg2', 'mysql',
 
        # 'sqlite3' or 'oracle' (keep the django.db.backends prefix).
 
        'ENGINE': 'django.db.backends.',
 
        # Name of database, or path to database file if using sqlite3.
 
        'NAME': '',
 
        # Username for logging-in into database server. Not required for
 
        # sqlite3.
 
        'USER': '',
 
        # Password for logging-in into database server. Should be read from
 
        # credentials.py.
 
        'PASSWORD': DATABASE_PASSWORDS['default'],
 
        # IP or resolvable name of the database server.
 
        'HOST': '127.0.0.1',
 
        # Port on which the database server accepts incoming connections. If not
 
        # specified, engine-specific port is set automatically.
 
        'PORT': '',
 
    }
 
}
 

	
 
# Hosts that are valid for accessing this site. Must be set for testing
 
# environment.
 
ALLOWED_HOSTS = []
 

	
 
# Local time zone for testing environment.
 
TIME_ZONE = 'Europe/Stockholm'
0 comments (0 inline, 0 general)