/
base.py
699 lines (625 loc) · 22.8 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
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
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
# pylint: disable=missing-docstring
import logging
import os
import subprocess
import socket
from celery.schedules import crontab
from readthedocs.core.settings import Settings
from readthedocs.projects.constants import CELERY_LOW, CELERY_MEDIUM, CELERY_HIGH
try:
import readthedocsext # noqa
ext = True
except ImportError:
ext = False
_ = gettext = lambda s: s
log = logging.getLogger(__name__)
class CommunityBaseSettings(Settings):
"""Community base settings, don't use this directly."""
# Django settings
SITE_ID = 1
ROOT_URLCONF = 'readthedocs.urls'
LOGIN_REDIRECT_URL = '/dashboard/'
FORCE_WWW = False
SECRET_KEY = 'replace-this-please' # noqa
ATOMIC_REQUESTS = True
# Debug settings
DEBUG = True
# Domains and URLs
RTD_IS_PRODUCTION = False
PRODUCTION_DOMAIN = 'readthedocs.org'
PUBLIC_DOMAIN = None
PUBLIC_DOMAIN_USES_HTTPS = False
USE_SUBDOMAIN = False
PUBLIC_API_URL = 'https://{}'.format(PRODUCTION_DOMAIN)
RTD_EXTERNAL_VERSION_DOMAIN = 'external-builds.readthedocs.io'
# Doc Builder Backends
MKDOCS_BACKEND = 'readthedocs.doc_builder.backends.mkdocs'
SPHINX_BACKEND = 'readthedocs.doc_builder.backends.sphinx'
# slumber settings
SLUMBER_API_HOST = 'https://readthedocs.org'
SLUMBER_USERNAME = None
SLUMBER_PASSWORD = None
# Email
DEFAULT_FROM_EMAIL = 'no-reply@readthedocs.org'
SERVER_EMAIL = DEFAULT_FROM_EMAIL
SUPPORT_EMAIL = None
# Sessions
SESSION_COOKIE_DOMAIN = 'readthedocs.org'
SESSION_COOKIE_HTTPONLY = True
SESSION_COOKIE_AGE = 30 * 24 * 60 * 60 # 30 days
SESSION_SAVE_EVERY_REQUEST = True
# This cookie is used in cross-origin API requests from *.readthedocs.io to readthedocs.org
SESSION_COOKIE_SAMESITE = None
# CSRF
CSRF_COOKIE_HTTPONLY = True
CSRF_COOKIE_AGE = 30 * 24 * 60 * 60
# Security & X-Frame-Options Middleware
# https://docs.djangoproject.com/en/1.11/ref/middleware/#django.middleware.security.SecurityMiddleware
SECURE_BROWSER_XSS_FILTER = True
SECURE_CONTENT_TYPE_NOSNIFF = True
SECURE_REFERRER_POLICY = "strict-origin-when-cross-origin"
X_FRAME_OPTIONS = 'DENY'
# Content Security Policy
# https://django-csp.readthedocs.io/
CSP_BLOCK_ALL_MIXED_CONTENT = True
CSP_DEFAULT_SRC = None # This could be improved
CSP_FRAME_ANCESTORS = ("'none'",)
CSP_OBJECT_SRC = ("'none'",)
CSP_REPORT_URI = None
CSP_REPORT_ONLY = True # Set to false to enable CSP in blocking mode
CSP_EXCLUDE_URL_PREFIXES = (
"/admin/",
)
# Read the Docs
READ_THE_DOCS_EXTENSIONS = ext
RTD_LATEST = 'latest'
RTD_LATEST_VERBOSE_NAME = 'latest'
RTD_STABLE = 'stable'
RTD_STABLE_VERBOSE_NAME = 'stable'
RTD_CLEAN_AFTER_BUILD = False
RTD_MAX_CONCURRENT_BUILDS = 4
RTD_BUILD_STATUS_API_NAME = 'docs/readthedocs'
# Database and API hitting settings
DONT_HIT_API = False
DONT_HIT_DB = True
USER_MATURITY_DAYS = 7
# override classes
CLASS_OVERRIDES = {}
DOC_PATH_PREFIX = '_/'
# Application classes
@property
def INSTALLED_APPS(self): # noqa
apps = [
'django.contrib.auth',
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.staticfiles',
'django.contrib.messages',
'django.contrib.humanize',
# third party apps
'dj_pagination',
'taggit',
'django_gravatar',
'rest_framework',
'rest_framework.authtoken',
'corsheaders',
'textclassifier',
'annoying',
'django_extensions',
'crispy_forms',
'messages_extends',
'django_elasticsearch_dsl',
'django_filters',
'polymorphic',
# our apps
'readthedocs.projects',
'readthedocs.organizations',
'readthedocs.builds',
'readthedocs.core',
'readthedocs.doc_builder',
'readthedocs.oauth',
'readthedocs.redirects',
'readthedocs.rtd_tests',
'readthedocs.api.v2',
'readthedocs.api.v3',
'readthedocs.gold',
'readthedocs.payments',
'readthedocs.notifications',
'readthedocs.integrations',
'readthedocs.analytics',
'readthedocs.sphinx_domains',
'readthedocs.search',
# allauth
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.github',
'allauth.socialaccount.providers.gitlab',
'allauth.socialaccount.providers.bitbucket',
'allauth.socialaccount.providers.bitbucket_oauth2',
]
if ext:
apps.append('django_countries')
apps.append('readthedocsext.cdn')
apps.append('readthedocsext.donate')
apps.append('readthedocsext.embed')
apps.append('readthedocsext.spamfighting')
return apps
@property
def USE_PROMOS(self): # noqa
return 'readthedocsext.donate' in self.INSTALLED_APPS
MIDDLEWARE = (
'readthedocs.core.middleware.ReadTheDocsSessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'dj_pagination.middleware.PaginationMiddleware',
'corsheaders.middleware.CorsMiddleware',
'csp.middleware.CSPMiddleware',
'readthedocs.core.middleware.ReferrerPolicyMiddleware',
)
AUTHENTICATION_BACKENDS = (
# Needed to login by username in Django admin, regardless of `allauth`
'django.contrib.auth.backends.ModelBackend',
# `allauth` specific authentication methods, such as login by e-mail
'allauth.account.auth_backends.AuthenticationBackend',
)
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
'OPTIONS': {
'min_length': 9,
}
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
MESSAGE_STORAGE = 'readthedocs.notifications.storages.FallbackUniqueStorage'
NOTIFICATION_BACKENDS = [
'readthedocs.notifications.backends.EmailBackend',
'readthedocs.notifications.backends.SiteBackend',
]
# Paths
SITE_ROOT = os.path.dirname(
os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
TEMPLATE_ROOT = os.path.join(SITE_ROOT, 'readthedocs', 'templates')
DOCROOT = os.path.join(SITE_ROOT, 'user_builds')
LOGS_ROOT = os.path.join(SITE_ROOT, 'logs')
PRODUCTION_ROOT = os.path.join(SITE_ROOT, 'prod_artifacts')
PRODUCTION_MEDIA_ARTIFACTS = os.path.join(PRODUCTION_ROOT, 'media')
# Assets and media
STATIC_ROOT = os.path.join(SITE_ROOT, 'static')
STATIC_URL = '/static/'
MEDIA_ROOT = os.path.join(SITE_ROOT, 'media/')
MEDIA_URL = '/media/'
ADMIN_MEDIA_PREFIX = '/media/admin/'
STATICFILES_DIRS = [
os.path.join(SITE_ROOT, 'readthedocs', 'static'),
os.path.join(SITE_ROOT, 'media'),
]
STATICFILES_FINDERS = [
'readthedocs.core.static.SelectiveFileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]
PYTHON_MEDIA = False
# Django Storage subclass used to write build artifacts to cloud or local storage
# https://docs.readthedocs.io/page/development/settings.html#rtd-build-media-storage
RTD_BUILD_MEDIA_STORAGE = 'readthedocs.builds.storage.BuildMediaFileSystemStorage'
RTD_BUILD_ENVIRONMENT_STORAGE = 'readthedocs.builds.storage.BuildMediaFileSystemStorage'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATE_ROOT],
'OPTIONS': {
'debug': DEBUG,
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.request',
# Read the Docs processor
'readthedocs.core.context_processors.readthedocs_processor',
],
'loaders': [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
],
},
},
]
# Cache
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'PREFIX': 'docs',
}
}
CACHE_MIDDLEWARE_SECONDS = 60
# I18n
TIME_ZONE = 'UTC'
USE_TZ = True
LANGUAGE_CODE = 'en-us'
LANGUAGES = (
('ca', gettext('Catalan')),
('en', gettext('English')),
('es', gettext('Spanish')),
('pt-br', gettext('Brazilian Portuguese')),
('nb', gettext('Norwegian Bokmål')),
('fr', gettext('French')),
('ru', gettext('Russian')),
('de', gettext('German')),
('gl', gettext('Galician')),
('vi', gettext('Vietnamese')),
('zh-cn', gettext('Simplified Chinese')),
('zh-tw', gettext('Traditional Chinese')),
('ja', gettext('Japanese')),
('uk', gettext('Ukrainian')),
('it', gettext('Italian')),
('ko', gettext('Korean')),
)
LOCALE_PATHS = [
os.path.join(SITE_ROOT, 'readthedocs', 'locale'),
]
USE_I18N = True
USE_L10N = True
# Celery
CELERY_APP_NAME = 'readthedocs'
CELERY_ALWAYS_EAGER = True
CELERYD_TASK_TIME_LIMIT = 60 * 60 # 60 minutes
CELERY_SEND_TASK_ERROR_EMAILS = False
CELERYD_HIJACK_ROOT_LOGGER = False
# This stops us from pre-fetching a task that then sits around on the builder
CELERY_ACKS_LATE = True
# Don't queue a bunch of tasks in the workers
CELERYD_PREFETCH_MULTIPLIER = 1
CELERY_CREATE_MISSING_QUEUES = True
BROKER_TRANSPORT_OPTIONS = {
'queue_order_strategy': 'priority',
# We use 0 here because some things still put a task in the queue with no priority
# I don't fully understand why, but this seems to solve it.
'priority_steps': [0, CELERY_LOW, CELERY_MEDIUM, CELERY_HIGH],
}
CELERY_DEFAULT_QUEUE = 'celery'
CELERYBEAT_SCHEDULE = {
'quarter-finish-inactive-builds': {
'task': 'readthedocs.projects.tasks.finish_inactive_builds',
'schedule': crontab(minute='*/15'),
'options': {'queue': 'web'},
},
'every-three-hour-clear-persistent-messages': {
'task': 'readthedocs.core.tasks.clear_persistent_messages',
'schedule': crontab(minute=0, hour='*/3'),
'options': {'queue': 'web'},
},
'every-day-delete-old-search-queries': {
'task': 'readthedocs.search.tasks.delete_old_search_queries_from_db',
'schedule': crontab(minute=0, hour=0),
'options': {'queue': 'web'},
},
'every-day-delete-old-page-views': {
'task': 'readthedocs.analytics.tasks.delete_old_page_counts',
'schedule': crontab(minute=0, hour=1),
'options': {'queue': 'web'},
},
}
MULTIPLE_APP_SERVERS = [CELERY_DEFAULT_QUEUE]
MULTIPLE_BUILD_SERVERS = [CELERY_DEFAULT_QUEUE]
# Sentry
SENTRY_CELERY_IGNORE_EXPECTED = True
# Docker
DOCKER_ENABLE = False
DOCKER_SOCKET = 'unix:///var/run/docker.sock'
# This settings has been deprecated in favor of DOCKER_IMAGE_SETTINGS
DOCKER_BUILD_IMAGES = None
# User used to create the container.
# In production we use the same user than the one defined by the
# ``USER docs`` instruction inside the Dockerfile.
# In development, we can use the "UID:GID" of the current user running the
# instance to avoid file permissions issues.
# https://docs.docker.com/engine/reference/run/#user
RTD_DOCKER_USER = 'docs:docs'
RTD_DOCKER_COMPOSE = False
DOCKER_DEFAULT_IMAGE = 'readthedocs/build'
DOCKER_VERSION = 'auto'
DOCKER_DEFAULT_VERSION = 'latest'
DOCKER_IMAGE = '{}:{}'.format(DOCKER_DEFAULT_IMAGE, DOCKER_DEFAULT_VERSION)
DOCKER_IMAGE_SETTINGS = {
# A large number of users still have this pinned in their config file.
# We must have documented it at some point.
'readthedocs/build:2.0': {
'python': {
'supported_versions': [2, 2.7, 3, 3.5],
'default_version': {
2: 2.7,
3: 3.5,
},
},
},
'readthedocs/build:4.0': {
'python': {
'supported_versions': [2, 2.7, 3, 3.5, 3.6, 3.7],
'default_version': {
2: 2.7,
3: 3.7,
},
},
},
'readthedocs/build:5.0': {
'python': {
'supported_versions': [2, 2.7, 3, 3.5, 3.6, 3.7, 'pypy3.5'],
'default_version': {
2: 2.7,
3: 3.7,
},
},
},
'readthedocs/build:6.0': {
'python': {
'supported_versions': [2, 2.7, 3, 3.5, 3.6, 3.7, 3.8, 'pypy3.5'],
'default_version': {
2: 2.7,
3: 3.7,
},
},
},
'readthedocs/build:7.0': {
'python': {
'supported_versions': [2, 2.7, 3, 3.5, 3.6, 3.7, 3.8, 'pypy3.5'],
'default_version': {
2: 2.7,
3: 3.7,
},
},
},
}
# Alias tagged via ``docker tag`` on the build servers
DOCKER_IMAGE_SETTINGS.update({
'readthedocs/build:stable': DOCKER_IMAGE_SETTINGS.get('readthedocs/build:5.0'),
'readthedocs/build:latest': DOCKER_IMAGE_SETTINGS.get('readthedocs/build:6.0'),
'readthedocs/build:testing': DOCKER_IMAGE_SETTINGS.get('readthedocs/build:7.0'),
})
def _get_docker_memory_limit(self):
try:
total_memory = int(subprocess.check_output(
"free -m | awk '/^Mem:/{print $2}'",
shell=True,
))
return total_memory, round(total_memory - 750, -2)
except ValueError:
# On systems without a `free` command it will return a string to
# int and raise a ValueError
log.exception('Failed to get memory size, using defaults Docker limits.')
# Coefficient used to determine build time limit, as a percentage of total
# memory. Historical values here were 0.225 to 0.3.
DOCKER_TIME_LIMIT_COEFF = 0.25
@property
def DOCKER_LIMITS(self):
"""
Set docker limits dynamically, if in production, based on system memory.
We do this to avoid having separate build images. This assumes 1 build
process per server, which will be allowed to consume all available
memory.
We substract 750MiB for overhead of processes and base system, and set
the build time as proportional to the memory limit.
"""
# Our normal default
limits = {
'memory': '1g',
'time': 600,
}
# Only run on our servers
if self.RTD_IS_PRODUCTION:
total_memory, memory_limit = self._get_docker_memory_limit()
if memory_limit:
limits = {
'memory': f'{memory_limit}m',
'time': max(
limits['time'],
round(total_memory * self.DOCKER_TIME_LIMIT_COEFF, -2),
)
}
log.info(
'Using dynamic docker limits. hostname=%s memory=%s time=%s',
socket.gethostname(),
limits['memory'],
limits['time'],
)
return limits
# All auth
ACCOUNT_ADAPTER = 'readthedocs.core.adapters.AccountAdapter'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
ACCOUNT_AUTHENTICATION_METHOD = 'username_email'
ACCOUNT_ACTIVATION_DAYS = 7
SOCIALACCOUNT_AUTO_SIGNUP = False
SOCIALACCOUNT_PROVIDERS = {
'github': {
'SCOPE': [
'user:email',
'read:org',
'admin:repo_hook',
'repo:status',
],
},
'gitlab': {
'SCOPE': [
'api',
'read_user',
],
},
# Bitbucket scope/permissions are determined by the Oauth consumer setup on bitbucket.org
}
# CORS
CORS_ORIGIN_REGEX_WHITELIST = (
r'^http://(.+)\.readthedocs\.io$',
r'^https://(.+)\.readthedocs\.io$',
)
# So people can post to their accounts
CORS_ALLOW_CREDENTIALS = True
CORS_ALLOW_HEADERS = (
'x-requested-with',
'content-type',
'accept',
'origin',
'authorization',
'x-csrftoken'
)
# RTD Settings
REPO_LOCK_SECONDS = 30
ALLOW_PRIVATE_REPOS = False
DEFAULT_PRIVACY_LEVEL = 'public'
DEFAULT_VERSION_PRIVACY_LEVEL = 'public'
GROK_API_HOST = 'https://api.grokthedocs.com'
ALLOW_ADMIN = True
# Elasticsearch settings.
ES_HOSTS = ['search:9200']
ELASTICSEARCH_DSL = {
'default': {
'hosts': 'search:9200'
},
}
# Chunk size for elasticsearch reindex celery tasks
ES_TASK_CHUNK_SIZE = 100
# Info from Honza about this:
# The key to determine shard number is actually usually not the node count,
# but the size of your data.
# There are advantages to just having a single shard in an index since
# you don't have to do the distribute/collect steps when executing a search.
# If your data will allow it (not significantly larger than 40GB)
# I would recommend going to a single shard and one replica meaning
# any of the two nodes will be able to serve any search without talking to the other one.
# Scaling to more searches will then just mean adding a third node
# and a second replica resulting in immediate 50% bump in max search throughput.
ES_INDEXES = {
'project': {
'name': 'project_index',
'settings': {'number_of_shards': 1,
'number_of_replicas': 1
}
},
'page': {
'name': 'page_index',
'settings': {
'number_of_shards': 1,
'number_of_replicas': 1,
}
},
}
# ANALYZER = 'analysis': {
# 'analyzer': {
# 'default_icu': {
# 'type': 'custom',
# 'tokenizer': 'icu_tokenizer',
# 'filter': ['word_delimiter', 'icu_folding', 'icu_normalizer'],
# }
# }
# }
# Disable auto refresh for increasing index performance
ELASTICSEARCH_DSL_AUTO_REFRESH = False
ALLOWED_HOSTS = ['*']
ABSOLUTE_URL_OVERRIDES = {
'auth.user': lambda o: '/profiles/{}/'.format(o.username)
}
INTERNAL_IPS = ('127.0.0.1',)
# Taggit
# https://django-taggit.readthedocs.io
TAGGIT_TAGS_FROM_STRING = 'readthedocs.projects.tag_utils.rtd_parse_tags'
# Stripe
STRIPE_SECRET = None
STRIPE_PUBLISHABLE = None
# Do Not Track support
DO_NOT_TRACK_ENABLED = False
# Advertising configuration defaults
ADSERVER_API_BASE = None
ADSERVER_API_KEY = None
ADSERVER_API_TIMEOUT = 0.35 # seconds
# Misc application settings
GLOBAL_ANALYTICS_CODE = None
DASHBOARD_ANALYTICS_CODE = None # For the dashboard, not docs
GRAVATAR_DEFAULT_IMAGE = 'https://assets.readthedocs.org/static/images/silhouette.png' # NOQA
OAUTH_AVATAR_USER_DEFAULT_URL = GRAVATAR_DEFAULT_IMAGE
OAUTH_AVATAR_ORG_DEFAULT_URL = GRAVATAR_DEFAULT_IMAGE
RESTRUCTUREDTEXT_FILTER_SETTINGS = {
'cloak_email_addresses': True,
'file_insertion_enabled': False,
'raw_enabled': False,
'strip_comments': True,
'doctitle_xform': True,
'sectsubtitle_xform': True,
'initial_header_level': 2,
'report_level': 5,
'syntax_highlight': 'none',
'math_output': 'latex',
'field_name_limit': 50,
}
REST_FRAMEWORK = {
'DEFAULT_FILTER_BACKENDS': ('django_filters.rest_framework.DjangoFilterBackend',),
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination', # NOQA
'DEFAULT_THROTTLE_RATES': {
'anon': '5/minute',
'user': '60/minute',
},
'PAGE_SIZE': 10,
'TEST_REQUEST_DEFAULT_FORMAT': 'json',
}
SILENCED_SYSTEM_CHECKS = ['fields.W342']
# Logging
LOG_FORMAT = '%(name)s:%(lineno)s[%(process)d]: %(levelname)s %(message)s'
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'default': {
'format': LOG_FORMAT,
'datefmt': '%d/%b/%Y %H:%M:%S',
},
},
'handlers': {
'console': {
'level': 'INFO',
'class': 'logging.StreamHandler',
'formatter': 'default'
},
'debug': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'filename': os.path.join(LOGS_ROOT, 'debug.log'),
'formatter': 'default',
},
'null': {
'class': 'logging.NullHandler',
},
},
'loggers': {
'': { # root logger
'handlers': ['debug', 'console'],
# Always send from the root, handlers can filter levels
'level': 'INFO',
},
'readthedocs': {
'handlers': ['debug', 'console'],
'level': 'DEBUG',
# Don't double log at the root logger for these.
'propagate': False,
},
'django.security.DisallowedHost': {
'handlers': ['null'],
'propagate': False,
},
},
}