settings.py 7.16 KB
Newer Older
1
"""
2
Django settings for roomlist project.
3
4

For more information on this file, see
5
https://docs.djangoproject.com/en/1.7/topics/settings/
6
7

For the full list of settings and their values, see
8
https://docs.djangoproject.com/en/1.7/ref/settings/
9
10
"""

11
12
from __future__ import absolute_import, print_function

13
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
14

15
16
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
17

18
19
ORGANIZATION_EMAIL_DOMAIN = 'masonlive.gmu.edu'

20
21
22
TEMPLATE_DIRS = (
    os.path.join(BASE_DIR, 'templates'),
    os.path.join(BASE_DIR, 'housing/templates'),
23
    os.path.join(BASE_DIR, 'accounts/templates'),
24
25
)

26
27
28
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)
29
30
31
32
33
34
35
36

TEMPLATE_LOADERS = (

    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',

)

37
38
39
40
41
42
43
44
TEMPLATE_CONTEXT_PROCESSORS = (
    'django.contrib.auth.context_processors.auth',
    'django.core.context_processors.debug',
    'django.core.context_processors.i18n',
    'django.core.context_processors.media',
    'django.core.context_processors.static',
    'django.contrib.messages.context_processors.messages',
    'django.core.context_processors.request',
Jason D Yeomans's avatar
Jason D Yeomans committed
45
46
    'allauth.account.context_processors.account',
    'allauth.socialaccount.context_processors.socialaccount',
47
)
48
# Quick-start development settings - unsuitable for production
49
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
50

51
from . import config
52
53
54
DEBUG = config.DEBUG
TEMPLATE_DEBUG = config.TEMPLATE_DEBUG
ALLOWED_HOSTS = config.ALLOWED_HOSTS
55

Daniel W Bond's avatar
Daniel W Bond committed
56
57
58
PIWIK_DOMAIN_PATH = config.PIWIK_DOMAIN_PATH
PIWIK_SITE_ID = config.PIWIK_SITE_ID

59
60
61
62
63
64
65
66
67
# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
Jason D Yeomans's avatar
Jason D Yeomans committed
68
    'django.contrib.sites',
69
    'django.contrib.humanize',
Daniel W Bond's avatar
Daniel W Bond committed
70
    # apps
71
    'api',
72
    'housing',
73
    'accounts',
Daniel W Bond's avatar
Daniel W Bond committed
74
    'welcome',
Daniel W Bond's avatar
Daniel W Bond committed
75
    # packages
76
77
    'crispy_forms',
    'django_gravatar',
Daniel W Bond's avatar
Daniel W Bond committed
78
    'analytical',
79
    'randomslugfield',
Daniel W Bond's avatar
Daniel W Bond committed
80
    'haystack',
81
    'multiselectfield',
82
    'rest_framework',
83
    # social media authentication
Jason D Yeomans's avatar
Jason D Yeomans committed
84
85
86
87
88
89
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.facebook',
    'allauth.socialaccount.providers.google',
    'allauth.socialaccount.providers.twitter',
90
    'allauth.socialaccount.providers.instagram',
91
92
93
94
    # 'allauth.socialaccount.providers.tumblr',
    # 'allauth.socialaccount.providers.spotify',
    # 'allauth.socialaccount.providers.github',
    # twitch? stackexchange? soundcloud?
95
96
)

97
98
CRISPY_TEMPLATE_PACK = 'bootstrap'

99
100
MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
101
    'django.contrib.sessions.middleware.SessionMiddleware',
102
    'django.contrib.auth.middleware.AuthenticationMiddleware',
Daniel W Bond's avatar
Daniel W Bond committed
103
    'cas.middleware.CASMiddleware',
104
    'django.contrib.admindocs.middleware.XViewMiddleware',
105
106

    'django.middleware.csrf.CsrfViewMiddleware',
107
108
109
110
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

111
112
113
114
# for bootstrap css classes
from django.contrib.messages import constants as messages
MESSAGE_TAGS = {messages.ERROR: 'danger',}

115
ROOT_URLCONF = 'settings.urls'
116

117
WSGI_APPLICATION = 'settings.wsgi.application'
118

119
from . import secret
120

121
122
SECRET_KEY = secret.SECRET_KEY

123
124
125
# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases

126
127
DATABASES = {
    'default': {
128
        'ENGINE': config.DB_ENGINE,
129
130
131
132
133
        'NAME': secret.DB_NAME,
        'USER': secret.DB_USER,
        'PASSWORD': secret.DB_PASSWORD,
        'HOST': secret.DB_HOST,
        'PORT': secret.DB_PORT,
134
135
136
137
    }
}

# Internationalization
138
# https://docs.djangoproject.com/en/1.7/topics/i18n/
139
140
141

LANGUAGE_CODE = 'en-us'

142
TIME_ZONE = 'America/New_York'
143
144
145
146
147
148
149

USE_I18N = True

USE_L10N = True

USE_TZ = True

150
# set for social auth
151
# example.com is by default set to 1
152

153
SITE_ID = 2
Daniel W Bond's avatar
Daniel W Bond committed
154

155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# further settings for social auth

SOCIALACCOUNT_ADAPTER = 'accounts.adapter.AccountAdapter'

SOCIALACCOUNT_PROVIDERS = {
    'facebook': {
        'SCOPE': ['public_profile', ],
        'FIELDS': [
            'id',
            'first_name',
            'last_name',
            'link',
            ]
        }
    }

171
# Static files (CSS, JavaScript, Images)
172
# https://docs.djangoproject.com/en/1.7/howto/static-files/
173
174

STATIC_URL = '/static/'
175

Jason D Yeomans's avatar
Jason D Yeomans committed
176
AUTHENTICATION_BACKENDS = (
177
    'django.contrib.auth.backends.ModelBackend',
Daniel W Bond's avatar
Daniel W Bond committed
178
    'cas.backends.CASBackend',
Jason D Yeomans's avatar
Jason D Yeomans committed
179
)
180

181
182
183
# Peoplefinder API for user creation
PF_URL = "http://api.srct.gmu.edu/pf/v1/"

Daniel W Bond's avatar
Daniel W Bond committed
184
CAS_SERVER_URL = 'https://login.gmu.edu'
185
186
CAS_LOGOUT_COMPLETELY = True
CAS_PROVIDE_URL_TO_LOGOUT = True
187

188
189
190
CAS_RESPONSE_CALLBACKS = (
    'accounts.cas_callbacks.create_user',
)
Daniel W Bond's avatar
Daniel W Bond committed
191
192
193
194
195
196
197
198
199
200
201
202
203

HAYSTACK_CONNECTIONS = {
    'default' : {
        'ENGINE' : 'haystack.backends.whoosh_backend.WhooshEngine',
        'PATH' : os.path.join(os.path.dirname(__file__), 'whoosh_index'),
    },
}

# Haystack Signal Processor
# The RealtimeSignalProcessor allows for objects to indexed as soon as
# they are created -- in real time.
HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'

204
205
206
207
208
209
210
# Use redis cache when not in local development
if DEBUG:
    pass
else:
    CACHES = {
        'default': {
            'BACKEND': 'redis_cache.RedisCache',
211
            # configure to redis port
212
213
            'LOCATION': '/var/run/redis/redis.sock',
        },
214
    }
Daniel W Bond's avatar
Daniel W Bond committed
215
216
217
218
219
220
221
222
223
224

# need to configure ADMINS email so that ERROR level logs (500 level exceptions)
# can be sent out

# https://docs.djangoproject.com/en/1.7/topics/logging/
# https://docs.djangoproject.com/en/1.7/howto/error-reporting/
# https://docs.python.org/2/library/logging.config.html#configuration-dictionary-schema

if not DEBUG:

225
226
227
228
229
230
231
    ADMINS = config.ADMINS
    SERVER_EMAIL = config.SERVER_EMAIL
    EMAIL_HOST = config.EMAIL_HOST
    EMAIL_PORT = config.EMAIL_PORT
    EMAIL_HOST_USER = config.EMAIL_HOST_USER
    EMAIL_HOST_PASSWORD = config.EMAIL_HOST_PASSWORD
    EMAIL_USE_SSL = config.EMAIL_USE_SSL
Daniel W Bond's avatar
Daniel W Bond committed
232
233
234
235
236
237

    LOGGING = {
        'version': 1,
        'disable_existing_loggers': False,
        'handlers': {
            'file': {
238
                'level': 'DEBUG', # will log all errors
Daniel W Bond's avatar
Daniel W Bond committed
239
240
241
242
243
                'class': 'logging.FileHandler',
                # make sure to change this to the proper path, and one that
                # can be written to
                'filename': '/path/to/django/debug.log',
            },
244
245
246
247
248
            # 'mail_admins' by default does not include a traceback attachment
            # setting 'include_html' to True will attach an html traceback file to the email
            # you can also set an addtional 'email_backend' arg to a custom email handler (e.g. SES)
            'mail_admins': {
                'level': 'ERROR',
249
                'class': 'django.utils.log.AdminEmailHandler',
250
251
                'include_html': True,
            },
Daniel W Bond's avatar
Daniel W Bond committed
252
253
254
255
256
257
258
259
        },
        # logs request errors
        'loggers': {
            'django.request': {
                'handlers': ['file'],
                'level': 'DEBUG',
                'propagate': True,
            },
260
261
        # django's default loggers send request and security messages at the ERROR
        # or CRITICAL level to the AdminEmailHandler via mail_admins
Daniel W Bond's avatar
Daniel W Bond committed
262
        },
263
    }