2015-06-26 07:59:53 +00:00
|
|
|
"""
|
2015-08-02 00:59:01 +00:00
|
|
|
Django settings for oj project.
|
2015-06-26 07:59:53 +00:00
|
|
|
|
2017-10-23 02:47:26 +00:00
|
|
|
Generated by 'django-admin startproject' using Django 1.11.
|
2015-06-26 07:59:53 +00:00
|
|
|
|
|
|
|
For more information on this file, see
|
|
|
|
https://docs.djangoproject.com/en/1.8/topics/settings/
|
|
|
|
|
|
|
|
For the full list of settings and their values, see
|
|
|
|
https://docs.djangoproject.com/en/1.8/ref/settings/
|
|
|
|
"""
|
|
|
|
import os
|
2017-10-31 08:33:25 +00:00
|
|
|
from copy import deepcopy
|
2015-06-26 07:59:53 +00:00
|
|
|
|
2017-10-23 12:59:44 +00:00
|
|
|
if os.environ.get("OJ_ENV") == "production":
|
2017-10-23 02:47:26 +00:00
|
|
|
from .production_settings import *
|
|
|
|
else:
|
|
|
|
from .dev_settings import *
|
2015-06-26 07:59:53 +00:00
|
|
|
|
2017-10-31 12:47:47 +00:00
|
|
|
from .custom_settings import *
|
|
|
|
|
2015-06-26 07:59:53 +00:00
|
|
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
|
2017-10-23 02:47:26 +00:00
|
|
|
# Applications
|
2017-10-31 08:33:25 +00:00
|
|
|
VENDOR_APPS = (
|
2015-06-26 07:59:53 +00:00
|
|
|
'django.contrib.auth',
|
|
|
|
'django.contrib.sessions',
|
2017-09-13 14:37:57 +00:00
|
|
|
'django.contrib.contenttypes',
|
2015-06-26 07:59:53 +00:00
|
|
|
'django.contrib.messages',
|
|
|
|
'django.contrib.staticfiles',
|
2017-09-13 14:37:57 +00:00
|
|
|
'rest_framework',
|
2017-10-31 08:33:25 +00:00
|
|
|
)
|
|
|
|
LOCAL_APPS = (
|
2017-11-01 14:25:14 +00:00
|
|
|
'account',
|
2015-08-05 02:34:00 +00:00
|
|
|
'announcement',
|
2016-11-19 05:47:59 +00:00
|
|
|
'conf',
|
2017-01-24 05:22:40 +00:00
|
|
|
'problem',
|
2017-01-25 04:50:35 +00:00
|
|
|
'contest',
|
2015-08-05 00:44:28 +00:00
|
|
|
'utils',
|
2017-05-08 09:29:01 +00:00
|
|
|
'submission',
|
2017-10-01 19:54:34 +00:00
|
|
|
'options',
|
2017-10-31 08:33:25 +00:00
|
|
|
'judge',
|
2015-06-26 07:59:53 +00:00
|
|
|
)
|
|
|
|
|
2017-10-31 08:33:25 +00:00
|
|
|
INSTALLED_APPS = VENDOR_APPS + LOCAL_APPS
|
|
|
|
|
2015-06-26 07:59:53 +00:00
|
|
|
MIDDLEWARE_CLASSES = (
|
|
|
|
'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',
|
|
|
|
'django.middleware.security.SecurityMiddleware',
|
2017-02-10 03:41:01 +00:00
|
|
|
'account.middleware.AdminRoleRequiredMiddleware',
|
2017-09-19 11:10:50 +00:00
|
|
|
'account.middleware.SessionRecordMiddleware',
|
2017-09-13 14:37:57 +00:00
|
|
|
# 'account.middleware.LogSqlMiddleware',
|
2015-06-26 07:59:53 +00:00
|
|
|
)
|
2015-08-02 00:59:01 +00:00
|
|
|
ROOT_URLCONF = 'oj.urls'
|
2015-06-26 07:59:53 +00:00
|
|
|
|
|
|
|
TEMPLATES = [
|
|
|
|
{
|
|
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
2017-01-25 08:29:00 +00:00
|
|
|
'DIRS': [],
|
2015-06-26 07:59:53 +00:00
|
|
|
'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',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
2015-08-02 00:59:01 +00:00
|
|
|
WSGI_APPLICATION = 'oj.wsgi.application'
|
2015-06-26 07:59:53 +00:00
|
|
|
|
2017-09-12 03:45:17 +00:00
|
|
|
# Password validation
|
|
|
|
# https://docs.djangoproject.com/en/1.9/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',
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2015-06-26 07:59:53 +00:00
|
|
|
# Internationalization
|
|
|
|
# https://docs.djangoproject.com/en/1.8/topics/i18n/
|
|
|
|
|
2016-06-23 04:19:16 +00:00
|
|
|
LANGUAGE_CODE = 'en-us'
|
2015-06-26 07:59:53 +00:00
|
|
|
|
2017-01-24 05:22:40 +00:00
|
|
|
TIME_ZONE = 'UTC'
|
2015-06-26 07:59:53 +00:00
|
|
|
|
|
|
|
USE_I18N = True
|
|
|
|
|
|
|
|
USE_L10N = True
|
|
|
|
|
|
|
|
USE_TZ = True
|
|
|
|
|
|
|
|
# Static files (CSS, JavaScript, Images)
|
|
|
|
# https://docs.djangoproject.com/en/1.8/howto/static-files/
|
|
|
|
|
2017-11-24 19:37:40 +00:00
|
|
|
STATIC_URL = '/storage/'
|
2015-06-26 07:59:53 +00:00
|
|
|
|
2015-06-29 04:43:17 +00:00
|
|
|
AUTH_USER_MODEL = 'account.User'
|
|
|
|
|
2017-11-25 04:30:00 +00:00
|
|
|
TEST_CASE_DIR = os.path.join(DATA_DIR, "test_case")
|
2017-11-24 19:37:40 +00:00
|
|
|
LOG_PATH = os.path.join(DATA_DIR, "log")
|
|
|
|
|
|
|
|
AVATAR_URI_PREFIX = "/public/avatar"
|
|
|
|
AVATAR_UPLOAD_DIR = f"{DATA_DIR}{AVATAR_URI_PREFIX}"
|
|
|
|
|
|
|
|
UPLOAD_PREFIX = "/public/upload"
|
|
|
|
UPLOAD_DIR = f"{DATA_DIR}{UPLOAD_PREFIX}"
|
|
|
|
|
|
|
|
STATICFILES_DIRS = [os.path.join(DATA_DIR, "public")]
|
|
|
|
|
|
|
|
|
2015-06-26 07:59:53 +00:00
|
|
|
LOGGING = {
|
|
|
|
'version': 1,
|
2017-09-12 03:45:17 +00:00
|
|
|
'disable_existing_loggers': False,
|
2015-06-26 07:59:53 +00:00
|
|
|
'formatters': {
|
|
|
|
'standard': {
|
2017-11-02 07:29:08 +00:00
|
|
|
'format': '%(asctime)s [%(threadName)s:%(thread)d] [%(name)s:%(lineno)d] [%(module)s:%(funcName)s] [%(levelname)s]- %(message)s',
|
|
|
|
'datefmt': '%Y-%m-%d %H:%M:%S'
|
|
|
|
}
|
2015-06-26 07:59:53 +00:00
|
|
|
},
|
|
|
|
'handlers': {
|
2015-08-22 06:12:58 +00:00
|
|
|
'django_error': {
|
2017-10-31 08:33:25 +00:00
|
|
|
'level': 'WARNING',
|
2015-06-26 07:59:53 +00:00
|
|
|
'class': 'logging.handlers.RotatingFileHandler',
|
2017-04-18 17:37:10 +00:00
|
|
|
'filename': os.path.join(LOG_PATH, 'django.log'),
|
2015-08-22 06:12:58 +00:00
|
|
|
'formatter': 'standard'
|
|
|
|
},
|
|
|
|
'app_info': {
|
2017-10-31 08:33:25 +00:00
|
|
|
'level': 'INFO',
|
2015-08-22 06:12:58 +00:00
|
|
|
'class': 'logging.handlers.RotatingFileHandler',
|
2017-04-18 17:37:10 +00:00
|
|
|
'filename': os.path.join(LOG_PATH, 'app_info.log'),
|
2015-06-26 07:59:53 +00:00
|
|
|
'formatter': 'standard'
|
|
|
|
},
|
|
|
|
'console': {
|
|
|
|
'level': 'DEBUG',
|
|
|
|
'class': 'logging.StreamHandler',
|
|
|
|
'formatter': 'standard'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'loggers': {
|
|
|
|
'django.request': {
|
2015-08-22 06:12:58 +00:00
|
|
|
'handlers': ['django_error', 'console'],
|
2017-10-31 08:33:25 +00:00
|
|
|
'level': 'WARNING',
|
2015-06-26 07:59:53 +00:00
|
|
|
'propagate': True,
|
|
|
|
},
|
2017-10-31 08:33:25 +00:00
|
|
|
'django.db.backends': {
|
|
|
|
'handlers': ['django_error', 'console'],
|
|
|
|
'level': 'WARNING',
|
|
|
|
'propagate': True,
|
|
|
|
},
|
2015-06-26 07:59:53 +00:00
|
|
|
},
|
|
|
|
}
|
2017-10-31 08:33:25 +00:00
|
|
|
app_logger = {
|
|
|
|
'handlers': ['app_info', 'console'],
|
|
|
|
'level': 'DEBUG',
|
|
|
|
'propagate': False
|
|
|
|
}
|
|
|
|
LOGGING["loggers"].update({app: deepcopy(app_logger) for app in LOCAL_APPS})
|
|
|
|
|
2017-10-21 02:51:35 +00:00
|
|
|
REST_FRAMEWORK = {
|
|
|
|
'TEST_REQUEST_DEFAULT_FORMAT': 'json',
|
|
|
|
'DEFAULT_RENDERER_CLASSES': (
|
|
|
|
'rest_framework.renderers.JSONRenderer',
|
|
|
|
)
|
|
|
|
}
|
2015-08-20 12:24:51 +00:00
|
|
|
|
2017-10-23 02:47:26 +00:00
|
|
|
REDIS_URL = "redis://%s:%s" % (REDIS_CONF["host"], REDIS_CONF["port"])
|
2017-08-15 12:32:14 +00:00
|
|
|
|
2017-10-31 08:33:25 +00:00
|
|
|
|
2017-10-06 09:46:14 +00:00
|
|
|
def redis_config(db):
|
|
|
|
def make_key(key, key_prefix, version):
|
|
|
|
return key
|
2017-08-15 12:32:14 +00:00
|
|
|
|
2017-10-06 09:46:14 +00:00
|
|
|
return {
|
|
|
|
"BACKEND": "utils.cache.MyRedisCache",
|
|
|
|
"LOCATION": f"{REDIS_URL}/{db}",
|
|
|
|
"TIMEOUT": None,
|
|
|
|
"KEY_PREFIX": "",
|
|
|
|
"KEY_FUNCTION": make_key
|
2017-08-15 12:32:14 +00:00
|
|
|
}
|
2017-10-06 09:46:14 +00:00
|
|
|
|
2017-10-31 08:33:25 +00:00
|
|
|
|
2017-10-06 09:46:14 +00:00
|
|
|
CACHES = {
|
|
|
|
"default": redis_config(db=1)
|
2017-08-15 12:32:14 +00:00
|
|
|
}
|
|
|
|
|
2017-10-06 09:46:14 +00:00
|
|
|
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
|
|
|
|
SESSION_CACHE_ALIAS = "default"
|
|
|
|
|
2017-10-23 02:47:26 +00:00
|
|
|
CELERY_RESULT_BACKEND = f"{REDIS_URL}/2"
|
|
|
|
BROKER_URL = f"{REDIS_URL}/3"
|
|
|
|
CELERY_TASK_SOFT_TIME_LIMIT = CELERY_TASK_TIME_LIMIT = 180
|
2016-04-30 11:27:20 +00:00
|
|
|
CELERY_ACCEPT_CONTENT = ["json"]
|
|
|
|
CELERY_TASK_SERIALIZER = "json"
|
|
|
|
|
2016-01-17 06:51:14 +00:00
|
|
|
# 用于限制用户恶意提交大量代码
|
2017-10-27 10:36:29 +00:00
|
|
|
TOKEN_BUCKET_DEFAULT_CAPACITY = 20
|
2016-01-17 06:51:14 +00:00
|
|
|
|
|
|
|
# 单位:每分钟
|
|
|
|
TOKEN_BUCKET_FILL_RATE = 2
|