OnlineJudge/oj/settings.py

191 lines
4.7 KiB
Python
Raw Normal View History

# coding=utf-8
"""
2015-08-02 00:59:01 +00:00
Django settings for oj project.
Generated by 'django-admin startproject' using Django 1.8.
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/
"""
from __future__ import absolute_import
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
2015-08-26 06:25:14 +00:00
# 判断运行环境
2015-08-02 02:49:31 +00:00
ENV = os.environ.get("oj_env", "local")
if ENV == "local":
from .local_settings import *
2015-08-02 02:49:31 +00:00
elif ENV == "server":
from .server_settings import *
from .custom_settings import *
import djcelery
djcelery.setup_loader()
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
# Application definition
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'account',
'announcement',
'utils',
'group',
'problem',
2015-08-09 10:00:52 +00:00
'admin',
2015-08-13 13:02:17 +00:00
'submission',
'contest',
'judge',
'judge_dispatcher',
2015-12-07 12:07:52 +00:00
'rest_framework',
'djcelery',
)
if DEBUG:
INSTALLED_APPS += (
2015-10-18 03:45:06 +00:00
# 'debug_toolbar',
'rest_framework_swagger',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
'admin.middleware.AdminRequiredMiddleware',
'account.middleware.SessionSecurityMiddleware'
)
2015-08-02 00:59:01 +00:00
ROOT_URLCONF = 'oj.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
2016-01-26 04:58:08 +00:00
'DIRS': OJ_TEMPLATE_DIRS,
'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'
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'zh-hans'
TIME_ZONE = 'Asia/Shanghai'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATIC_URL = '/static/'
AUTH_USER_MODEL = 'account.User'
LOG_PATH = "log/"
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'standard': {
'format': '%(asctime)s [%(threadName)s:%(thread)d] [%(name)s:%(lineno)d] [%(module)s:%(funcName)s] [%(levelname)s]- %(message)s'}
# 日志格式
},
'handlers': {
2015-08-22 06:12:58 +00:00
'django_error': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
2015-08-22 06:12:58 +00:00
'filename': LOG_PATH + 'django.log',
'formatter': 'standard'
},
'app_info': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'filename': LOG_PATH + 'app_info.log',
'formatter': 'standard'
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'standard'
}
},
'loggers': {
2015-08-22 06:26:32 +00:00
'app_info': {
2015-08-22 06:12:58 +00:00
'handlers': ['app_info', "console"],
'level': 'DEBUG',
'propagate': True
},
'django.request': {
2015-08-22 06:12:58 +00:00
'handlers': ['django_error', 'console'],
'level': 'DEBUG',
'propagate': True,
},
'django.db.backends': {
'handlers': ['console'],
'level': 'ERROR',
'propagate': True,
}
},
}
if DEBUG:
REST_FRAMEWORK = {
'TEST_REQUEST_DEFAULT_FORMAT': 'json'
}
else:
REST_FRAMEWORK = {
'TEST_REQUEST_DEFAULT_FORMAT': 'json',
'DEFAULT_RENDERER_CLASSES': (
'rest_framework.renderers.JSONRenderer',
)
}
DATABASE_ROUTERS = ['oj.db_router.DBRouter']
TEST_CASE_DIR = os.path.join(BASE_DIR, 'test_case/')
2015-10-13 01:07:34 +00:00
IMAGE_UPLOAD_DIR = os.path.join(BASE_DIR, 'upload/')
# 用于限制用户恶意提交大量代码
TOKEN_BUCKET_DEFAULT_CAPACITY = 50
# 单位:每分钟
TOKEN_BUCKET_FILL_RATE = 2