settings.py 9.9 KB
Newer Older
David Haynes's avatar
David Haynes committed
1
2
3
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
David Haynes's avatar
David Haynes committed
4
settings/base.py
5

David Haynes's avatar
David Haynes committed
6
7
8
Base Django settings for whats-open.
"""
# Python std. lib. imports
9
import sys
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from os import path, environ

# DEV vs PROD
if environ["WOPEN_ENV"] != "production":
    DEBUG = True
    # dummy cache for development-- doesn't actually cache things
    CACHES = {"default": {"BACKEND": "django.core.cache.backends.dummy.DummyCache"}}
else:
    DEBUG = False
    CACHES = {
        "default": {"BACKEND": "redis_cache.RedisCache", "LOCATION": "localhost:6379"}
    }
    ALLOWED_HOSTS = ["*"]
    SECRET_KEY = environ["WOPEN_SECRET_KEY"]
24

David Haynes's avatar
David Haynes committed
25
26
27
"""
PATH CONFIGURATION
"""
28
# Absolute filesystem path to the Django project directory:
29
DJANGO_ROOT = path.dirname(path.dirname(path.abspath(__file__)))
30
31

# Absolute filesystem path to the top-level project folder:
32
SITE_ROOT = path.dirname(DJANGO_ROOT)
33
34
35

# Add our project to our pythonpath, this way we don't need to type our project
# name in our dotted import paths:
36
sys.path.append(DJANGO_ROOT)
37

David Haynes's avatar
David Haynes committed
38
39
40
"""
MANAGER CONFIGURATION
"""
41
# See: https://docs.djangoproject.com/en/dev/ref/settings/#admins
Daniel W Bond's avatar
Daniel W Bond committed
42
# Insert a ('Name', 'Email') inside ADMINS tuple
43
ADMINS = (("SRCT Admin", "srct@gmu.edu"),)
44
45
46
47

# See: https://docs.djangoproject.com/en/dev/ref/settings/#managers
MANAGERS = ADMINS

David Haynes's avatar
David Haynes committed
48
49
50
"""
GENERAL CONFIGURATION
"""
51
52
# See: https://docs.djangoproject.com/en/dev/ref/settings/#time-zone
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
Daniel W Bond's avatar
Daniel W Bond committed
53
# although not all choices may be available on all operating systems.
54
# In a Windows environment this must be set to your system time zone.
55
TIME_ZONE = "America/New_York"
56
57

# See: https://docs.djangoproject.com/en/dev/ref/settings/#language-code
Daniel W Bond's avatar
Daniel W Bond committed
58
59
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
60
LANGUAGE_CODE = "en-us"
61
62
63
64
65

# 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
Daniel W Bond's avatar
Daniel W Bond committed
66
67
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
68
69
70
USE_I18N = True

# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-l10n
Daniel W Bond's avatar
Daniel W Bond committed
71
72
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
73
74
75
USE_L10N = True

# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-tz
Daniel W Bond's avatar
Daniel W Bond committed
76
# If you set this to False, Django will not use timezone-aware datetimes.
77
78
USE_TZ = True

David Haynes's avatar
David Haynes committed
79
80
81
"""
MEDIA CONFIGURATION
"""
82
# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-root
Daniel W Bond's avatar
Daniel W Bond committed
83
84
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
85
MEDIA_ROOT = path.normpath(path.join(SITE_ROOT, "media"))
86
87

# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-url
Daniel W Bond's avatar
Daniel W Bond committed
88
89
90
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
91
MEDIA_URL = "/media/"
92

David Haynes's avatar
David Haynes committed
93
94
95
"""
STATIC FILE CONFIGURATION
"""
96
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-root
Daniel W Bond's avatar
Daniel W Bond committed
97
98
99
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
David Haynes's avatar
David Haynes committed
100
# Example: "/home/media/media.lawrence.com/static/"
101
STATIC_ROOT = path.normpath(path.join(SITE_ROOT, "static"))
102
103

# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url
Daniel W Bond's avatar
Daniel W Bond committed
104
105
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
106
STATIC_URL = "/static/"
107

108
ADMIN_MEDIA_PREFIX = "/static/admin/"
109
110
111

# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders
STATICFILES_FINDERS = (
112
113
    "django.contrib.staticfiles.finders.FileSystemFinder",
    "django.contrib.staticfiles.finders.AppDirectoriesFinder",
114
115
)

David Haynes's avatar
David Haynes committed
116
117
118
"""
SECRET CONFIGURATION
"""
119
120
121
122
# See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
# Note: This key should only be used for development and testing.
SECRET_KEY = r"{{ secret_key }}"

David Haynes's avatar
David Haynes committed
123
124
125
"""
SITE CONFIGURATION
"""
Daniel W Bond's avatar
Daniel W Bond committed
126
# Hosts/domain names that are valid for this site; required if DEBUG is False
127
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
128
ALLOWED_HOSTS = ["*"]
129
130
131
########## END SITE CONFIGURATION


David Haynes's avatar
David Haynes committed
132
133
134
"""
FIXTURE CONFIGURATION
"""
135
# See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS
136
FIXTURE_DIRS = (path.normpath(path.join(SITE_ROOT, "fixtures")),)
137

David Haynes's avatar
David Haynes committed
138
139
140
"""
DATABASE CONFIGURATION
"""
David Haynes's avatar
David Haynes committed
141
142
143
# Use the same DB everywhere.
# See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = {
144
145
    "default": {
        "ENGINE": "django.contrib.gis.db.backends.mysql",
146
147
148
149
150
        "NAME": environ["WOPEN_DB_NAME"],
        "USER": environ["WOPEN_DB_USER"],
        "PASSWORD": environ["WOPEN_DB_PASSWORD"],
        "HOST": environ["WOPEN_DB_HOST"],
        "PORT": environ["WOPEN_DB_PORT"],
David Haynes's avatar
David Haynes committed
151
152
    }
}
153

David Haynes's avatar
David Haynes committed
154
155
156
"""
TEMPLATE CONFIGURATION
"""
157
158
TEMPLATES = [
    {
159
        "BACKEND": "django.template.backends.django.DjangoTemplates",
160
        # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
161
        "DIRS": [
162
            path.normpath(path.join(SITE_ROOT, "templates")),
163
            # may specify to avoid requiring paths
164
            path.normpath(path.join(SITE_ROOT, "api/templates")),
165
        ],
166
        "OPTIONS": {
167
            # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
168
169
170
171
172
173
174
175
176
177
178
            "context_processors": [
                "django.contrib.auth.context_processors.auth",
                "django.template.context_processors.request",
                "django.contrib.auth.context_processors.auth",
                "django.template.context_processors.debug",
                "django.template.context_processors.i18n",
                "django.template.context_processors.media",
                "django.template.context_processors.static",
                "django.template.context_processors.tz",
                "django.contrib.messages.context_processors.messages",
                "django.template.context_processors.request",
179
180
            ],
            # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders
181
182
183
            "loaders": [
                "django.template.loaders.filesystem.Loader",
                "django.template.loaders.app_directories.Loader",
184
            ],
185
        },
186
187
    }
]
188

David Haynes's avatar
David Haynes committed
189
190
191
"""
MIDDLEWARE CONFIGURATION
"""
192
# See: https://docs.djangoproject.com/en/dev/ref/settings/#middleware-classes
David Haynes's avatar
David Haynes committed
193
MIDDLEWARE = [
194
    # Default Django middleware.
195
196
197
198
199
200
    "django.middleware.common.CommonMiddleware",
    "django.contrib.sessions.middleware.SessionMiddleware",
    "django.middleware.csrf.CsrfViewMiddleware",
    "django.contrib.auth.middleware.AuthenticationMiddleware",
    "django.contrib.messages.middleware.MessageMiddleware",
    "django.middleware.clickjacking.XFrameOptionsMiddleware",
David Haynes's avatar
David Haynes committed
201
]
202

David Haynes's avatar
David Haynes committed
203
204
205
"""
URL CONFIGURATION
"""
206
# See: https://docs.djangoproject.com/en/dev/ref/settings/#root-urlconf
207
ROOT_URLCONF = "settings.urls"
208

David Haynes's avatar
David Haynes committed
209
210
211
"""
WSGI CONFIGURATION
"""
212
# See: https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application
Daniel W Bond's avatar
Daniel W Bond committed
213
# Python dotted path to the WSGI application used by Django's runserver.
214
WSGI_APPLICATION = "settings.wsgi.application"
215

David Haynes's avatar
David Haynes committed
216
217
218
"""
SERIALIZER CONFIGURATION
"""
219
# http://djx.readthedocs.org/en/latest/topics/http/sessions.html#session-serialization
220
SESSION_SERIALIZER = "django.contrib.sessions.serializers.JSONSerializer"
221

David Haynes's avatar
David Haynes committed
222
223
224
"""
CACHE MIDDLEWARE CONFIGURATION
"""
225
CACHE_MIDDLEWARE_ALIAS = "default"
226
CACHE_MIDDLEWARE_SECONDS = 259200
227
CACHE_MIDDLEWARE_KEY_PREFIX = ""
228

David Haynes's avatar
David Haynes committed
229
230
231
"""
APP CONFIGURATION
"""
232
INSTALLED_APPS = (
233
    # Default Django apps:
234
235
236
237
238
239
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.sites",
    "django.contrib.messages",
    "django.contrib.staticfiles",
240
    # Admin panel and documentation:
241
242
243
    "django.contrib.admin",
    "django.contrib.admindocs",
    "django.contrib.gis",
244
    # Apps specific for this project go here.
245
    "api",
246
    # Third party apps
247
248
249
250
251
252
    "taggit",
    "taggit_serializer",
    "rest_framework",
    "rest_framework_gis",
    "django_filters",
    "crispy_forms",
253
254
)

David Haynes's avatar
David Haynes committed
255
256
257
"""
DJANGO REST FRAMEWORK CONFIGURATION
"""
258
259
260
261
# http://www.django-rest-framework.org/api-guide/settings
REST_FRAMEWORK = {
    # Use hyperlinked styles by default.
    # Only used if the `serializer_class` attribute is not set on a view.
262
    "DEFAULT_MODEL_SERIALIZER_CLASS": "rest_framework.serializers.HyperlinkedModelSerializer",
263
264
    # Use Django's standard `django.contrib.auth` permissions,
    # or allow read-only access for unauthenticated users.
265
266
    "DEFAULT_PERMISSION_CLASSES": [
        "rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly"
David Haynes's avatar
David Haynes committed
267
268
    ],
    # http://www.django-rest-framework.org/api-guide/throttling/#throttling
269
270
    "DEFAULT_THROTTLE_CLASSES": ("rest_framework.throttling.AnonRateThrottle",),
    "DEFAULT_THROTTLE_RATES": {"anon": "1000/day"},
271
272
}

David Haynes's avatar
David Haynes committed
273
274
275
"""
LOGGING CONFIGURATION
"""
276
277
278
279
280
281
282
# 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 = {
283
284
285
286
287
288
289
290
    "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",
291
        },
292
293
294
295
        "console": {
            "level": "INFO",
            "class": "logging.StreamHandler",
            "stream": sys.stdout,
296
        },
297
    },
298
299
300
301
302
    "loggers": {
        "django.request": {
            "handlers": ["mail_admins"],
            "level": "ERROR",
            "propagate": True,
303
        },
304
305
        "django": {"handlers": ["console"], "level": "INFO", "propogate": True},
    },
306
}