base.py 9.91 KB
Newer Older
1
2
3
""""Base Django settings for whats_open."""

import os
4
import sys
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from os.path import abspath, basename, dirname, join, normpath
from sys import path

########## PATH CONFIGURATION
# 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)
########## END PATH CONFIGURATION

########## MANAGER CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#admins
Daniel W Bond's avatar
Daniel W Bond committed
22
# Insert a ('Name', 'Email') inside ADMINS tuple
23
ADMINS = (
Daniel W Bond's avatar
Daniel W Bond committed
24
    ('SRCT Admin', 'srct@gmu.edu'),
25
26
27
28
29
30
31
32
33
)

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

########## GENERAL CONFIGURATION
# 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
34
# although not all choices may be available on all operating systems.
35
36
37
38
# 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
39
40
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
41
42
43
44
45
46
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
47
48
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
49
50
51
USE_I18N = True

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

# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-tz
Daniel W Bond's avatar
Daniel W Bond committed
57
# If you set this to False, Django will not use timezone-aware datetimes.
58
59
60
61
62
63
USE_TZ = True
########## END GENERAL CONFIGURATION


########## MEDIA CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-root
Daniel W Bond's avatar
Daniel W Bond committed
64
65
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
66
67
68
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
69
70
71
# 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/"
72
73
74
75
76
MEDIA_URL = '/media/'
########## END MEDIA CONFIGURATION

########## STATIC FILE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-root
Daniel W Bond's avatar
Daniel W Bond committed
77
78
79
80
# 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.
# Example: "/home/media/media.lawrence.com/static/" 
81
82
83
STATIC_ROOT = normpath(join(SITE_ROOT, 'assets'))

# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url
Daniel W Bond's avatar
Daniel W Bond committed
84
85
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
STATIC_URL = '/static/'

# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
STATICFILES_DIRS = (
    normpath(join(SITE_ROOT, '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',
)
########## END STATIC FILE CONFIGURATION


########## SECRET CONFIGURATION
# 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 }}"
########## END SECRET CONFIGURATION


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


########## FIXTURE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS
FIXTURE_DIRS = (
    normpath(join(SITE_ROOT, 'fixtures')),
)
########## END FIXTURE CONFIGURATION

David Haynes's avatar
David Haynes committed
124
125
126
127
128
129
130
131
132
133
134
135
136
########## DATABASE CONFIGURATION
# Use the same DB everywhere.
# See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        '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'],
    }
}
137
138

########## TEMPLATE CONFIGURATION
139
140
141
142
143
144
145
146
147
148
149
150
151
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',
152
153
154
155
156
                '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',
157
                'django.contrib.messages.context_processors.messages',
158
                'django.template.context_processors.request',
159
160
161
162
163
164
165
166
167
            ],
            # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders
            'loaders': [
                'django.template.loaders.filesystem.Loader',
                'django.template.loaders.app_directories.Loader',
            ],
        }
    }
]
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
########## END TEMPLATE CONFIGURATION


########## MIDDLEWARE CONFIGURATION
# 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',
)
########## END MIDDLEWARE CONFIGURATION


########## URL CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#root-urlconf
187
ROOT_URLCONF = 'settings.urls'
188
189
190
191
192
########## END URL CONFIGURATION


########## WSGI CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application
Daniel W Bond's avatar
Daniel W Bond committed
193
# Python dotted path to the WSGI application used by Django's runserver.
194
WSGI_APPLICATION = 'settings.wsgi.application'
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
########## END WSGI CONFIGURATION


########## SERIALIZER CONFIGURATION
# http://djx.readthedocs.org/en/latest/topics/http/sessions.html#session-serialization
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer'
########## END SERIALIZER CONFIGURATION


########## CACHE MIDDLEWARE CONFIGURATION
CACHE_MIDDLEWARE_ALIAS = 'default'
CACHE_MIDDLEWARE_SECONDS = 259200
CACHE_MIDDLEWARE_KEY_PREFIX = ''
########## END CACHE MIDDLEWARE CONFIGURATION


########## APP CONFIGURATION
212
INSTALLED_APPS = (
213
214
215
216
217
218
219
220
221
222
223
224
    # 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',

225
    # Apps specific for this project go here.
226
    'api',
227
228
229

    # Third party apps
    'taggit',
230
231
    'taggit_serializer',
    'rest_framework',
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
)

########## END APP CONFIGURATION


########## DJANGO REST FRAMEWORK CONFIGURATION
# 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'
    ]
}
########## END DJANGO REST FRAMEWORK CONFIGURATION


########## LOGGING CONFIGURATION
# 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'
274
275
276
277
278
279
        },
        'console': {
            'level': 'INFO',
            'class': 'logging.StreamHandler',
            'stream': sys.stdout
        },
280
281
282
283
284
285
286
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
287
288
289
290
291
        'django': {
            'handlers': ['console'],
            'level': 'INFO',
            'propogate': True
        },
292
293
    }
}
Daniel W Bond's avatar
Daniel W Bond committed
294

295
########## END LOGGING CONFIGURATION