changeset 34:903260593491

Reworking settings.py to a settings package.
author Brian Neal <bgneal@gmail.com>
date Tue, 29 Nov 2011 03:14:25 +0000
parents 7d8015de651a
children 21172e9be136
files mysite/apache/madeira.wsgi mysite/settings.py mysite/settings/__init__.py mysite/settings/base.py mysite/settings/local.py mysite/settings/production.py mysite/templates/band/gigs.html mysite/urls.py
diffstat 7 files changed, 301 insertions(+), 179 deletions(-) [+]
line wrap: on
line diff
--- a/mysite/apache/madeira.wsgi	Wed Nov 02 01:30:46 2011 +0000
+++ b/mysite/apache/madeira.wsgi	Tue Nov 29 03:14:25 2011 +0000
@@ -30,7 +30,7 @@
 
 
 if not OFFLINE:
-    os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
+    os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings.production'
     import django.core.handlers.wsgi
     application = django.core.handlers.wsgi.WSGIHandler()
 else:
--- a/mysite/settings.py	Wed Nov 02 01:30:46 2011 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,176 +0,0 @@
-# Django settings for madeira project.
-
-import os
-import platform
-import local_settings
-project_path = os.path.abspath(os.path.split(__file__)[0])
-
-DEBUG = local_settings.DEBUG
-TEMPLATE_DEBUG = DEBUG
-
-ADMINS = (
-    ('Brian Neal', 'admin@surfguitar101.com'),
-)
-
-MANAGERS = ADMINS
-
-DATABASES = local_settings.DATABASES
-
-INTERNAL_IPS = local_settings.INTERNAL_IPS
-
-# 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.
-# If running in a Windows environment this must be set to the same as your
-# system time zone.
-TIME_ZONE = local_settings.TIME_ZONE
-
-# Language code for this installation. All choices can be found here:
-# http://www.i18nguy.com/unicode/language-identifiers.html
-LANGUAGE_CODE = 'en-us'
-
-SITE_ID = local_settings.SITE_ID
-
-# If you set this to False, Django will make some optimizations so as not
-# to load the internationalization machinery.
-USE_I18N = False
-
-# Absolute path to the directory that holds media.
-# Example: "/home/media/media.lawrence.com/"
-MEDIA_ROOT = local_settings.MEDIA_ROOT
-
-# URL that handles the media served from MEDIA_ROOT. Make sure to use a
-# trailing slash if there is a path component (optional in other cases).
-# Examples: "http://media.lawrence.com", "http://example.com/media/"
-MEDIA_URL = local_settings.MEDIA_URL
-
-# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
-# trailing slash.
-# Examples: "http://foo.com/media/", "/media/".
-ADMIN_MEDIA_PREFIX = local_settings.ADMIN_MEDIA_PREFIX
-
-# Staticfiles settings:
-STATICFILES_DIRS = local_settings.STATICFILES_DIRS
-STATIC_ROOT = local_settings.STATIC_ROOT
-STATIC_URL = local_settings.STATIC_URL
-
-# Make this unique, and don't share it with anybody.
-SECRET_KEY = local_settings.SECRET_KEY
-
-if DEBUG:
-    TEMPLATE_LOADERS = (
-        'django.template.loaders.filesystem.Loader',
-        'django.template.loaders.app_directories.Loader',
-    )
-else:
-    TEMPLATE_LOADERS = (
-        ('django.template.loaders.cached.Loader', (
-            'django.template.loaders.filesystem.Loader',
-            'django.template.loaders.app_directories.Loader',
-        )),
-    )
-
-if DEBUG:
-    MIDDLEWARE_CLASSES = (
-        'django.middleware.common.CommonMiddleware',
-        'django.middleware.csrf.CsrfViewMiddleware',
-        'django.contrib.sessions.middleware.SessionMiddleware',
-        'django.contrib.messages.middleware.MessageMiddleware',
-        'debug_toolbar.middleware.DebugToolbarMiddleware',
-        'django.contrib.auth.middleware.AuthenticationMiddleware',
-        'django.middleware.doc.XViewMiddleware',
-        'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
-    )
-else:
-    MIDDLEWARE_CLASSES = (
-        'django.middleware.common.CommonMiddleware',
-        'django.middleware.csrf.CsrfViewMiddleware',
-        'django.contrib.sessions.middleware.SessionMiddleware',
-        'django.contrib.messages.middleware.MessageMiddleware',
-        'django.contrib.auth.middleware.AuthenticationMiddleware',
-        'django.middleware.doc.XViewMiddleware',
-        'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
-    )
-
-#######################################################################
-# Caching
-#######################################################################
-if local_settings.USE_CACHE:
-    CACHES = local_settings.CACHES
-    CACHE_MIDDLEWARE_ANONYMOUS_ONLY = local_settings.CACHE_MIDDLEWARE_ANONYMOUS_ONLY
-    CACHE_MIDDLEWARE_SECONDS = local_settings.CACHE_MIDDLEWARE_SECONDS
-    CACHE_MIDDLEWARE_KEY_PREFIX = local_settings.CACHE_MIDDLEWARE_KEY_PREFIX
-
-ROOT_URLCONF = 'mysite.urls'
-
-# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
-# Always use forward slashes, even on Windows.
-# Don't forget to use absolute paths, not relative paths.
-TEMPLATE_DIRS = (
-    os.path.join(project_path, 'templates'),
-    os.path.join(project_path, 'templates', 'band'),
-    os.path.join(project_path, 'photologue', 'templates'),
-)
-
-TEMPLATE_CONTEXT_PROCESSORS = (
-    "django.contrib.auth.context_processors.auth",
-    "django.core.context_processors.debug",
-    "django.core.context_processors.request",
-    "django.core.context_processors.media",
-    "django.core.context_processors.static",
-    "django.contrib.messages.context_processors.messages",
-)
-
-INSTALLED_APPS = [
-    'django.contrib.admin',
-    'django.contrib.admindocs',
-    'django.contrib.auth',
-    'django.contrib.contenttypes',
-    'django.contrib.flatpages',
-    'django.contrib.markup',
-    'django.contrib.messages',
-    'django.contrib.sessions',
-    'django.contrib.sites',
-    'django.contrib.staticfiles',
-    'mysite.band',
-    'mysite.photologue',
-]
-if DEBUG:
-    INSTALLED_APPS.append('debug_toolbar')
-
-#######################################################################
-# Messages
-#######################################################################
-MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage'
-
-#######################################################################
-# Email
-#######################################################################
-EMAIL_HOST = local_settings.EMAIL_HOST
-EMAIL_PORT = local_settings.EMAIL_PORT
-
-#######################################################################
-# Sessions
-#######################################################################
-SESSION_ENGINE = "django.contrib.sessions.backends.cached_db"
-SESSION_COOKIE_AGE = 2 * 7 * 24 * 60 * 60   # 2 weeks in seconds
-SESSION_COOKIE_DOMAIN = None
-SESSION_COOKIE_NAME = 'madeira_sessionid'
-SESSION_COOKIE_PATH = '/'
-SESSION_COOKIE_SECURE = False
-SESSION_EXPIRE_AT_BROWSER_CLOSE = False
-SESSION_SAVE_EVERY_REQUEST = False
-
-#######################################################################
-# Configure Logging
-#######################################################################
-
-LOGGING = local_settings.LOGGING
-
-#######################################################################
-# Django Debug Toolbar 
-#######################################################################
-
-if DEBUG:
-    DEBUG_TOOLBAR_CONFIG = local_settings.DEBUG_TOOLBAR_CONFIG
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mysite/settings/base.py	Tue Nov 29 03:14:25 2011 +0000
@@ -0,0 +1,133 @@
+# Base Django settings for madeira project.
+
+import os
+import django.utils.simplejson as json
+
+PROJECT_PATH = os.path.abspath(os.path.join(os.path.split(__file__)[0], '..'))
+
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+
+ADMINS = [
+    ('Brian Neal', 'admin@surfguitar101.com'),
+]
+
+MANAGERS = ADMINS
+
+INTERNAL_IPS = ['127.0.0.1']
+
+# 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.
+# If running in a Windows environment this must be set to the same as your
+# system time zone.
+TIME_ZONE = 'America/Chicago'
+
+# Language code for this installation. All choices can be found here:
+# http://www.i18nguy.com/unicode/language-identifiers.html
+LANGUAGE_CODE = 'en-us'
+
+SITE_ID = 1
+
+# If you set this to False, Django will make some optimizations so as not
+# to load the internationalization machinery.
+USE_I18N = False
+
+# Absolute path to the directory that holds media.
+# Example: "/home/media/media.lawrence.com/"
+MEDIA_ROOT = os.path.abspath(os.path.join(PROJECT_PATH, '..', 'media'))
+
+# URL that handles the media served from MEDIA_ROOT. Make sure to use a
+# trailing slash if there is a path component (optional in other cases).
+# Examples: "http://media.lawrence.com", "http://example.com/media/"
+MEDIA_URL = '/media/'
+
+# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
+# trailing slash.
+# Examples: "http://foo.com/media/", "/media/".
+ADMIN_MEDIA_PREFIX = '/static/admin/'
+
+# Staticfiles settings:
+STATICFILES_DIRS = [
+    os.path.abspath(os.path.join(PROJECT_PATH, '..', 'static')),
+]
+STATIC_ROOT = '/tmp/test_madeira_static_root'
+STATIC_URL = '/static/'
+
+# Make this unique, and don't share it with anybody.
+SECRETS = json.load(open(os.path.join(PROJECT_PATH, 'settings', 'secrets.json')))
+SECRET_KEY = SECRETS['SECRET_KEY']
+
+TEMPLATE_LOADERS = [
+    'django.template.loaders.filesystem.Loader',
+    'django.template.loaders.app_directories.Loader',
+#     'django.template.loaders.eggs.Loader',
+]
+
+MIDDLEWARE_CLASSES = [
+    'django.middleware.common.CommonMiddleware',
+    'django.middleware.csrf.CsrfViewMiddleware',
+    'django.contrib.sessions.middleware.SessionMiddleware',
+    'django.contrib.messages.middleware.MessageMiddleware',
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
+    'django.middleware.doc.XViewMiddleware',
+    'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
+]
+
+ROOT_URLCONF = 'mysite.urls'
+
+# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
+# Always use forward slashes, even on Windows.
+# Don't forget to use absolute paths, not relative paths.
+TEMPLATE_DIRS = [
+    os.path.join(PROJECT_PATH, 'templates'),
+    os.path.join(PROJECT_PATH, 'templates', 'band'),
+    os.path.join(PROJECT_PATH, 'photologue', 'templates'),
+]
+
+TEMPLATE_CONTEXT_PROCESSORS = [
+    "django.contrib.auth.context_processors.auth",
+    "django.core.context_processors.debug",
+    "django.core.context_processors.request",
+    "django.core.context_processors.media",
+    "django.core.context_processors.static",
+    "django.contrib.messages.context_processors.messages",
+]
+
+INSTALLED_APPS = [
+    'django.contrib.admin',
+    'django.contrib.admindocs',
+    'django.contrib.auth',
+    'django.contrib.contenttypes',
+    'django.contrib.flatpages',
+    'django.contrib.markup',
+    'django.contrib.messages',
+    'django.contrib.sessions',
+    'django.contrib.sites',
+    'django.contrib.staticfiles',
+    'mysite.band',
+    'mysite.photologue',
+]
+
+#######################################################################
+# Messages
+#######################################################################
+MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage'
+
+#######################################################################
+# Email
+#######################################################################
+EMAIL_HOST = 'localhost'
+EMAIL_PORT = 1025
+
+#######################################################################
+# Sessions
+#######################################################################
+SESSION_ENGINE = "django.contrib.sessions.backends.cached_db"
+SESSION_COOKIE_AGE = 2 * 7 * 24 * 60 * 60   # 2 weeks in seconds
+SESSION_COOKIE_DOMAIN = None
+SESSION_COOKIE_NAME = 'madeira_sessionid'
+SESSION_COOKIE_PATH = '/'
+SESSION_COOKIE_SECURE = False
+SESSION_EXPIRE_AT_BROWSER_CLOSE = False
+SESSION_SAVE_EVERY_REQUEST = False
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mysite/settings/local.py	Tue Nov 29 03:14:25 2011 +0000
@@ -0,0 +1,77 @@
+"""
+Local Django settings for The Madeira site.
+The contents of this file will vary depending on the local installation.
+
+"""
+from settings.base import *
+
+DATABASES = {
+    'default': {
+        'ENGINE': 'django.db.backends.mysql',
+        'NAME': 'madeira_django1_3',
+        'USER': SECRETS['DB_USER'],
+        'PASSWORD': SECRETS['DB_PASSWORD'],
+    },
+}
+
+# Django Debug Toolbar support
+if DEBUG:
+    try:
+        import debug_toolbar
+    except ImportError:
+        pass
+    else:
+        i = MIDDLEWARE_CLASSES.index('django.middleware.common.CommonMiddleware')
+        MIDDLEWARE_CLASSES.insert(i + 1,
+                'debug_toolbar.middleware.DebugToolbarMiddleware')
+        INSTALLED_APPS.append('debug_toolbar')
+        DEBUG_TOOLBAR_CONFIG = {
+            'INTERCEPT_REDIRECTS': True,
+        }
+
+# Logging configuration
+
+LOGGING = {
+    'version': 1,
+    'disable_existing_loggers': True,
+    'formatters': {
+        'verbose': {
+            'format': '%(asctime)s %(levelname)s %(module)s %(process)d %(thread)d %(message)s'
+        },
+        'simple': {
+            'format': '%(asctime)s %(levelname)s %(message)s'
+        },
+    },
+    'handlers': {
+        'console': {
+            'class': 'logging.StreamHandler',
+            'level': 'DEBUG',
+            'formatter': 'simple',
+        },
+        'file': {
+            'class': 'logging.handlers.RotatingFileHandler',
+            'level': 'DEBUG',
+            'formatter': 'simple',
+            'filename': os.path.join(PROJECT_PATH, 'logs', 'madeira.log'),
+            'mode': 'a',
+            'maxBytes': 100 * 1024,
+            'backupCount': 10,
+        },
+        'mail_admins': {
+            'class': 'django.utils.log.AdminEmailHandler',
+            'level': 'ERROR',
+            'formatter': 'simple',
+        },
+    },
+    'loggers': {
+        'django':{
+            'level': 'WARNING',
+            'propagate': False,
+            'handlers': ['file'],
+        },
+    },
+    'root': {
+        'level': 'DEBUG',
+        'handlers': ['file'],
+    },
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mysite/settings/production.py	Tue Nov 29 03:14:25 2011 +0000
@@ -0,0 +1,88 @@
+# Django production settings for the madeira project.
+
+from settings.base import *
+
+DEBUG = False
+TEMPLATE_DEBUG = DEBUG
+
+DATABASES = {
+    'default': {
+        'ENGINE': 'django.db.backends.mysql',
+        'NAME': 'madeira_django',
+        'USER': SECRETS['DB_USER'],
+        'PASSWORD': SECRETS['DB_PASSWORD'],
+    },
+}
+
+STATIC_ROOT = os.path.abspath(os.path.join(PROJECT_PATH, '..', 'static_serve'))
+
+TEMPLATE_LOADERS = [
+    ('django.template.loaders.cached.Loader', (
+        'django.template.loaders.filesystem.Loader',
+        'django.template.loaders.app_directories.Loader',
+    )),
+]
+
+CACHES = {
+    'default': {
+        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
+        'LOCATION': '127.0.0.1:11211',
+        'TIMEOUT': 600,
+    },
+}
+CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True
+CACHE_MIDDLEWARE_SECONDS = 600
+CACHE_MIDDLEWARE_KEY_PREFIX = ''
+
+EMAIL_HOST = 'localhost'
+EMAIL_PORT = 25
+
+LOGGING = {
+    'version': 1,
+    'disable_existing_loggers': True,
+    'formatters': {
+        'verbose': {
+            'format': '%(asctime)s %(levelname)s %(module)s %(process)d %(thread)d %(message)s'
+        },
+        'simple': {
+            'format': '%(asctime)s %(levelname)s %(message)s'
+        },
+    },
+    'handlers': {
+        'console': {
+            'class': 'logging.StreamHandler',
+            'level': 'DEBUG',
+            'formatter': 'simple',
+        },
+        'file': {
+            'class': 'logging.handlers.RotatingFileHandler',
+            'level': 'DEBUG',
+            'formatter': 'simple',
+            'filename': os.path.join(project_path, 'logs', 'madeira.log'),
+            'mode': 'a',
+            'maxBytes': 100 * 1024,
+            'backupCount': 10,
+        },
+        'mail_admins': {
+            'class': 'django.utils.log.AdminEmailHandler',
+            'level': 'ERROR',
+            'formatter': 'simple',
+        },
+    },
+    'loggers': {
+        'django':{
+            'level': 'WARNING',
+            'propagate': False,
+            'handlers': ['file'],
+        },
+        'django.request':{
+            'level': 'ERROR',
+            'propagate': True,
+            'handlers': ['mail_admins'],
+        },
+    },
+    'root': {
+        'level': 'INFO',
+        'handlers': ['file'],
+    },
+}
--- a/mysite/templates/band/gigs.html	Wed Nov 02 01:30:46 2011 +0000
+++ b/mysite/templates/band/gigs.html	Tue Nov 29 03:14:25 2011 +0000
@@ -103,7 +103,7 @@
    {% endfor %}
    </div>
    <div clear="all"></div>
-   <center><p>To see all our flyers in full size, check out our <a href="{% url 'band.views.flyers' %}">show flyer gallery</a>.</p></center>
+   <center><p>To see all our flyers in full size, check out our <a href="{% url 'mysite.band.views.flyers' %}">show flyer gallery</a>.</p></center>
 </div>
 {% endif %}
 
--- a/mysite/urls.py	Wed Nov 02 01:30:46 2011 +0000
+++ b/mysite/urls.py	Tue Nov 29 03:14:25 2011 +0000
@@ -1,6 +1,6 @@
 from django.conf.urls.defaults import *
 from django.contrib import admin
-from mysite import settings
+from django.conf import settings
 
 admin.autodiscover()