Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactor settings to separate docs from www better.

  • Loading branch information...
commit e0ef4f5eb06deccb82db60aa725d6b5f9458efb5 1 parent 7b19c8d
@aaugustin aaugustin authored
View
75 django_docs/settings.py
@@ -1,42 +1,79 @@
-from django_www.settings import *
+# Settings for docs.djangoproject.com
+
+from django_www.common_settings import *
+
+
+### Django settings
-PREPEND_WWW = False
-TEMPLATE_CONTEXT_PROCESSORS += ["django.core.context_processors.request"]
-ROOT_URLCONF = 'django_docs.urls'
CACHE_MIDDLEWARE_KEY_PREFIX = 'djangodocs'
-# Override INSTALLED_APPS so that we only have a few things running on docs.
-# Keep around debug_toolbar and raven if the parent settings module installed
-# them.
-_new_apps = [
+INSTALLED_APPS = [
'django.contrib.staticfiles',
- 'docs',
+
+ 'djangosecure',
'haystack',
+
+ 'docs',
]
-if 'debug_toolbar' in INSTALLED_APPS:
- _new_apps.append('debug_toolbar')
-if 'raven.contrib.django' in INSTALLED_APPS:
- _new_apps.append('raven.contrib.django')
-INSTALLED_APPS = _new_apps
MIDDLEWARE_CLASSES = [
+ 'django.middleware.cache.UpdateCacheMiddleware',
+ 'djangosecure.middleware.SecurityMiddleware',
'django.middleware.common.CommonMiddleware',
+ 'django.middleware.cache.FetchFromCacheMiddleware'
]
-if PRODUCTION:
- MIDDLEWARE_CLASSES.insert(0, 'django.middleware.cache.UpdateCacheMiddleware')
- MIDDLEWARE_CLASSES.append('django.middleware.cache.FetchFromCacheMiddleware')
-# Where to store the build Sphinx docs.
+TEMPLATE_CONTEXT_PROCESSORS = [
+ 'django.contrib.auth.context_processors.auth',
+ 'django.core.context_processors.debug',
+ 'django.core.context_processors.i18n',
+ 'django.core.context_processors.static',
+ 'django.contrib.messages.context_processors.messages',
+ 'docs.context_processors.recent_release',
+ 'django.core.context_processors.request',
+]
+
+ROOT_URLCONF = 'django_docs.urls'
+
+SITE_ID = 2
+
+
+### Docs settings
+
if PRODUCTION:
DOCS_BUILD_ROOT = BASE.parent.child('docbuilds')
else:
DOCS_BUILD_ROOT = '/tmp/djangodocs'
-# Haystack settings
+
+### Haystack settings
+
HAYSTACK_SITECONF = 'docs.search_sites'
+
if PRODUCTION:
HAYSTACK_SEARCH_ENGINE = 'xapian'
HAYSTACK_XAPIAN_PATH = BASE.parent.child('djangodocs.index')
else:
HAYSTACK_SEARCH_ENGINE = 'whoosh'
HAYSTACK_WHOOSH_PATH = '/tmp/djangodocs.index'
+
+
+### Enable optional components
+
+if DEBUG:
+ try:
+ import debug_toolbar
+ except ImportError:
+ pass
+ else:
+ INSTALLED_APPS.append('debug_toolbar')
+ INTERNAL_IPS = ['127.0.0.1']
+ MIDDLEWARE_CLASSES.insert(
+ MIDDLEWARE_CLASSES.index('django.middleware.common.CommonMiddleware') + 1,
+ 'debug_toolbar.middleware.DebugToolbarMiddleware')
+
+# Log errors to Sentry instead of email, if available.
+if 'sentry_dsn' in SECRETS:
+ INSTALLED_APPS.append('raven.contrib.django')
+ SENTRY_DSN = SECRETS['sentry_dsn']
+ LOGGING["loggers"]["django.request"]["handlers"].remove("mail_admins")
View
142 django_www/common_settings.py
@@ -0,0 +1,142 @@
+# Settings common to www.djangoproject.com and docs.djangoproject.com
+
+import json
+import os
+import platform
+
+from unipath import FSPath as Path
+
+
+### Utilities
+
+# The full path to the repository root.
+BASE = Path(__file__).absolute().ancestor(2)
+
+# Far too clever trick to know if we're running on the deployment server.
+PRODUCTION = ('DJANGOPROJECT_DEBUG' not in os.environ) and ("djangoproject" in platform.node())
+
+# It's a secret to everybody
+with open(BASE.parent.child('secrets.json')) as handle:
+ SECRETS = json.load(handle)
+
+
+### Django settings
+
+ADMINS = (
+ ('Adrian Holovaty', 'holovaty@gmail.com'),
+ ('Jacob Kaplan-Moss', 'jacob@jacobian.org'),
+)
+
+CACHES = {
+ 'default': {
+ 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
+ 'LOCATION': '127.0.0.1:11211',
+ } if PRODUCTION else {
+ 'BACKEND': 'django.core.cache.backends.dummy.DummyCache'
+ },
+}
+
+CACHE_MIDDLEWARE_SECONDS = 60 * 5 # 5 minutes
+
+CSRF_COOKIE_SECURE = PRODUCTION
+
+CSRF_COOKIE_HTTPONLY = True
+
+DATABASES = {
+ 'default': {
+ 'ENGINE': 'django.db.backends.postgresql_psycopg2',
+ 'NAME': 'djangoproject',
+ 'USER': 'djangoproject'
+ },
+}
+
+DEBUG = not PRODUCTION
+
+DEFAULT_FROM_EMAIL = "noreply@djangoproject.com"
+
+if not PRODUCTION:
+ EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
+
+LOGGING = {
+ "version": 1,
+ "disable_existing_loggers": True,
+ "formatters": {
+ "simple": {"format": "[%(name)s] %(levelname)s: %(message)s"},
+ "full": {"format": "%(asctime)s [%(name)s] %(levelname)s: %(message)s"},
+ },
+ "filters": {
+ "require_debug_false": {
+ "()": "django.utils.log.RequireDebugFalse",
+ },
+ },
+ "handlers": {
+ "mail_admins": {
+ "level": "ERROR",
+ "filters": ['require_debug_false'],
+ "class": "django.utils.log.AdminEmailHandler",
+ },
+ "console": {
+ "level": "DEBUG",
+ "class": "logging.StreamHandler",
+ "formatter": "simple",
+ },
+ },
+ "loggers": {
+ "django.request": {
+ "handlers": ["mail_admins"],
+ "level": "ERROR",
+ "propagate": False,
+ },
+ }
+}
+if PRODUCTION:
+ LOGGING["handlers"]["logfile"] = {
+ "formatter": "full",
+ "level": "DEBUG",
+ "class": "logging.handlers.TimedRotatingFileHandler",
+ "filename": "/var/log/django_website/website.log",
+ "when": "D",
+ "interval": 7,
+ "backupCount": 5,
+ }
+ LOGGING["loggers"]["django.request"]["handlers"].append("logfile")
+
+
+MANAGERS = (
+ ('Jacob Kaplan-Moss', 'jacob@jacobian.org'),
+)
+
+MEDIA_ROOT = BASE.child('media')
+
+MEDIA_URL = '/m/'
+
+SECRET_KEY = str(SECRETS['secret_key'])
+
+SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTOCOL", "SSL")
+
+SERVER_EMAIL = "root@djangoproject.com"
+
+SESSION_COOKIE_SECURE = PRODUCTION
+
+SESSION_COOKIE_HTTPONLY = True
+
+STATICFILES_DIRS = [BASE.child('static')]
+
+STATIC_ROOT = BASE.child('static_root')
+
+STATIC_URL = '/s/'
+
+TEMPLATE_DIRS = [BASE.child('templates')]
+
+TIME_ZONE = 'America/Chicago'
+
+USE_I18N = False
+
+USE_L10N = False
+
+USE_TZ = False
+
+
+### django-secure settings
+
+SECURE_HSTS_SECONDS = 600
View
199 django_www/settings.py
@@ -1,74 +1,26 @@
# Settings for www.djangoproject.com
-import os
-import json
-import platform
-from unipath import FSPath as Path
-
-# The full path to the repository root.
-BASE = Path(__file__).absolute().ancestor(2)
-
-# Far too clever trick to know if we're running on the deployment server.
-PRODUCTION = ('DJANGOPROJECT_DEBUG' not in os.environ) and ("djangoproject" in platform.node())
-
-# It's a secret to everybody
-SECRETS = json.load(open(BASE.parent.child('secrets.json')))
-SECRET_KEY = str(SECRETS['secret_key'])
-
-ADMINS = (
- ('Adrian Holovaty', 'holovaty@gmail.com'),
- ('Jacob Kaplan-Moss', 'jacob@jacobian.org'),
-)
-MANAGERS = (
- ('Jacob Kaplan-Moss', 'jacob@jacobian.org'),
-)
-FEED_APPROVERS_GROUP_NAME = "feed-approver"
+from django_www.common_settings import *
-TIME_ZONE = 'America/Chicago'
-CACHES = {
- 'default': {
- 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
- 'LOCATION': '127.0.0.1:11211',
- }
-}
+### Django settings
-DATABASES = {
- 'default': {
- 'ENGINE': 'django.db.backends.postgresql_psycopg2',
- 'NAME': 'djangoproject',
- 'USER': 'djangoproject'
- },
- 'trac': {
- 'ENGINE': 'django.db.backends.postgresql_psycopg2',
- 'NAME': 'code.djangoproject',
- 'USER': 'code.djangoproject'
- }
+CACHE_MIDDLEWARE_KEY_PREFIX = 'djangoproject'
+
+DATABASES['trac'] = {
+ 'ENGINE': 'django.db.backends.postgresql_psycopg2',
+ 'NAME': 'code.djangoproject',
+ 'USER': 'code.djangoproject'
}
+
DATABASE_ROUTERS = ['tracdb.db_router.TracRouter']
-USE_I18N = False
-USE_L10N = False
-USE_TZ = False
-
-MEDIA_ROOT = BASE.child('media')
-MEDIA_URL = '/m/'
-TEMPLATE_DIRS = [BASE.child('templates')]
-STATICFILES_DIRS = [BASE.child('static')]
-STATIC_ROOT = BASE.child('static_root')
-STATIC_URL = '/s/'
-
-if PRODUCTION:
- DEBUG = False
- PREPEND_WWW = True
-else:
- DEBUG = True
- PREPEND_WWW = False
- CACHES['default']['BACKEND'] = 'django.core.cache.backends.dummy.DummyCache'
- EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
+PREPEND_WWW = PRODUCTION
-SITE_ID = 1
ROOT_URLCONF = 'django_www.urls'
+
+SITE_ID = 1
+
INSTALLED_APPS = [
'django.contrib.sites',
'django.contrib.auth',
@@ -83,27 +35,22 @@
'django.contrib.sitemaps',
'django_push.subscriber',
+ 'djangosecure',
+ 'registration',
+ 'south',
+
'accounts',
'aggregator',
'blog',
'cla',
'contact',
- 'docs',
'legacy',
'svntogit',
'tracdb',
-
- 'djangosecure',
- 'registration',
- 'south',
]
-MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage'
-
-CACHE_MIDDLEWARE_SECONDS = 60 * 5 # 5 minutes
-CACHE_MIDDLEWARE_KEY_PREFIX = 'djangoproject'
-
MIDDLEWARE_CLASSES = [
+ 'django.middleware.cache.UpdateCacheMiddleware',
'djangosecure.middleware.SecurityMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
@@ -113,108 +60,58 @@
'django.middleware.common.CommonMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
'django.contrib.redirects.middleware.RedirectFallbackMiddleware',
+ 'django.middleware.cache.FetchFromCacheMiddleware',
]
-if PRODUCTION:
- MIDDLEWARE_CLASSES.insert(0, 'django.middleware.cache.UpdateCacheMiddleware')
- MIDDLEWARE_CLASSES.append('django.middleware.cache.FetchFromCacheMiddleware')
TEMPLATE_CONTEXT_PROCESSORS = [
- "django.contrib.auth.context_processors.auth",
- "django.core.context_processors.debug",
- "django.core.context_processors.i18n",
- "django.core.context_processors.static",
- "django.contrib.messages.context_processors.messages",
- "docs.context_processors.recent_release",
+ 'django.contrib.auth.context_processors.auth',
+ 'django.core.context_processors.debug',
+ 'django.core.context_processors.i18n',
+ 'django.core.context_processors.static',
+ 'django.contrib.messages.context_processors.messages',
+ 'docs.context_processors.recent_release',
]
-DEFAULT_FROM_EMAIL = "noreply@djangoproject.com"
-SERVER_EMAIL = "root@djangoproject.com"
-
-LOGGING = {
- "version": 1,
- "disable_existing_loggers": True,
- "formatters": {
- "simple": {"format": "[%(name)s] %(levelname)s: %(message)s"},
- "full": {"format": "%(asctime)s [%(name)s] %(levelname)s: %(message)s"},
- },
- "filters": {
- "require_debug_false": {
- "()": "django.utils.log.RequireDebugFalse",
- },
- },
- "handlers": {
- "mail_admins": {
- "level": "ERROR",
- "filters": ['require_debug_false'],
- "class": "django.utils.log.AdminEmailHandler",
- },
- "console": {
- "level": "DEBUG",
- "class": "logging.StreamHandler",
- "formatter": "simple",
- },
- },
- "loggers": {
- "django.request": {
- "handlers": ["mail_admins"],
- "level": "ERROR",
- "propagate": False,
- },
- "django_website": {
- "handlers": ["console"],
- "level": "DEBUG",
- },
- }
-}
-if PRODUCTION:
- LOGGING["handlers"]["logfile"] = {
- "formatter": "full",
- "level": "DEBUG",
- "class": "logging.handlers.TimedRotatingFileHandler",
- "filename": "/var/log/django_website/website.log",
- "when": "D",
- "interval": 7,
- "backupCount": 5,
- }
- LOGGING["loggers"]["django.request"]["handlers"].append("logfile")
- LOGGING["loggers"]["django_website"]["handlers"] = ["logfile"]
-
-# django-registration settings
-ACCOUNT_ACTIVATION_DAYS = 3
-# comment_utils settings
+### django-contact-form / Akismet settings
+
AKISMET_API_KEY = "c892e4962244"
-# south settings
-SOUTH_TESTS_MIGRATE = False
-# PubSubHubbub settings
+### django-registration settings
+
+ACCOUNT_ACTIVATION_DAYS = 3
+
+
+### aggregator / PubSubHubbub settings
+
+FEED_APPROVERS_GROUP_NAME = "feed-approver"
+
PUSH_HUB = 'https://superfeedr.com/hubbub'
PUSH_CREDENTIALS = 'aggregator.utils.push_credentials'
PUSH_SSL_CALLBACK = PRODUCTION
# SUPERFEEDR_CREDS is a 2 element list in the form of [email,secretkey]
SUPERFEEDR_CREDS = SECRETS.get('superfeedr_creds')
-# Lock down some security stuff
-if PRODUCTION:
- SESSION_COOKIE_SECURE = True
- SESSION_COOKIE_HTTPONLY = True
- SECURE_SSL_REDIRECT = False
- SECURE_HSTS_SECONDS = 600
- SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTOCOL", "SSL")
-# If django-debug-toolbar is installed enable it.
-if not PRODUCTION:
+### South settings
+
+SOUTH_TESTS_MIGRATE = False
+
+
+### Enable optional components
+
+if DEBUG:
try:
import debug_toolbar
except ImportError:
pass
else:
- # Insert DDT after the common middleware
- common_index = MIDDLEWARE_CLASSES.index('django.middleware.common.CommonMiddleware')
- MIDDLEWARE_CLASSES.insert(common_index+1, 'debug_toolbar.middleware.DebugToolbarMiddleware')
- INTERNAL_IPS = ['127.0.0.1']
INSTALLED_APPS.append('debug_toolbar')
+ INTERNAL_IPS = ['127.0.0.1']
+ MIDDLEWARE_CLASSES.insert(
+ MIDDLEWARE_CLASSES.index('django.middleware.common.CommonMiddleware') + 1,
+ 'debug_toolbar.middleware.DebugToolbarMiddleware')
# Log errors to Sentry instead of email, if available.
if 'sentry_dsn' in SECRETS:
Please sign in to comment.
Something went wrong with that request. Please try again.