Skip to content

Commit 3c73f98

Browse files
committed
Ch29: Split settings file.
1 parent ee87540 commit 3c73f98

File tree

4 files changed

+125
-111
lines changed

4 files changed

+125
-111
lines changed

suorganizer/settings/__init__.py

Whitespace-only changes.
Lines changed: 20 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,14 @@
1-
"""
2-
Django settings for suorganizer project.
1+
# https://docs.djangoproject.com/en/1.8/topics/settings/
2+
# https://docs.djangoproject.com/en/1.8/ref/settings/
33

4-
Generated by 'django-admin startproject' using Django 1.8.
5-
6-
For more information on this file, see
7-
https://docs.djangoproject.com/en/1.8/topics/settings/
8-
9-
For the full list of settings and their values, see
10-
https://docs.djangoproject.com/en/1.8/ref/settings/
11-
"""
12-
13-
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
144
import os
155

16-
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17-
6+
from django.core.urlresolvers import reverse_lazy
187

19-
# Quick-start development settings - unsuitable for production
20-
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
8+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
219

2210
SITE_ID = 1
2311

24-
# SECURITY WARNING: keep the secret key used in production secret!
25-
SECRET_KEY = 'l)zht&^pddidsyqe$+09%se1*ba2#b_q-!j0^v$(-3c-=-vmq4'
26-
27-
# SECURITY WARNING: don't run with debug turned on in production!
28-
DEBUG = True
29-
30-
ALLOWED_HOSTS = []
31-
32-
33-
# Application definition
34-
3512
INSTALLED_APPS = (
3613
'user',
3714
'django.contrib.admin',
@@ -42,8 +19,6 @@
4219
'django.contrib.sites',
4320
'django.contrib.sitemaps',
4421
'django.contrib.staticfiles',
45-
'debug_toolbar',
46-
'django_extensions',
4722
'core',
4823
'organizer',
4924
'blog',
@@ -53,6 +28,7 @@
5328
MIDDLEWARE_CLASSES = (
5429
'django.middleware.cache.UpdateCacheMiddleware',
5530
'django.contrib.sessions.middleware.SessionMiddleware',
31+
'django.middleware.common.BrokenLinkEmailsMiddleware',
5632
'django.middleware.common.CommonMiddleware',
5733
'django.middleware.csrf.CsrfViewMiddleware',
5834
'django.contrib.auth.middleware.AuthenticationMiddleware',
@@ -78,109 +54,49 @@
7854
'django.contrib.messages.context_processors.messages',
7955
],
8056
'loaders': [
81-
# ('django.template.loaders.cached.Loader', [
82-
'django.template.loaders.filesystem.Loader',
83-
'django.template.loaders.app_directories.Loader',
84-
# ]),
57+
'django.template.loaders.filesystem.Loader',
58+
'django.template.loaders.app_directories.Loader',
8559
],
8660
},
8761
}]
8862

8963
WSGI_APPLICATION = 'suorganizer.wsgi.application'
9064

91-
92-
# Caches
93-
# https://docs.djangoproject.com/en/1.8/topics/cache/#local-memory-caching
94-
95-
CACHES = {
96-
'default': {
97-
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
98-
}
99-
}
100-
CACHE_MIDDLEWARE_ALIAS = 'default'
101-
102-
10365
# User
10466
# https://docs.djangoproject.com/en/1.8/topics/auth/customizing/#substituting-a-custom-user-model
10567

10668
AUTH_USER_MODEL = 'user.User'
10769

70+
# Internationalization
71+
# https://docs.djangoproject.com/en/1.8/topics/i18n/
10872

109-
# Database
110-
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
111-
112-
DATABASES = {
113-
'default': {
114-
'ENGINE': 'django.db.backends.sqlite3',
115-
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
116-
}
117-
}
73+
LANGUAGE_CODE = 'en-us'
11874

75+
TIME_ZONE = 'UTC'
11976

120-
# Logging
121-
# https://docs.djangoproject.com/en/1.8/topics/logging/
77+
USE_I18N = True
12278

123-
from .log_filters import ManagementFilter
79+
USE_L10N = True
12480

125-
verbose = (
126-
"[%(asctime)s] %(levelname)s "
127-
"[%(name)s:%(lineno)s] %(message)s")
81+
USE_TZ = True
12882

129-
LOGGING = {
130-
'version': 1,
131-
'disable_existing_loggers': False,
132-
'filters': {
133-
'remove_migration_sql': {
134-
'()': ManagementFilter,
135-
},
136-
},
137-
'handlers': {
138-
'console': {
139-
'filters': ['remove_migration_sql'],
140-
'class': 'logging.StreamHandler',
141-
},
142-
},
143-
'formatters': {
144-
'verbose': {
145-
'format': verbose,
146-
'datefmt': "%Y-%b-%d %H:%M:%S"
147-
},
148-
},
149-
'loggers': {
150-
'django': {
151-
'handlers': ['console'],
152-
'level': 'DEBUG',
153-
'formatter': 'verbose'
154-
},
155-
},
156-
}
83+
# Login Settings
84+
# https://docs.djangoproject.com/en/1.8/topics/auth/
15785

86+
LOGIN_REDIRECT_URL = reverse_lazy('blog_post_list')
87+
LOGIN_URL = reverse_lazy('dj-auth:login')
88+
LOGOUT_URL = reverse_lazy('dj-auth:logout')
15889

15990
# Email
16091
# https://docs.djangoproject.com/en/1.8/topics/email/
16192

162-
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
16393
SERVER_EMAIL = 'contact@django-unleashed.com'
16494
DEFAULT_FROM_EMAIL = 'no-reply@django-unleashed.com'
16595
EMAIL_SUBJECT_PREFIX = '[Startup Organizer] '
16696
MANAGERS = (
16797
('Us', 'ourselves@django-unleashed.com'),
16898
)
16999

170-
# Internationalization
171-
# https://docs.djangoproject.com/en/1.8/topics/i18n/
172-
173-
LANGUAGE_CODE = 'en-us'
174-
175-
TIME_ZONE = 'UTC'
176-
177-
USE_I18N = True
178-
179-
USE_L10N = True
180-
181-
USE_TZ = True
182-
183-
184100
# Fixtures
185101
# https://docs.djangoproject.com/en/1.8/topics/serialization/
186102

@@ -192,11 +108,4 @@
192108

193109
STATIC_URL = '/static/'
194110
STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),)
195-
196-
# Login Settings
197-
# https://docs.djangoproject.com/en/1.8/topics/auth/
198-
from django.core.urlresolvers import reverse_lazy
199-
200-
LOGIN_REDIRECT_URL = reverse_lazy('blog_post_list')
201-
LOGIN_URL = reverse_lazy('dj-auth:login')
202-
LOGOUT_URL = reverse_lazy('dj-auth:logout')
111+
STATIC_ROOT = os.path.join(BASE_DIR, 'collected_static')

suorganizer/settings/dev.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# https://docs.djangoproject.com/en/1.8/topics/settings/
2+
# https://docs.djangoproject.com/en/1.8/ref/settings/
3+
4+
from ..log_filters import ManagementFilter
5+
from .base import *
6+
7+
# SECURITY WARNING: keep the secret key used in production secret!
8+
SECRET_KEY = 'l)zht&^pddidsyqe$+09%se1*ba2#b_q-!j0^v$(-3c-=-vmq4'
9+
10+
DEBUG = True
11+
12+
ALLOWED_HOSTS = []
13+
14+
INSTALLED_APPS += (
15+
'debug_toolbar',
16+
'django_extensions',
17+
)
18+
19+
20+
# Database
21+
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
22+
23+
DATABASES = {
24+
'default': {
25+
'ENGINE': 'django.db.backends.sqlite3',
26+
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
27+
}
28+
}
29+
30+
31+
# Caches
32+
# https://docs.djangoproject.com/en/1.8/topics/cache/#local-memory-caching
33+
34+
CACHES = {
35+
'default': {
36+
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
37+
}
38+
}
39+
CACHE_MIDDLEWARE_ALIAS = 'default'
40+
41+
42+
# Logging
43+
# https://docs.djangoproject.com/en/1.8/topics/logging/
44+
45+
verbose = (
46+
"[%(asctime)s] %(levelname)s "
47+
"[%(name)s:%(lineno)s] %(message)s")
48+
49+
LOGGING = {
50+
'version': 1,
51+
'disable_existing_loggers': False,
52+
'filters': {
53+
'remove_migration_sql': {
54+
'()': ManagementFilter,
55+
},
56+
},
57+
'handlers': {
58+
'console': {
59+
'filters': ['remove_migration_sql'],
60+
'class': 'logging.StreamHandler',
61+
},
62+
},
63+
'formatters': {
64+
'verbose': {
65+
'format': verbose,
66+
'datefmt': "%Y-%b-%d %H:%M:%S"
67+
},
68+
},
69+
'loggers': {
70+
'django': {
71+
'handlers': ['console'],
72+
'level': 'DEBUG',
73+
'formatter': 'verbose'
74+
},
75+
},
76+
}
77+
78+
# Email
79+
# https://docs.djangoproject.com/en/1.8/topics/email/
80+
81+
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

suorganizer/settings/production.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# https://docs.djangoproject.com/en/1.8/topics/settings/
2+
# https://docs.djangoproject.com/en/1.8/ref/settings/
3+
4+
import os
5+
6+
import dj_database_url
7+
8+
from .base import *
9+
10+
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
11+
12+
# SECURITY WARNING: don't run with debug turned on in production!
13+
DEBUG = False
14+
TEMPLATE_DEBUG = False
15+
16+
SECRET_KEY = os.environ.get('SECRET_KEY')
17+
18+
ALLOWED_HOSTS = ['*']
19+
20+
DATABASES = {'default': dj_database_url.config()}
21+
22+
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
23+
24+
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

0 commit comments

Comments
 (0)