forked from Unicaronas/Unicaronas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.py
442 lines (345 loc) · 13.6 KB
/
settings.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
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
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
"""
Django settings for unicaronas_api project.
Generated by 'django-admin startproject' using Django 2.0.4.
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 sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
# Website root url
ROOT_URL = os.environ.get('ROOT_URL', 'http://localhost:8000')
# Project name
PROJECT_NAME = os.environ.get('PROJECT_NAME', 'Unicaronas')
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production a secret!
SECRET_KEY = os.environ.get('DJANGO_SECRET', 'abc123')
# 256 bit prime
SECRET_PRIME = int(os.environ.get('SECRET_PRIME', '1'))
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = eval(os.environ.get('DEBUG', 'False').capitalize())
# manage.py test mode that disables fb connection stuff
TEST_MODE = eval(os.environ.get('TEST_MODE', 'False').capitalize())
ALLOWED_HOSTS = eval(os.environ.get('ALLOWED_HOSTS', '["*"]'))
# Sentry
if not DEBUG and os.environ.get('SENTRY_DSN'):
sentry_sdk.init(
dsn=os.environ.get('SENTRY_DSN'),
integrations=[DjangoIntegration()]
)
# Application definition
INSTALLED_APPS = [
'scout_apm.django',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'whitenoise.runserver_nostatic',
'django.contrib.staticfiles',
'django.contrib.sites',
'django.contrib.gis',
'django.contrib.humanize',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.facebook',
'allauth.socialaccount.providers.github',
'allauth.socialaccount.providers.google',
'oauth',
'user_data',
'trips',
'search',
'third_parties',
'alarms',
'maintenance_mode',
'debug_toolbar',
'oauth2_provider',
'rest_framework',
'rest_framework_filters',
'django_extensions',
'captcha',
'analytical',
'drf_yasg',
'silk',
'nplusone.ext.django',
'djcelery_email',
'phonenumber_field',
'watchman',
'storages',
'versatileimagefield',
]
MIDDLEWARE = [
'silk.middleware.SilkyMiddleware',
'nplusone.ext.django.NPlusOneMiddleware',
'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',
'debug_toolbar.middleware.DebugToolbarMiddleware',
'maintenance_mode.middleware.MaintenanceModeMiddleware',
]
ROOT_URLCONF = 'project.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(PROJECT_ROOT, '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',
'project.context_processors.fb_handle',
],
},
},
]
WSGI_APPLICATION = 'project.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'),
}
}
# 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',
},
]
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
# `allauth` specific authentication methods, such as login by e-mail
'allauth.account.auth_backends.AuthenticationBackend',
)
# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/
LANGUAGE_CODE = 'pt-br'
TIME_ZONE = 'America/Sao_Paulo'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
STATICFILES_DIRS = (
os.path.join(PROJECT_ROOT, 'static'),
)
STATIC_HOST = os.environ.get('STATIC_HOST', ROOT_URL)
STATIC_URL = STATIC_HOST + '/static/'
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = os.environ.get('AWS_STORAGE_BUCKET_NAME')
AWS_AUTO_CREATE_BUCKET = True
# Celery stuff
REDIS_URL = os.environ.get('REDIS_URL', 'redis://localhost:6379/0')
CELERY_BROKER_URL = REDIS_URL
CELERY_IMPORTS = ['project.tasks']
# Cache settings
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': 'unique-snowflake',
}
}
# Update database configuration with $DATABASE_URL.
db_from_env = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(db_from_env)
DATABASES['default']['ENGINE'] = 'django.contrib.gis.db.backends.postgis'
# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# Email settings
EMAIL_HOST_USER = os.environ.get('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD')
EMAIL_USE_TLS = eval(os.environ.get('EMAIL_USE_TLS', 'True'))
EMAIL_HOST = os.environ.get('EMAIL_HOST', 'smtp.gmail.com')
EMAIL_PORT = int(os.environ.get('EMAIL_PORT', '587'))
DEFAULT_FROM_EMAIL = os.environ.get('DEFAULT_FROM_EMAIL', EMAIL_HOST_USER)
DEFAULT_CONTACT_EMAIL = os.environ.get('DEFAULT_CONTACT_EMAIL', EMAIL_HOST_USER)
SERVER_EMAIL = os.environ.get('SERVER_EMAIL', EMAIL_HOST_USER)
ADMINS = [('Admin', os.environ.get('ADMIN_ACCOUNT')), ]
EMAIL_BACKEND = 'djcelery_email.backends.CeleryEmailBackend'
# Debug Toolbar
SHOW_TOOLBAR_CALLBACK = eval(os.environ.get('SHOW_TOOLBAR_CALLBACK', DEBUG))
DEBUG_TOOLBAR_CONFIG = {
'SHOW_TOOLBAR_CALLBACK': lambda r: SHOW_TOOLBAR_CALLBACK and r.user.is_superuser # disables it
}
# Maintenance mode
MAINTENANCE_MODE = eval(os.environ.get('MAINTENANCE_MODE', 'False'))
MAINTENANCE_MODE_TEMPLATE = 'project/errors/503.html'
MAINTENANCE_MODE_IGNORE_ADMIN_SITE = True
MAINTENANCE_MODE_IGNORE_SUPERUSER = True
# OAuth2
OAUTH2_PROVIDER = {
# this is the list of available scopes
'SCOPES': {
'basic:read': 'Seu primeiro e segundo nome',
'profile:read': 'Seu aniversário e gênero',
'phone:read': 'Seu número de celular',
'email:read': 'Seu endereço de email principal e acadêmico',
'student:read': 'Seu perfil de aluno na sua universidade',
'driver:read': 'Informações sobre seu carro',
'driver:preferences:read': 'Suas preferências como motorista',
'alarms:read': 'Detalhes sobre os alarmes de caronas criados por você',
'alarms:write': 'Criar, editar e apagar seus alarmes de caronas',
'trips:read': 'Pesquisar caronas por você',
'trips:driver:read': 'Detalhes sobre as caronas, e seus passageiros, em que você é motorista',
'trips:driver:write': 'Criar, editar e apagar as caronas em que você é motorista e gerenciar seus passageiros',
'trips:passenger:read': 'Informações sobre as caronas em que você é passageiro',
'trips:passenger:write': 'Entrar e sair de caronas por você'
},
"DEFAULT_SCOPES": ['basic:read'],
'REQUEST_APPROVAL_PROMPT': 'auto',
'APPLICATION_MODEL': 'oauth.Application',
'SCOPES_BACKEND_CLASS': 'oauth.scopes.CustomSettingsScopes',
"REFRESH_TOKEN_GRACE_PERIOD_SECONDS": 120,
"ACCESS_TOKEN_EXPIRE_SECONDS": 3600,
}
OAUTH2_PROVIDER_APPLICATION_MODEL = 'oauth.Application'
# Rest settings
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
'rest_framework.authentication.TokenAuthentication',
'rest_framework.authentication.SessionAuthentication',
),
'DEFAULT_PAGINATION_CLASS': 'project.pagination.CustomLimitOffsetPagination',
# 'DEFAULT_PERMISSION_CLASSES': ['rest_framework.permissions.IsAdminUser'],
'EXCEPTION_HANDLER': 'project.exceptions.custom_exception_handler',
'DEFAULT_VERSIONING_CLASS': 'rest_framework.versioning.NamespaceVersioning',
'DEFAULT_VERSION': 'v1.0',
'ALLOWED_VERSIONS': ['v1.0'],
'DEFAULT_THROTTLE_CLASSES': (
'project.throttling.ApplicationBurstRateThrottle',
'project.throttling.ApplicationSustainedRateThrottle',
),
'DEFAULT_THROTTLE_RATES': {
'application_burst': '60/min', # Burst application calls
'application_sustained': '10000/day', # Sustained application calls
}
}
# Sites framework
SITE_ID = int(os.environ.get('SITE_ID', '1'))
# AllAuth settings
ACCOUNT_AUTHENTICATION_METHOD = "username"
ACCOUNT_PRESERVE_USERNAME_CASING = False
ACCOUNT_SESSION_REMEMBER = True
ACCOUNT_CONFIRM_EMAIL_ON_GET = True
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
ACCOUNT_DEFAULT_HTTP_PROTOCOL = "http" if DEBUG else "https"
ACCOUNT_FORMS = {
'signup': 'user_data.forms.CustomSignupForm',
'login': 'user_data.forms.CustomLoginForm',
}
SOCIALACCOUNT_FORMS = {
'signup': 'user_data.forms.CustomSocialSignupForm'
}
ACCOUNT_SIGNUP_FORM_CLASS = 'user_data.forms2.ExtraSignupFields'
ACCOUNT_LOGIN_ON_EMAIL_CONFIRMATION = True
def ACCOUNT_USER_DISPLAY(user):
return user.first_name
SOCIALACCOUNT_AUTO_SIGNUP = False
ACCOUNT_LOGOUT_ON_GET = True
# Captcha Settings
NOCAPTCHA = True
RECAPTCHA_PUBLIC_KEY = os.environ.get('RECAPTCHA_PUBLIC_KEY')
RECAPTCHA_PRIVATE_KEY = os.environ.get('RECAPTCHA_PRIVATE_KEY')
# Documentation settings
SWAGGER_SETTINGS = {
'DEFAULT_AUTO_SCHEMA_CLASS': 'project.swagger_schema.CustomTagAutoSchema',
'USE_SESSION_AUTH': False,
'SECURITY_DEFINITIONS': {
'OAuth2': {
'type': 'oauth2',
'description': """
OAuth2 é uma forma de autenticação que permite que seu aplicativo obtenha acesso granular aos dados dos seus usuários. Seu usuário tem controle total sobre quais informações deseja compartilhar e você acessa a API usando endpoints comuns HTTP. OAuth2 possui flows para aplicativos web, desktop e mobile, todos implementados na API do Unicaronas. Para saber mais, [visite o guia de OAuth2](/what_is_oauth/)
Abaixo você encontrará os `scopes` disponíveis e suas descrições, além das URLs de autorização e troca de tokens.""",
'authorizationUrl': f'{ROOT_URL}/o/authorize/',
'tokenUrl': f'{ROOT_URL}/o/token/',
'flow': 'accessCode',
'scopes': OAUTH2_PROVIDER['SCOPES']
}
},
'OAUTH2_CONFIG': {
'clientId': '9hzg1FNkZPeR1761B460TTDyYH8dkfjkzTXgYuaz',
'clientSecret': 'Bg76qkj0ci7gPCtWrqvZniVkuh1KAYpVKcWzq4o1ryDtWu60qHJDg50a7bkSxEHFUVPGSvRnPPBvc6zEle5jKrlpb7n0jX8p7ulL5HBE9OP1S7mwZabHTRBP7SL1OACQ',
'appName': 'Seu aplicativo'
},
}
# Phonenumbers
PHONENUMBER_DB_FORMAT = 'NATIONAL'
PHONENUMBER_DEFAULT_REGION = 'BR'
# Geocoding API
GEOCODING_API_KEY = os.environ.get('GEOCODING_API_KEY')
# Analytics
GOOGLE_ANALYTICS_PROPERTY_ID = os.environ.get('GOOGLE_ANALYTICS_PROPERTY_ID')
GOOGLE_ANALYTICS_SITE_SPEED = True
# Profiling
SILKY_PYTHON_PROFILER = True
SILKY_AUTHENTICATION = True
SILKY_AUTHORISATION = True
SILKY_PERMISSIONS = lambda user: user.is_superuser
SILKY_META = True
SILKY_MAX_RECORDED_REQUESTS = 10**3
SILKY_INTERCEPT_PERCENT = 30
# Watchman
WATCHMAN_CHECKS = (
'project.status_checks.redis_check',
'project.status_checks.celery_check',
'project.status_checks.google_apis',
'project.status_checks.facebook',
'project.status_checks.blablacar',
'project.status_checks.email',
'watchman.checks.databases',
'watchman.checks.caches',
'watchman.checks.storage',
)
WATCHMAN_ENABLE_PAID_CHECKS = not DEBUG
# Scout settings
SCOUT_MONITOR = not DEBUG
SCOUT_KEY = os.environ.get('SCOUT_KEY')
SCOUT_NAME = "Unicaronas"
# Email variables
FACEBOOK_HANDLE = os.environ.get('FACEBOOK_HANDLE', 'Unicaronas2.0')
# BlaBlaCar API Key
BLABLACAR_API_KEY = os.environ.get('BLABLACAR_API_KEY')
# Get GDAL_LIBRARY_PATH from env during heroku's build
_GDAL_LIBRARY_PATH = os.getenv('GDAL_LIBRARY_PATH', None)
if _GDAL_LIBRARY_PATH:
GDAL_LIBRARY_PATH = _GDAL_LIBRARY_PATH
_GEOS_LIBRARY_PATH = os.getenv('GEOS_LIBRARY_PATH', None)
if _GEOS_LIBRARY_PATH:
GEOS_LIBRARY_PATH = _GEOS_LIBRARY_PATH