base.py 9.36 KB
Newer Older
David Haynes's avatar
David Haynes committed
1
2
""""
settings/base.py
3

David Haynes's avatar
David Haynes committed
4
5
6
7
8
9
10
Base Django settings for whats-open.
"""
# Future Imports
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)

# Python std. lib. imports
11
import os
12
import sys
David Haynes's avatar
David Haynes committed
13
from os.path import abspath, dirname, join, normpath
14
15
from sys import path

David Haynes's avatar
David Haynes committed
16
17
18
"""
PATH CONFIGURATION
"""
19
20
21
22
23
24
25
26
27
28
# Absolute filesystem path to the Django project directory:
DJANGO_ROOT = dirname(dirname(abspath(__file__)))

# Absolute filesystem path to the top-level project folder:
SITE_ROOT = dirname(DJANGO_ROOT)

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

David Haynes's avatar
David Haynes committed
29
30
31
"""
MANAGER CONFIGURATION
"""
32
# See: https://docs.djangoproject.com/en/dev/ref/settings/#admins
Daniel W Bond's avatar
Daniel W Bond committed
33
# Insert a ('Name', 'Email') inside ADMINS tuple
34
ADMINS = (
Daniel W Bond's avatar
Daniel W Bond committed
35
    ('SRCT Admin', 'srct@gmu.edu'),
36
37
38
39
40
)

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

David Haynes's avatar
David Haynes committed
41
42
43
"""
GENERAL CONFIGURATION
"""
44
45
# 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
46
# although not all choices may be available on all operating systems.
47
48
49
50
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'America/New_York'

# See: https://docs.djangoproject.com/en/dev/ref/settings/#language-code
Daniel W Bond's avatar
Daniel W Bond committed
51
52
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
53
54
55
56
57
58
LANGUAGE_CODE = 'en-us'

# 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
59
60
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
61
62
63
USE_I18N = True

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

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

David Haynes's avatar
David Haynes committed
72
73
74
"""
MEDIA CONFIGURATION
"""
75
# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-root
Daniel W Bond's avatar
Daniel W Bond committed
76
77
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
78
79
80
MEDIA_ROOT = normpath(join(SITE_ROOT, 'media'))

# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-url
Daniel W Bond's avatar
Daniel W Bond committed
81
82
83
# 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/"
84
85
MEDIA_URL = '/media/'

David Haynes's avatar
David Haynes committed
86
87
88
"""
STATIC FILE CONFIGURATION
"""
89
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-root
Daniel W Bond's avatar
Daniel W Bond committed
90
91
92
# 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
93
94
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = normpath(join(SITE_ROOT, 'static'))
95
96

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

ADMIN_MEDIA_PREFIX = '/static/admin/'

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

David Haynes's avatar
David Haynes committed
109
110
111
"""
SECRET CONFIGURATION
"""
112
113
114
115
# 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
116
117
118
"""
SITE CONFIGURATION
"""
Daniel W Bond's avatar
Daniel W Bond committed
119
# Hosts/domain names that are valid for this site; required if DEBUG is False
120
121
122
123
124
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = ['*']
########## END SITE CONFIGURATION


David Haynes's avatar
David Haynes committed
125
126
127
"""
FIXTURE CONFIGURATION
"""
128
129
130
131
132
# See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS
FIXTURE_DIRS = (
    normpath(join(SITE_ROOT, 'fixtures')),
)

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

David Haynes's avatar
David Haynes committed
149
150
151
"""
TEMPLATE CONFIGURATION
"""
152
153
154
155
156
157
158
159
160
161
162
163
164
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
        'DIRS': [
            normpath(join(SITE_ROOT, 'templates'))
        ],
        'OPTIONS': {
            # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
            'context_processors': [
                'django.contrib.auth.context_processors.auth',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
165
166
167
168
169
                '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',
170
                'django.contrib.messages.context_processors.messages',
171
                'django.template.context_processors.request',
172
173
174
175
176
177
178
179
180
            ],
            # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders
            'loaders': [
                'django.template.loaders.filesystem.Loader',
                'django.template.loaders.app_directories.Loader',
            ],
        }
    }
]
181

David Haynes's avatar
David Haynes committed
182
183
184
"""
MIDDLEWARE CONFIGURATION
"""
185
186
187
188
189
190
191
192
193
194
195
# See: https://docs.djangoproject.com/en/dev/ref/settings/#middleware-classes
MIDDLEWARE_CLASSES = (
    # Default Django middleware.
    '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
196
197
198
"""
URL CONFIGURATION
"""
199
# See: https://docs.djangoproject.com/en/dev/ref/settings/#root-urlconf
200
ROOT_URLCONF = 'settings.urls'
201

David Haynes's avatar
David Haynes committed
202
203
204
"""
WSGI CONFIGURATION
"""
205
# See: https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application
Daniel W Bond's avatar
Daniel W Bond committed
206
# Python dotted path to the WSGI application used by Django's runserver.
207
WSGI_APPLICATION = 'settings.wsgi.application'
208

David Haynes's avatar
David Haynes committed
209
210
211
"""
SERIALIZER CONFIGURATION
"""
212
213
214
# http://djx.readthedocs.org/en/latest/topics/http/sessions.html#session-serialization
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer'

David Haynes's avatar
David Haynes committed
215
216
217
"""
CACHE MIDDLEWARE CONFIGURATION
"""
218
219
220
221
CACHE_MIDDLEWARE_ALIAS = 'default'
CACHE_MIDDLEWARE_SECONDS = 259200
CACHE_MIDDLEWARE_KEY_PREFIX = ''

David Haynes's avatar
David Haynes committed
222
223
224
"""
APP CONFIGURATION
"""
225
INSTALLED_APPS = (
226
227
228
229
230
231
232
233
234
235
236
    # Default Django apps:
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    # Admin panel and documentation:
    'django.contrib.admin',
    'django.contrib.admindocs',
David Haynes's avatar
David Haynes committed
237
    'django.contrib.gis',
238

239
    # Apps specific for this project go here.
240
    'api',
241
242
243

    # Third party apps
    'taggit',
244
245
    'taggit_serializer',
    'rest_framework',
David Haynes's avatar
David Haynes committed
246
    'rest_framework_gis',
David Haynes's avatar
David Haynes committed
247
    'django_filters',
David Haynes's avatar
David Haynes committed
248
    'crispy_forms',
249
250
)

David Haynes's avatar
David Haynes committed
251
252
253
"""
DJANGO REST FRAMEWORK CONFIGURATION
"""
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# 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.
    'DEFAULT_MODEL_SERIALIZER_CLASS':
        'rest_framework.serializers.HyperlinkedModelSerializer',

    # Use Django's standard `django.contrib.auth` permissions,
    # or allow read-only access for unauthenticated users.
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
    ]
}

David Haynes's avatar
David Haynes committed
268
269
270
"""
LOGGING CONFIGURATION
"""
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# 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 = {
    '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'
290
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
306
307
        'django': {
            'handlers': ['console'],
            'level': 'INFO',
            'propogate': True
        },
308
309
    }
}