-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsettings.py
More file actions
executable file
·248 lines (201 loc) · 6.9 KB
/
settings.py
File metadata and controls
executable file
·248 lines (201 loc) · 6.9 KB
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
"""
Django settings for oh-fitbit-integration project.
Generated by 'django-admin startproject' using Django 2.0.2.
For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/
"""
import os
import dj_database_url
import logging
from requests_respectful import RespectfulRequester
logger = logging.getLogger(__name__)
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.getenv('SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False if os.getenv('DEBUG', '').lower() == 'false' else True
REMOTE = True if os.getenv('REMOTE', '').lower() == 'true' else False
ALLOWED_HOSTS = ['*']
# Check if running on Heroku. If so, force SSL.
ON_HEROKU = os.getenv('ON_HEROKU', 'false').lower() == 'true'
if ON_HEROKU:
SECURE_SSL_REDIRECT = True
HEROKUCONFIG_APP_NAME = os.getenv('HEROKUCONFIG_APP_NAME', '')
DEFAULT_BASE_URL = ('https://{}.herokuapp.com'.format(HEROKUCONFIG_APP_NAME) if
REMOTE else 'http://127.0.0.1:5000')
OPENHUMANS_APP_BASE_URL = os.getenv('APP_BASE_URL', DEFAULT_BASE_URL)
if OPENHUMANS_APP_BASE_URL[-1] == "/":
OPENHUMANS_APP_BASE_URL = OPENHUMANS_APP_BASE_URL[:-1]
# Open Humans configuration
OPENHUMANS_CLIENT_ID = os.getenv('OH_CLIENT_ID')
OPENHUMANS_CLIENT_SECRET = os.getenv('OH_CLIENT_SECRET')
OH_ACTIVITY_PAGE = os.getenv('OH_ACTIVITY_PAGE')
OPENHUMANS_OH_BASE_URL = 'https://www.openhumans.org'
OH_API_BASE = OPENHUMANS_OH_BASE_URL + '/api/direct-sharing'
OH_DIRECT_UPLOAD = OH_API_BASE + '/project/files/upload/direct/'
OH_DIRECT_UPLOAD_COMPLETE = OH_API_BASE + '/project/files/upload/complete/'
OH_DELETE_FILES = OH_API_BASE + '/project/files/delete/'
# Fitbit configuration
FITBIT_CLIENT_ID=os.getenv('FITBIT_CLIENT_ID')
FITBIT_CLIENT_SECRET=os.getenv('FITBIT_CLIENT_SECRET')
from urllib.parse import urlparse
url_object = urlparse(os.getenv('REDIS_URL'))
logger.info('Connecting to redis at %s:%s',
url_object.hostname,
url_object.port)
RespectfulRequester.configure(
redis={
"host": url_object.hostname,
"port": url_object.port,
"password": url_object.password,
"database": 0
},
safety_threshold=5)
# Requests Respectful (rate limiting, waiting)
rr = RespectfulRequester()
rr.register_realm("Fitbit", max_requests=3600, timespan=3600)
if REMOTE is False:
FITBIT_CALLBACK_URL = 'http://127.0.0.1:5000/complete/fitbit'
else:
FITBIT_CALLBACK_URL =\
'http://oh-fitbit-integration.herokuapp.com/complete/fitbit'
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'raven.contrib.django.raven_compat',
'datauploader.apps.DatauploaderConfig',
'open_humans.apps.OpenHumansConfig',
'main.apps.MainConfig',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware'
]
ROOT_URLCONF = 'fitbit.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'fitbit.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
if REMOTE:
db_from_env = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(db_from_env)
# Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': ('django.contrib.auth.password_validation.'
'UserAttributeSimilarityValidator'),
},
{
'NAME': ('django.contrib.auth.password_validation.'
'MinimumLengthValidator'),
},
{
'NAME': ('django.contrib.auth.password_validation.'
'CommonPasswordValidator'),
},
{
'NAME': ('django.contrib.auth.password_validation.'
'NumericPasswordValidator'),
},
]
# Configure logging to print Django logs to the console.
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'root': {
'level': 'WARNING',
'handlers': ['sentry'],
},
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s '
'%(process)d %(thread)d %(message)s'
},
},
'handlers': {
'sentry': {
'level': 'ERROR',
'class':
'raven.contrib.django.raven_compat.handlers.SentryHandler',
'tags': {'custom-tag': 'x'},
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose'
}
},
'loggers': {
'django.db.backends': {
'level': 'ERROR',
'handlers': ['console'],
'propagate': False,
},
'raven': {
'level': 'DEBUG',
'handlers': ['console'],
'propagate': False,
},
'sentry.errors': {
'level': 'DEBUG',
'handlers': ['console'],
'propagate': False,
},
},
}
# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Setry/Raven setup for error tracking
RAVEN_CONFIG = {
'dsn': os.getenv('RAVEN_DSN'),
'CELERY_LOGLEVEL': logging.INFO
}
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'