Changeset View
Changeset View
Standalone View
Standalone View
swh/web/settings/common.py
# Copyright (C) 2017-2019 The Software Heritage developers | # Copyright (C) 2017-2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU Affero General Public License version 3, or any later version | # License: GNU Affero General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
""" | """ | ||||
Django common settings for swh-web. | Django common settings for swh-web. | ||||
""" | """ | ||||
import os | import os | ||||
import sys | import sys | ||||
from typing import Any, Dict | |||||
from swh.web.config import get_config | from swh.web.config import get_config | ||||
swh_web_config = get_config() | swh_web_config = get_config() | ||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) | ||||
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__)) | PROJECT_DIR = os.path.dirname(os.path.abspath(__file__)) | ||||
# Quick-start development settings - unsuitable for production | # Quick-start development settings - unsuitable for production | ||||
▲ Show 20 Lines • Show All 132 Lines • ▼ Show 20 Lines | for limiter_scope, limiter_conf in throttling['scopes'].items(): | ||||
else: | else: | ||||
throttle_rates[limiter_scope] = limiter_conf['limiter_rate'] | throttle_rates[limiter_scope] = limiter_conf['limiter_rate'] | ||||
# register sub scopes specific for HTTP request types | # register sub scopes specific for HTTP request types | ||||
for http_request in http_requests: | for http_request in http_requests: | ||||
if http_request in limiter_conf['limiter_rate']: | if http_request in limiter_conf['limiter_rate']: | ||||
throttle_rates[limiter_scope + '_' + http_request.lower()] = \ | throttle_rates[limiter_scope + '_' + http_request.lower()] = \ | ||||
limiter_conf['limiter_rate'][http_request] | limiter_conf['limiter_rate'][http_request] | ||||
REST_FRAMEWORK = { | REST_FRAMEWORK: Dict[str, Any] = { | ||||
'DEFAULT_RENDERER_CLASSES': ( | 'DEFAULT_RENDERER_CLASSES': ( | ||||
'rest_framework.renderers.JSONRenderer', | 'rest_framework.renderers.JSONRenderer', | ||||
'swh.web.api.renderers.YAMLRenderer', | 'swh.web.api.renderers.YAMLRenderer', | ||||
'rest_framework.renderers.TemplateHTMLRenderer' | 'rest_framework.renderers.TemplateHTMLRenderer' | ||||
), | ), | ||||
'DEFAULT_THROTTLE_CLASSES': ( | 'DEFAULT_THROTTLE_CLASSES': ( | ||||
'swh.web.common.throttling.SwhWebRateThrottle', | 'swh.web.common.throttling.SwhWebRateThrottle', | ||||
), | ), | ||||
▲ Show 20 Lines • Show All 121 Lines • Show Last 20 Lines |