/
settings_global.py
515 lines (445 loc) · 12.9 KB
/
settings_global.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
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
# -*- coding: utf-8 -*-
# This file is part of wger Workout Manager.
#
# wger Workout Manager is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# wger Workout Manager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# Standard Library
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
import re
from datetime import timedelta
"""
This file contains the global settings that don't usually need to be changed.
For a full list of options, visit:
https://docs.djangoproject.com/en/dev/ref/settings/
"""
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
SITE_ROOT = os.path.realpath(os.path.dirname(__file__))
#
# Application definition
#
SITE_ID = 1
ROOT_URLCONF = 'wger.urls'
WSGI_APPLICATION = 'wger.wsgi.application'
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.messages',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.staticfiles',
'django_extensions',
'storages',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Apps from wger proper
'wger.config',
'wger.core',
'wger.mailer',
'wger.exercises',
'wger.gym',
'wger.manager',
'wger.nutrition',
'wger.software',
'wger.utils',
'wger.weight',
'wger.gallery',
'wger.measurements',
# reCaptcha support, see https://github.com/praekelt/django-recaptcha
'captcha',
# The sitemaps app
'django.contrib.sitemaps',
# thumbnails
'easy_thumbnails',
# CSS/JS compressor
'compressor',
# Form renderer helper
'crispy_forms',
# REST-API
'rest_framework',
'rest_framework.authtoken',
'django_filters',
'rest_framework_simplejwt',
# Breadcrumbs
'django_bootstrap_breadcrumbs',
# CORS
'corsheaders',
# Django Axes
'axes',
# History keeping
'simple_history',
# Django email verification
'django_email_verification',
# Activity stream
'actstream',
# Fontawesome
'fontawesomefree',
)
MIDDLEWARE = (
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
# Django Admin
'django.contrib.auth.middleware.AuthenticationMiddleware',
# Javascript Header. Sends helper headers for AJAX
'wger.utils.middleware.JavascriptAJAXRedirectionMiddleware',
# Custom authentication middleware. Creates users on-the-fly for certain paths
'wger.utils.middleware.WgerAuthenticationMiddleware',
# Send an appropriate Header so search engines don't index pages
'wger.utils.middleware.RobotsExclusionMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.locale.LocaleMiddleware',
# History keeping
'simple_history.middleware.HistoryRequestMiddleware',
# Django Axes
'axes.middleware.AxesMiddleware', # should be the last one in the list
)
AUTHENTICATION_BACKENDS = (
'axes.backends.AxesStandaloneBackend', # should be the first one in the list
'django.contrib.auth.backends.ModelBackend',
'wger.utils.helpers.EmailAuthBackend',
)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
# 'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'wger.utils.context_processor.processor',
# Django
'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',
# Breadcrumbs
'django.template.context_processors.request'
],
'loaders': [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
],
'debug':
False
},
},
]
# Store the user messages in the session
MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage'
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# Django compressor
'compressor.finders.CompressorFinder',
)
#
# Email
#
EMAIL_SUBJECT_PREFIX = '[wger] '
# EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
#
# Login
#
LOGIN_URL = '/user/login'
LOGIN_REDIRECT_URL = '/'
#
# Internationalization
#
USE_TZ = True
USE_I18N = True
USE_L10N = True
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'UTC'
# Restrict the available languages
LANGUAGES = (
('en', 'English'),
('de', 'German'),
('bg', 'Bulgarian'),
('es', 'Spanish'),
('ru', 'Russian'),
('nl', 'Dutch'),
('pt', 'Portuguese'),
('el', 'Greek'),
('cs', 'Czech'),
('sv', 'Swedish'),
('no', 'Norwegian'),
('fr', 'French'),
('it', 'Italian'),
('pl', 'Polish'),
('uk', 'Ukrainian'),
('tr', 'Turkish'),
)
# Default language code for this installation.
LANGUAGE_CODE = 'en'
# All translation files are in one place
LOCALE_PATHS = (os.path.join(SITE_ROOT, 'locale'), )
# Primary keys are AutoFields
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
#
# Logging
# See http://docs.python.org/library/logging.config.html
#
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'simple': {
'format': '%(levelname)s %(asctime)s %(module)s %(message)s'
},
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'simple'
},
},
'loggers': {
'wger': {
'handlers': ['console'],
'level': 'DEBUG',
}
}
}
#
# ReCaptcha
#
RECAPTCHA_USE_SSL = True
#
# Cache
#
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': 'wger-cache',
'TIMEOUT': 30 * 24 * 60 * 60, # Cache for a month
}
}
#
# Django Axes
#
AXES_ENABLED = True
AXES_FAILURE_LIMIT = 5
AXES_COOLOFF_TIME = 0.5 # in hours
AXES_LOCKOUT_TEMPLATE = None
AXES_RESET_ON_SUCCESS = False
AXES_RESET_COOL_OFF_ON_FAILURE_DURING_LOCKOUT = True
# If you want to set up redis, set AXES_HANDLER = 'axes.handlers.cache.AxesCacheHandler'
AXES_HANDLER = 'axes.handlers.database.AxesDatabaseHandler'
# If your redis or MemcachedCache has a different name other than 'default'
# (e.g. when you have multiple caches defined in CACHES), change the following value to that name
AXES_CACHE = 'default'
#
# Django Crispy Templates
#
CRISPY_TEMPLATE_PACK = 'bootstrap4'
#
# Easy thumbnails
#
THUMBNAIL_ALIASES = {
'': {
'micro': {
'size': (30, 30)
},
'micro_cropped': {
'size': (30, 30),
'crop': 'smart'
},
'thumbnail': {
'size': (80, 80)
},
'thumbnail_cropped': {
'size': (80, 80),
'crop': 'smart'
},
'small': {
'size': (200, 200)
},
'small_cropped': {
'size': (200, 200),
'crop': 'smart'
},
'medium': {
'size': (400, 400)
},
'medium_cropped': {
'size': (400, 400),
'crop': 'smart'
},
'large': {
'size': (800, 800),
'quality': 90
},
'large_cropped': {
'size': (800, 800),
'crop': 'smart',
'quality': 90
},
},
}
STATIC_ROOT = ''
USE_S3 = os.getenv('USE_S3') == 'TRUE'
if USE_S3:
# aws settings
AWS_ACCESS_KEY_ID = os.getenv('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.getenv('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = os.getenv('AWS_STORAGE_BUCKET_NAME')
AWS_DEFAULT_ACL = 'public-read'
AWS_S3_CUSTOM_DOMAIN = os.getenv('WGER_CDN_DOMAIN')
AWS_S3_OBJECT_PARAMETERS = {'CacheControl': 'max-age=31557600'}
# s3 static settings
AWS_LOCATION = 'static'
STATIC_URL = 'https://%s/%s/' % (AWS_S3_CUSTOM_DOMAIN, AWS_LOCATION)
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
COMPRESS_URL = STATIC_URL
COMPRESS_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
COMPRESS_OFFLINE = True
COMPRESS_OFFLINE_CONTEXT = [
{
'request': {
'user_agent': {
'is_mobile': True
}
},
'STATIC_URL': STATIC_URL
}, {
'request': {
'user_agent': {
'is_mobile': False
}
},
'STATIC_URL': STATIC_URL
}
]
else:
STATIC_URL = '/static/'
#
# Django compressor
#
# The default is not DEBUG, override if needed
# COMPRESS_ENABLED = True
COMPRESS_CSS_FILTERS = (
'compressor.filters.css_default.CssAbsoluteFilter', 'compressor.filters.cssmin.rCSSMinFilter'
)
COMPRESS_JS_FILTERS = [
'compressor.filters.jsmin.JSMinFilter',
'compressor.filters.template.TemplateFilter',
]
COMPRESS_ROOT = STATIC_ROOT
#
# Django Rest Framework
#
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': ('wger.utils.permissions.WgerPermission',),
'DEFAULT_PAGINATION_CLASS':
'rest_framework.pagination.LimitOffsetPagination',
'PAGE_SIZE':
20,
'PAGINATE_BY_PARAM':
'limit', # Allow client to override, using `?limit=xxx`.
'TEST_REQUEST_DEFAULT_FORMAT':
'json',
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
'rest_framework_simplejwt.authentication.JWTAuthentication',
),
'DEFAULT_FILTER_BACKENDS': (
'django_filters.rest_framework.DjangoFilterBackend',
'rest_framework.filters.OrderingFilter',
),
'DEFAULT_THROTTLE_CLASSES': ['rest_framework.throttling.ScopedRateThrottle'],
'DEFAULT_THROTTLE_RATES': {
'login': '3/min'
}
}
#
# Django Rest Framework SimpleJWT
#
SIMPLE_JWT = {
'ACCESS_TOKEN_LIFETIME': timedelta(minutes=5),
'REFRESH_TOKEN_LIFETIME': timedelta(days=1),
'ROTATE_REFRESH_TOKENS': False,
'BLACKLIST_AFTER_ROTATION': False,
'UPDATE_LAST_LOGIN': False,
}
#
# CORS headers: allow all hosts to access the API
#
CORS_ORIGIN_ALLOW_ALL = True
CORS_URLS_REGEX = r'^/api/.*$'
#
# Ignore these URLs if they cause 404
#
IGNORABLE_404_URLS = (re.compile(r'^/favicon\.ico$'),)
#
# Password rules
#
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',
},
]
USER_AGENTS_CACHE = 'default'
#
# Application specific configuration options
#
# Consult docs/settings.rst for more information
#
WGER_SETTINGS = {
'ALLOW_GUEST_USERS': True,
'ALLOW_REGISTRATION': True,
'ALLOW_UPLOAD_VIDEOS': False,
'EMAIL_FROM': 'wger Workout Manager <wger@example.com>',
'EXERCISE_CACHE_TTL': 3600,
'TWITTER': False,
'USE_RECAPTCHA': False
}
#
# Django email verification
#
def email_verified_callback(user):
user.userprofile.email_verified = True
user.userprofile.save()
EMAIL_VERIFIED_CALLBACK = email_verified_callback
EMAIL_FROM_ADDRESS = WGER_SETTINGS['EMAIL_FROM']
EMAIL_MAIL_SUBJECT = 'Confirm your email'
EMAIL_MAIL_HTML = 'email_verification/email_body_html.tpl'
EMAIL_MAIL_PLAIN = 'email_verification/email_body_txt.tpl'
EMAIL_MAIL_TOKEN_LIFE = 60 * 60
EMAIL_MAIL_PAGE_TEMPLATE = 'email_verification/confirm_template.html'
EMAIL_PAGE_DOMAIN = 'http://localhost:8000/'
#
# Django activity stream
#
ACTSTREAM_SETTINGS = {
'USE_JSONFIELD': True,
}