-
Notifications
You must be signed in to change notification settings - Fork 5
/
base.py
202 lines (155 loc) · 5.03 KB
/
base.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import sys
import os
from os.path import join, abspath, dirname
from celery.schedules import crontab
from kombu import Exchange, Queue
# PATH vars
here = lambda *x: join(abspath(dirname(__file__)), *x)
PROJECT_ROOT = here("..")
root = lambda *x: join(abspath(PROJECT_ROOT), *x)
sys.path.insert(0, root('apps'))
ADMINS = (
('Ross Blair', 'rblair2@stanford.edu'),
)
MANAGERS = ADMINS
DEFAULT_FROM_EMAIL = "admin@openfmri.org"
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', '')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ.get('DJANGO_DEBUG', False)
ALLOWED_HOSTS = os.environ.get('DJANGO_ALLOWED_HOSTS', '')
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'django.contrib.flatpages'
)
PROJECT_APPS = (
'contact',
'dataset',
'log_parse',
)
THIRD_PARTY_APPS = (
'ckeditor',
'contact_form',
'crispy_forms',
'djcelery',
'opbeat.contrib.django',
'rest_framework',
)
INSTALLED_APPS += PROJECT_APPS
INSTALLED_APPS += THIRD_PARTY_APPS
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
root('templates'),
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'dataset.context_processors.featured_dataset_processor',
'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',
],
},
},
]
ROOT_URLCONF = 'open_fmri.urls'
LOGIN_REDIRECT_URL = '/dataset/'
SITE_ID = 1
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'open_fmri.wsgi.application'
# Moved database settings into base since any testing we do within docker
# will be pulling from the same env file. Any non docker can override in
# the relevant configuration file.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.environ.get('POSTGRES_NAME', ''),
'USER': os.environ.get('POSTGRES_USER', ''),
'PASSWORD': os.environ.get('POSTGRES_PASSWORD', ''),
'HOST': os.environ.get('POSTGRES_HOST', ''),
'PORT': os.environ.get('POSTGRES_PORT', ''),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC' # 'Europe/London'
USE_I18N = False
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = '/var/www/static/'
MEDIA_ROOT = root('assets', 'uploads')
MEDIA_URL = '/media/'
LOGIN_URL = '/login/'
# Additional locations of static files
STATICFILES_DIRS = (
root('assets'),
)
EMAIL_HOST = os.environ.get("EMAIL_HOST", '')
EMAIL_PORT = os.environ.get("EMAIL_PORT", '')
EMAIL_HOST_USER = os.environ.get("EMAIL_HOST_USER", '')
EMAIL_HOST_PASSWORD = os.environ.get("EMAIL_HOST_PASSWORD", '')
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
),}
CKEDITOR_CONFIGS = {
'default': {
'width': '100%',
},
}
OPBEAT = {
'ORGANIZATION_ID': os.environ.get('OPBEAT_ORGANIZATION_ID', ''),
'APP_ID': os.environ.get('OPBEAT_APP_ID', ''),
'SECRET_TOKEN': os.environ.get('OPBEAT_SECRET_TOKEN', ''),
}
# Celery config
BROKER_URL = 'redis://redis:6379/0'
CELERY_RESULT_BACKEND = 'djcelery.backends.database:DatabaseBackend'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_DEFAULT_QUEUE = 'default'
CELERY_QUEUES = (
Queue('default', Exchange('default'), routing_key='default'),
)
if os.environ.get('RUN_TASKS', False):
CELERYBEAT_SCHEDULE = {
'Parse Logs': {
'task': 'log_parse_task',
'schedule': crontab()
},
}
# .local.py overrides all the common settings.
try:
from .local import *
except ImportError:
pass
# importing test settings file if necessary
if len(sys.argv) > 1 and 'test' in sys.argv[1]:
from .testing import *