NDOJ/dmoj/settings.py

479 lines
14 KiB
Python
Raw Normal View History

2020-01-21 06:35:58 +00:00
"""
Django settings for dmoj project.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
import tempfile
from django.utils.translation import ugettext_lazy as _
from django_jinja.builtins import DEFAULT_EXTENSIONS
from jinja2 import select_autoescape
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
2022-05-14 17:57:27 +00:00
SECRET_KEY = "5*9f5q57mqmlz2#f$x1h76&jxy#yortjl1v+l*6hd18$d*yx#0"
2020-01-21 06:35:58 +00:00
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
SITE_ID = 1
2022-05-14 17:57:27 +00:00
SITE_NAME = "LQDOJ"
SITE_LONG_NAME = "LQDOJ: Le Quy Don Online Judge"
2020-01-21 06:35:58 +00:00
SITE_ADMIN_EMAIL = False
DMOJ_REQUIRE_STAFF_2FA = True
# Set to 1 to use HTTPS if request was made to https://
# Set to 2 to always use HTTPS for links
# Set to 0 to always use HTTP for links
DMOJ_SSL = 0
# Refer to dmoj.ca/post/103-point-system-rework
DMOJ_PP_STEP = 0.95
DMOJ_PP_ENTRIES = 100
2022-05-14 17:57:27 +00:00
DMOJ_PP_BONUS_FUNCTION = lambda n: 300 * (1 - 0.997**n) # noqa: E731
NODEJS = "/usr/bin/node"
EXIFTOOL = "/usr/bin/exiftool"
ACE_URL = "//cdnjs.cloudflare.com/ajax/libs/ace/1.1.3"
2020-01-21 06:35:58 +00:00
DMOJ_CAMO_URL = None
DMOJ_CAMO_KEY = None
DMOJ_CAMO_HTTPS = False
DMOJ_CAMO_EXCLUDE = ()
DMOJ_PROBLEM_DATA_ROOT = None
DMOJ_PROBLEM_MIN_TIME_LIMIT = 0 # seconds
DMOJ_PROBLEM_MAX_TIME_LIMIT = 60 # seconds
DMOJ_PROBLEM_MIN_MEMORY_LIMIT = 0 # kilobytes
DMOJ_PROBLEM_MAX_MEMORY_LIMIT = 1048576 # kilobytes
DMOJ_PROBLEM_MIN_PROBLEM_POINTS = 0
2020-06-12 23:01:53 +00:00
DMOJ_RATING_COLORS = True
2020-01-21 06:35:58 +00:00
DMOJ_EMAIL_THROTTLING = (10, 60)
DMOJ_STATS_LANGUAGE_THRESHOLD = 10
DMOJ_SUBMISSIONS_REJUDGE_LIMIT = 10
# Maximum number of submissions a single user can queue without the `spam_submission` permission
DMOJ_SUBMISSION_LIMIT = 3
2020-01-21 06:35:58 +00:00
DMOJ_BLOG_NEW_PROBLEM_COUNT = 7
2020-12-28 05:45:58 +00:00
DMOJ_BLOG_NEW_CONTEST_COUNT = 7
2020-01-21 06:35:58 +00:00
DMOJ_BLOG_RECENTLY_ATTEMPTED_PROBLEMS_COUNT = 7
DMOJ_TOTP_TOLERANCE_HALF_MINUTES = 1
2021-12-17 04:06:03 +00:00
DMOJ_USER_MAX_ORGANIZATION_COUNT = 10
DMOJ_USER_MAX_ORGANIZATION_ADD = 5
2020-01-21 06:35:58 +00:00
DMOJ_COMMENT_VOTE_HIDE_THRESHOLD = -5
2022-05-14 17:57:27 +00:00
DMOJ_PDF_PROBLEM_CACHE = ""
2020-01-21 06:35:58 +00:00
DMOJ_PDF_PROBLEM_TEMP_DIR = tempfile.gettempdir()
DMOJ_STATS_SUBMISSION_RESULT_COLORS = {
2022-05-14 17:57:27 +00:00
"TLE": "#a3bcbd",
"AC": "#00a92a",
"WA": "#ed4420",
"CE": "#42586d",
"ERR": "#ffa71c",
2020-01-21 06:35:58 +00:00
}
MARKDOWN_STYLES = {}
MARKDOWN_DEFAULT_STYLE = {}
MATHOID_URL = False
MATHOID_GZIP = False
MATHOID_MML_CACHE = None
2022-05-14 17:57:27 +00:00
MATHOID_CSS_CACHE = "default"
MATHOID_DEFAULT_TYPE = "auto"
2020-01-21 06:35:58 +00:00
MATHOID_MML_CACHE_TTL = 86400
2022-05-14 17:57:27 +00:00
MATHOID_CACHE_ROOT = tempfile.gettempdir() + "/mathoidCache"
2020-01-21 06:35:58 +00:00
MATHOID_CACHE_URL = False
TEXOID_GZIP = False
2022-05-14 17:57:27 +00:00
TEXOID_META_CACHE = "default"
2020-01-21 06:35:58 +00:00
TEXOID_META_CACHE_TTL = 86400
BAD_MAIL_PROVIDERS = ()
BAD_MAIL_PROVIDER_REGEX = ()
NOFOLLOW_EXCLUDED = set()
TIMEZONE_BG = None
TIMEZONE_MAP = None
TIMEZONE_DETECT_BACKEND = None
TERMS_OF_SERVICE_URL = None
2022-05-14 17:57:27 +00:00
DEFAULT_USER_LANGUAGE = "PY3"
2020-01-21 06:35:58 +00:00
2022-05-14 17:57:27 +00:00
PHANTOMJS = ""
2020-01-21 06:35:58 +00:00
PHANTOMJS_PDF_ZOOM = 0.75
PHANTOMJS_PDF_TIMEOUT = 5.0
2022-05-14 17:57:27 +00:00
PHANTOMJS_PAPER_SIZE = "Letter"
2020-01-21 06:35:58 +00:00
2022-05-14 17:57:27 +00:00
SLIMERJS = ""
2020-01-21 06:35:58 +00:00
SLIMERJS_PDF_ZOOM = 0.75
2022-05-14 17:57:27 +00:00
SLIMERJS_FIREFOX_PATH = ""
SLIMERJS_PAPER_SIZE = "Letter"
2020-01-21 06:35:58 +00:00
2022-05-14 17:57:27 +00:00
PUPPETEER_MODULE = "/usr/lib/node_modules/puppeteer"
PUPPETEER_PAPER_SIZE = "Letter"
2020-01-21 06:35:58 +00:00
2021-05-30 17:51:19 +00:00
USE_SELENIUM = False
SELENIUM_CUSTOM_CHROME_PATH = None
2022-05-14 17:57:27 +00:00
SELENIUM_CHROMEDRIVER_PATH = "chromedriver"
2021-05-30 17:51:19 +00:00
2022-05-14 17:57:27 +00:00
PYGMENT_THEME = "pygment-github.css"
2020-01-21 06:35:58 +00:00
INLINE_JQUERY = True
INLINE_FONTAWESOME = True
2022-05-14 17:57:27 +00:00
JQUERY_JS = "//ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"
FONTAWESOME_CSS = (
"//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css"
)
DMOJ_CANONICAL = ""
2020-01-21 06:35:58 +00:00
# Application definition
INSTALLED_APPS = ()
try:
import wpadmin
except ImportError:
pass
else:
del wpadmin
2022-05-14 17:57:27 +00:00
INSTALLED_APPS += ("wpadmin",)
2020-01-21 06:35:58 +00:00
WPADMIN = {
2022-05-14 17:57:27 +00:00
"admin": {
"title": "LQDOJ Admin",
"menu": {
"top": "wpadmin.menu.menus.BasicTopMenu",
"left": "wpadmin.menu.custom.CustomModelLeftMenuWithDashboard",
2020-01-21 06:35:58 +00:00
},
2022-05-14 17:57:27 +00:00
"custom_menu": [
2020-01-21 06:35:58 +00:00
{
2022-05-14 17:57:27 +00:00
"model": "judge.Problem",
"icon": "fa-question-circle",
"children": [
"judge.ProblemGroup",
"judge.ProblemType",
"judge.ProblemPointsVote",
2020-01-21 06:35:58 +00:00
],
},
{
2022-05-14 17:57:27 +00:00
"model": "judge.Submission",
"icon": "fa-check-square-o",
"children": [
"judge.Language",
"judge.Judge",
2020-01-21 06:35:58 +00:00
],
},
{
2022-05-14 17:57:27 +00:00
"model": "judge.Contest",
"icon": "fa-bar-chart",
"children": [
"judge.ContestParticipation",
"judge.ContestTag",
2020-01-21 06:35:58 +00:00
],
},
{
2022-05-14 17:57:27 +00:00
"model": "auth.User",
"icon": "fa-user",
"children": [
"auth.Group",
"registration.RegistrationProfile",
2020-01-21 06:35:58 +00:00
],
},
{
2022-05-14 17:57:27 +00:00
"model": "judge.Profile",
"icon": "fa-user-plus",
"children": [
"judge.Organization",
"judge.OrganizationRequest",
2020-01-21 06:35:58 +00:00
],
},
{
2022-05-14 17:57:27 +00:00
"model": "judge.NavigationBar",
"icon": "fa-bars",
"children": [
"judge.MiscConfig",
"judge.License",
"sites.Site",
"redirects.Redirect",
2020-01-21 06:35:58 +00:00
],
},
2022-05-14 17:57:27 +00:00
("judge.BlogPost", "fa-rss-square"),
("judge.Ticket", "fa-exclamation-circle"),
2022-09-02 23:03:54 +00:00
("admin.LogEntry", "fa-empire"),
2020-01-21 06:35:58 +00:00
],
2022-05-14 17:57:27 +00:00
"dashboard": {
"breadcrumbs": True,
2020-01-21 06:35:58 +00:00
},
},
}
INSTALLED_APPS += (
2022-05-14 17:57:27 +00:00
"django.contrib.admin",
"judge",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.flatpages",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.redirects",
"django.contrib.staticfiles",
"django.contrib.sites",
"django.contrib.sitemaps",
"registration",
"mptt",
"reversion",
"reversion_compare",
"django_social_share",
"social_django",
"compressor",
"django_ace",
"pagedown",
"sortedm2m",
"statici18n",
"impersonate",
"django_jinja",
"chat_box",
"django.forms",
2020-01-21 06:35:58 +00:00
)
MIDDLEWARE = (
2022-05-14 17:57:27 +00:00
"judge.middleware.ShortCircuitMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.locale.LocaleMiddleware",
2022-11-14 01:01:34 +00:00
"django.middleware.common.CommonMiddleware",
2022-05-14 17:57:27 +00:00
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"judge.middleware.DMOJLoginMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"judge.user_log.LogUserAccessMiddleware",
"judge.timezone.TimezoneMiddleware",
"impersonate.middleware.ImpersonateMiddleware",
"judge.middleware.DMOJImpersonationMiddleware",
"judge.middleware.ContestMiddleware",
2022-12-18 09:31:31 +00:00
"judge.middleware.DarkModeMiddleware",
2023-01-24 02:36:44 +00:00
"judge.middleware.SubdomainMiddleware",
2022-05-14 17:57:27 +00:00
"django.contrib.flatpages.middleware.FlatpageFallbackMiddleware",
"judge.social_auth.SocialAuthExceptionMiddleware",
"django.contrib.redirects.middleware.RedirectFallbackMiddleware",
2020-01-21 06:35:58 +00:00
)
2022-11-04 03:38:39 +00:00
X_FRAME_OPTIONS = "SAMEORIGIN"
2022-11-14 01:01:34 +00:00
LANGUAGE_COOKIE_AGE = 8640000
2022-05-14 17:57:27 +00:00
FORM_RENDERER = "django.forms.renderers.TemplatesSetting"
2021-11-28 03:28:48 +00:00
2020-01-21 06:35:58 +00:00
IMPERSONATE_REQUIRE_SUPERUSER = True
IMPERSONATE_DISABLE_LOGGING = True
ACCOUNT_ACTIVATION_DAYS = 7
AUTH_PASSWORD_VALIDATORS = [
{
2022-05-14 17:57:27 +00:00
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
2020-01-21 06:35:58 +00:00
},
{
2022-05-14 17:57:27 +00:00
"NAME": "judge.utils.pwned.PwnedPasswordsValidator",
2020-01-21 06:35:58 +00:00
},
{
2022-05-14 17:57:27 +00:00
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
2020-01-21 06:35:58 +00:00
},
]
2022-05-14 17:57:27 +00:00
SILENCED_SYSTEM_CHECKS = ["urls.W002", "fields.W342"]
2020-01-21 06:35:58 +00:00
2022-05-14 17:57:27 +00:00
ROOT_URLCONF = "dmoj.urls"
LOGIN_REDIRECT_URL = "/user"
WSGI_APPLICATION = "dmoj.wsgi.application"
2020-01-21 06:35:58 +00:00
TEMPLATES = [
{
2022-05-14 17:57:27 +00:00
"BACKEND": "django_jinja.backend.Jinja2",
"DIRS": [
os.path.join(BASE_DIR, "templates"),
2020-01-21 06:35:58 +00:00
],
2022-05-14 17:57:27 +00:00
"APP_DIRS": False,
"OPTIONS": {
"match_extension": (".html", ".txt"),
"match_regex": "^(?!admin/)",
"context_processors": [
"django.template.context_processors.media",
"django.template.context_processors.tz",
"django.template.context_processors.i18n",
"django.template.context_processors.request",
"django.contrib.messages.context_processors.messages",
"judge.template_context.comet_location",
"judge.template_context.get_resource",
"judge.template_context.general_info",
"judge.template_context.site",
"judge.template_context.site_name",
"judge.template_context.misc_config",
"judge.template_context.math_setting",
"social_django.context_processors.backends",
"social_django.context_processors.login_redirect",
2020-01-21 06:35:58 +00:00
],
2022-05-14 17:57:27 +00:00
"autoescape": select_autoescape(["html", "xml"]),
"trim_blocks": True,
"lstrip_blocks": True,
"extensions": DEFAULT_EXTENSIONS
+ [
"compressor.contrib.jinja2ext.CompressorExtension",
"judge.jinja2.DMOJExtension",
"judge.jinja2.spaceless.SpacelessExtension",
2020-01-21 06:35:58 +00:00
],
},
},
{
2022-05-14 17:57:27 +00:00
"BACKEND": "django.template.backends.django.DjangoTemplates",
"APP_DIRS": True,
"DIRS": [
os.path.join(BASE_DIR, "templates"),
2020-01-21 06:35:58 +00:00
],
2022-05-14 17:57:27 +00:00
"OPTIONS": {
"context_processors": [
"django.contrib.auth.context_processors.auth",
"django.template.context_processors.media",
"django.template.context_processors.tz",
"django.template.context_processors.i18n",
"django.template.context_processors.request",
"django.contrib.messages.context_processors.messages",
2020-01-21 06:35:58 +00:00
],
},
},
]
LOCALE_PATHS = [
2022-05-14 17:57:27 +00:00
os.path.join(BASE_DIR, "locale"),
2020-01-21 06:35:58 +00:00
]
LANGUAGES = [
2022-05-14 17:57:27 +00:00
("vi", _("Vietnamese")),
2022-11-07 21:48:05 +00:00
("en", _("English")),
2020-01-21 06:35:58 +00:00
]
# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
DATABASES = {
2022-05-14 17:57:27 +00:00
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
2020-01-21 06:35:58 +00:00
},
}
ENABLE_FTS = False
# Bridged configuration
2022-05-14 17:57:27 +00:00
BRIDGED_JUDGE_ADDRESS = [("localhost", 9999)]
2020-01-21 06:35:58 +00:00
BRIDGED_JUDGE_PROXIES = None
2022-05-14 17:57:27 +00:00
BRIDGED_DJANGO_ADDRESS = [("localhost", 9998)]
2020-01-21 06:35:58 +00:00
BRIDGED_DJANGO_CONNECT = None
# Event Server configuration
EVENT_DAEMON_USE = False
2022-05-14 17:57:27 +00:00
EVENT_DAEMON_POST = "ws://localhost:9997/"
EVENT_DAEMON_GET = "ws://localhost:9996/"
EVENT_DAEMON_POLL = "/channels/"
2020-01-21 06:35:58 +00:00
EVENT_DAEMON_KEY = None
2022-05-14 17:57:27 +00:00
EVENT_DAEMON_AMQP_EXCHANGE = "dmoj-events"
EVENT_DAEMON_SUBMISSION_KEY = (
"6Sdmkx^%pk@GsifDfXcwX*Y7LRF%RGT8vmFpSxFBT$fwS7trc8raWfN#CSfQuKApx&$B#Gh2L7p%W!Ww"
)
2020-01-21 06:35:58 +00:00
# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/
# Whatever you do, this better be one of the entries in `LANGUAGES`.
2022-05-14 17:57:27 +00:00
LANGUAGE_CODE = "vi"
TIME_ZONE = "Asia/Ho_Chi_Minh"
DEFAULT_USER_TIME_ZONE = "Asia/Ho_Chi_Minh"
2020-01-21 06:35:58 +00:00
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Cookies
2022-05-14 17:57:27 +00:00
SESSION_ENGINE = "django.contrib.sessions.backends.cached_db"
2020-01-21 06:35:58 +00:00
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
2022-05-14 17:57:27 +00:00
DMOJ_RESOURCES = os.path.join(BASE_DIR, "resources")
2020-01-21 06:35:58 +00:00
STATICFILES_FINDERS = (
2022-05-14 17:57:27 +00:00
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
2020-01-21 06:35:58 +00:00
)
STATICFILES_DIRS = [
2022-05-14 17:57:27 +00:00
os.path.join(BASE_DIR, "resources"),
2020-01-21 06:35:58 +00:00
]
2022-05-14 17:57:27 +00:00
STATIC_URL = "/static/"
2020-01-21 06:35:58 +00:00
# Define a cache
CACHES = {}
# Authentication
AUTHENTICATION_BACKENDS = (
2022-05-14 17:57:27 +00:00
"social_core.backends.google.GoogleOAuth2",
"social_core.backends.facebook.FacebookOAuth2",
"judge.social_auth.GitHubSecureEmailOAuth2",
"django.contrib.auth.backends.ModelBackend",
2020-01-21 06:35:58 +00:00
)
SOCIAL_AUTH_PIPELINE = (
2022-05-14 17:57:27 +00:00
"social_core.pipeline.social_auth.social_details",
"social_core.pipeline.social_auth.social_uid",
"social_core.pipeline.social_auth.auth_allowed",
"judge.social_auth.verify_email",
"social_core.pipeline.social_auth.social_user",
"social_core.pipeline.user.get_username",
"social_core.pipeline.social_auth.associate_by_email",
"judge.social_auth.choose_username",
"social_core.pipeline.user.create_user",
"judge.social_auth.make_profile",
"social_core.pipeline.social_auth.associate_user",
"social_core.pipeline.social_auth.load_extra_data",
"social_core.pipeline.user.user_details",
2020-01-21 06:35:58 +00:00
)
2022-05-14 17:57:27 +00:00
SOCIAL_AUTH_PROTECTED_USER_FIELDS = ["first_name", "last_name"]
SOCIAL_AUTH_GOOGLE_OAUTH2_USER_FIELDS = ["email", "username"]
SOCIAL_AUTH_GITHUB_SECURE_SCOPE = ["user:email"]
SOCIAL_AUTH_FACEBOOK_SCOPE = ["email"]
2020-01-21 06:35:58 +00:00
SOCIAL_AUTH_SLUGIFY_USERNAMES = True
2022-05-14 17:57:27 +00:00
SOCIAL_AUTH_SLUGIFY_FUNCTION = "judge.social_auth.slugify_username"
2020-01-21 06:35:58 +00:00
JUDGE_AMQP_PATH = None
MOSS_API_KEY = None
CELERY_WORKER_HIJACK_ROOT_LOGGER = False
2020-01-21 17:42:16 +00:00
TESTCASE_VISIBLE_LENGTH = 64
2020-01-26 05:22:27 +00:00
DATA_UPLOAD_MAX_NUMBER_FIELDS = 10240
DATA_UPLOAD_MAX_MEMORY_SIZE = 2621440
2020-07-20 15:20:27 +00:00
FILE_UPLOAD_PERMISSIONS = 0o644
2020-01-27 20:37:52 +00:00
2020-03-19 22:51:56 +00:00
MESSAGES_TO_LOAD = 15
2022-11-20 02:00:31 +00:00
ML_OUTPUT_PATH = None
2021-12-29 06:33:25 +00:00
try:
2022-05-14 17:57:27 +00:00
with open(os.path.join(os.path.dirname(__file__), "local_settings.py")) as f:
2021-12-29 06:33:25 +00:00
exec(f.read(), globals())
except IOError:
pass
2022-11-01 01:43:06 +00:00
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"