Reformat using black
This commit is contained in:
parent
efee4ad081
commit
a87fb49918
221 changed files with 19127 additions and 7310 deletions
|
@ -4,24 +4,30 @@ import socket
|
|||
from celery import Celery
|
||||
from celery.signals import task_failure
|
||||
|
||||
app = Celery('dmoj')
|
||||
app = Celery("dmoj")
|
||||
|
||||
from django.conf import settings # noqa: E402, I202, django must be imported here
|
||||
app.config_from_object(settings, namespace='CELERY')
|
||||
|
||||
if hasattr(settings, 'CELERY_BROKER_URL_SECRET'):
|
||||
app.config_from_object(settings, namespace="CELERY")
|
||||
|
||||
if hasattr(settings, "CELERY_BROKER_URL_SECRET"):
|
||||
app.conf.broker_url = settings.CELERY_BROKER_URL_SECRET
|
||||
if hasattr(settings, 'CELERY_RESULT_BACKEND_SECRET'):
|
||||
if hasattr(settings, "CELERY_RESULT_BACKEND_SECRET"):
|
||||
app.conf.result_backend = settings.CELERY_RESULT_BACKEND_SECRET
|
||||
|
||||
# Load task modules from all registered Django app configs.
|
||||
app.autodiscover_tasks()
|
||||
|
||||
# Logger to enable errors be reported.
|
||||
logger = logging.getLogger('judge.celery')
|
||||
logger = logging.getLogger("judge.celery")
|
||||
|
||||
|
||||
@task_failure.connect()
|
||||
def celery_failure_log(sender, task_id, exception, traceback, *args, **kwargs):
|
||||
logger.error('Celery Task %s: %s on %s', sender.name, task_id, socket.gethostname(), # noqa: G201
|
||||
exc_info=(type(exception), exception, traceback))
|
||||
logger.error(
|
||||
"Celery Task %s: %s on %s",
|
||||
sender.name,
|
||||
task_id,
|
||||
socket.gethostname(), # noqa: G201
|
||||
exc_info=(type(exception), exception, traceback),
|
||||
)
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
import time
|
||||
|
||||
|
||||
def timeit(method):
|
||||
def timed(*args, **kw):
|
||||
ts = time.time()
|
||||
result = method(*args, **kw)
|
||||
te = time.time()
|
||||
if 'log_time' in kw:
|
||||
name = kw.get('log_name', method.__name__.upper())
|
||||
kw['log_time'][name] = int((te - ts) * 1000)
|
||||
if "log_time" in kw:
|
||||
name = kw.get("log_name", method.__name__.upper())
|
||||
kw["log_time"][name] = int((te - ts) * 1000)
|
||||
return result
|
||||
return timed
|
||||
|
||||
return timed
|
||||
|
|
519
dmoj/settings.py
519
dmoj/settings.py
|
@ -22,7 +22,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
|||
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = '5*9f5q57mqmlz2#f$x1h76&jxy#yortjl1v+l*6hd18$d*yx#0'
|
||||
SECRET_KEY = "5*9f5q57mqmlz2#f$x1h76&jxy#yortjl1v+l*6hd18$d*yx#0"
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
@ -30,8 +30,8 @@ DEBUG = True
|
|||
ALLOWED_HOSTS = []
|
||||
|
||||
SITE_ID = 1
|
||||
SITE_NAME = 'LQDOJ'
|
||||
SITE_LONG_NAME = 'LQDOJ: Le Quy Don Online Judge'
|
||||
SITE_NAME = "LQDOJ"
|
||||
SITE_LONG_NAME = "LQDOJ: Le Quy Don Online Judge"
|
||||
SITE_ADMIN_EMAIL = False
|
||||
|
||||
DMOJ_REQUIRE_STAFF_2FA = True
|
||||
|
@ -44,13 +44,15 @@ DMOJ_SSL = 0
|
|||
# Refer to dmoj.ca/post/103-point-system-rework
|
||||
DMOJ_PP_STEP = 0.95
|
||||
DMOJ_PP_ENTRIES = 100
|
||||
DMOJ_PP_BONUS_FUNCTION = lambda n: 300 * (1 - 0.997 ** n) # noqa: E731
|
||||
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'
|
||||
SELECT2_JS_URL = '//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js'
|
||||
DEFAULT_SELECT2_CSS = '//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css'
|
||||
NODEJS = "/usr/bin/node"
|
||||
EXIFTOOL = "/usr/bin/exiftool"
|
||||
ACE_URL = "//cdnjs.cloudflare.com/ajax/libs/ace/1.1.3"
|
||||
SELECT2_JS_URL = "//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"
|
||||
DEFAULT_SELECT2_CSS = (
|
||||
"//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css"
|
||||
)
|
||||
|
||||
DMOJ_CAMO_URL = None
|
||||
DMOJ_CAMO_KEY = None
|
||||
|
@ -74,14 +76,14 @@ DMOJ_BLOG_RECENTLY_ATTEMPTED_PROBLEMS_COUNT = 7
|
|||
DMOJ_TOTP_TOLERANCE_HALF_MINUTES = 1
|
||||
DMOJ_USER_MAX_ORGANIZATION_COUNT = 10
|
||||
DMOJ_COMMENT_VOTE_HIDE_THRESHOLD = -5
|
||||
DMOJ_PDF_PROBLEM_CACHE = ''
|
||||
DMOJ_PDF_PROBLEM_CACHE = ""
|
||||
DMOJ_PDF_PROBLEM_TEMP_DIR = tempfile.gettempdir()
|
||||
DMOJ_STATS_SUBMISSION_RESULT_COLORS = {
|
||||
'TLE': '#a3bcbd',
|
||||
'AC': '#00a92a',
|
||||
'WA': '#ed4420',
|
||||
'CE': '#42586d',
|
||||
'ERR': '#ffa71c',
|
||||
"TLE": "#a3bcbd",
|
||||
"AC": "#00a92a",
|
||||
"WA": "#ed4420",
|
||||
"CE": "#42586d",
|
||||
"ERR": "#ffa71c",
|
||||
}
|
||||
|
||||
MARKDOWN_STYLES = {}
|
||||
|
@ -90,14 +92,14 @@ MARKDOWN_DEFAULT_STYLE = {}
|
|||
MATHOID_URL = False
|
||||
MATHOID_GZIP = False
|
||||
MATHOID_MML_CACHE = None
|
||||
MATHOID_CSS_CACHE = 'default'
|
||||
MATHOID_DEFAULT_TYPE = 'auto'
|
||||
MATHOID_CSS_CACHE = "default"
|
||||
MATHOID_DEFAULT_TYPE = "auto"
|
||||
MATHOID_MML_CACHE_TTL = 86400
|
||||
MATHOID_CACHE_ROOT = tempfile.gettempdir() + '/mathoidCache'
|
||||
MATHOID_CACHE_ROOT = tempfile.gettempdir() + "/mathoidCache"
|
||||
MATHOID_CACHE_URL = False
|
||||
|
||||
TEXOID_GZIP = False
|
||||
TEXOID_META_CACHE = 'default'
|
||||
TEXOID_META_CACHE = "default"
|
||||
TEXOID_META_CACHE_TTL = 86400
|
||||
DMOJ_NEWSLETTER_ID_ON_REGISTER = 1
|
||||
|
||||
|
@ -110,31 +112,33 @@ TIMEZONE_MAP = None
|
|||
TIMEZONE_DETECT_BACKEND = None
|
||||
|
||||
TERMS_OF_SERVICE_URL = None
|
||||
DEFAULT_USER_LANGUAGE = 'PY3'
|
||||
DEFAULT_USER_LANGUAGE = "PY3"
|
||||
|
||||
PHANTOMJS = ''
|
||||
PHANTOMJS = ""
|
||||
PHANTOMJS_PDF_ZOOM = 0.75
|
||||
PHANTOMJS_PDF_TIMEOUT = 5.0
|
||||
PHANTOMJS_PAPER_SIZE = 'Letter'
|
||||
PHANTOMJS_PAPER_SIZE = "Letter"
|
||||
|
||||
SLIMERJS = ''
|
||||
SLIMERJS = ""
|
||||
SLIMERJS_PDF_ZOOM = 0.75
|
||||
SLIMERJS_FIREFOX_PATH = ''
|
||||
SLIMERJS_PAPER_SIZE = 'Letter'
|
||||
SLIMERJS_FIREFOX_PATH = ""
|
||||
SLIMERJS_PAPER_SIZE = "Letter"
|
||||
|
||||
PUPPETEER_MODULE = '/usr/lib/node_modules/puppeteer'
|
||||
PUPPETEER_PAPER_SIZE = 'Letter'
|
||||
PUPPETEER_MODULE = "/usr/lib/node_modules/puppeteer"
|
||||
PUPPETEER_PAPER_SIZE = "Letter"
|
||||
|
||||
USE_SELENIUM = False
|
||||
SELENIUM_CUSTOM_CHROME_PATH = None
|
||||
SELENIUM_CHROMEDRIVER_PATH = 'chromedriver'
|
||||
SELENIUM_CHROMEDRIVER_PATH = "chromedriver"
|
||||
|
||||
PYGMENT_THEME = 'pygment-github.css'
|
||||
PYGMENT_THEME = "pygment-github.css"
|
||||
INLINE_JQUERY = True
|
||||
INLINE_FONTAWESOME = True
|
||||
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 = ''
|
||||
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 = ""
|
||||
|
||||
# Application definition
|
||||
|
||||
|
@ -146,130 +150,130 @@ except ImportError:
|
|||
pass
|
||||
else:
|
||||
del wpadmin
|
||||
INSTALLED_APPS += ('wpadmin',)
|
||||
INSTALLED_APPS += ("wpadmin",)
|
||||
|
||||
WPADMIN = {
|
||||
'admin': {
|
||||
'title': 'LQDOJ Admin',
|
||||
'menu': {
|
||||
'top': 'wpadmin.menu.menus.BasicTopMenu',
|
||||
'left': 'wpadmin.menu.custom.CustomModelLeftMenuWithDashboard',
|
||||
"admin": {
|
||||
"title": "LQDOJ Admin",
|
||||
"menu": {
|
||||
"top": "wpadmin.menu.menus.BasicTopMenu",
|
||||
"left": "wpadmin.menu.custom.CustomModelLeftMenuWithDashboard",
|
||||
},
|
||||
'custom_menu': [
|
||||
"custom_menu": [
|
||||
{
|
||||
'model': 'judge.Problem',
|
||||
'icon': 'fa-question-circle',
|
||||
'children': [
|
||||
'judge.ProblemGroup',
|
||||
'judge.ProblemType',
|
||||
'judge.ProblemPointsVote',
|
||||
"model": "judge.Problem",
|
||||
"icon": "fa-question-circle",
|
||||
"children": [
|
||||
"judge.ProblemGroup",
|
||||
"judge.ProblemType",
|
||||
"judge.ProblemPointsVote",
|
||||
],
|
||||
},
|
||||
{
|
||||
'model': 'judge.Submission',
|
||||
'icon': 'fa-check-square-o',
|
||||
'children': [
|
||||
'judge.Language',
|
||||
'judge.Judge',
|
||||
"model": "judge.Submission",
|
||||
"icon": "fa-check-square-o",
|
||||
"children": [
|
||||
"judge.Language",
|
||||
"judge.Judge",
|
||||
],
|
||||
},
|
||||
{
|
||||
'model': 'judge.Contest',
|
||||
'icon': 'fa-bar-chart',
|
||||
'children': [
|
||||
'judge.ContestParticipation',
|
||||
'judge.ContestTag',
|
||||
"model": "judge.Contest",
|
||||
"icon": "fa-bar-chart",
|
||||
"children": [
|
||||
"judge.ContestParticipation",
|
||||
"judge.ContestTag",
|
||||
],
|
||||
},
|
||||
{
|
||||
'model': 'auth.User',
|
||||
'icon': 'fa-user',
|
||||
'children': [
|
||||
'auth.Group',
|
||||
'registration.RegistrationProfile',
|
||||
"model": "auth.User",
|
||||
"icon": "fa-user",
|
||||
"children": [
|
||||
"auth.Group",
|
||||
"registration.RegistrationProfile",
|
||||
],
|
||||
},
|
||||
{
|
||||
'model': 'judge.Profile',
|
||||
'icon': 'fa-user-plus',
|
||||
'children': [
|
||||
'judge.Organization',
|
||||
'judge.OrganizationRequest',
|
||||
"model": "judge.Profile",
|
||||
"icon": "fa-user-plus",
|
||||
"children": [
|
||||
"judge.Organization",
|
||||
"judge.OrganizationRequest",
|
||||
],
|
||||
},
|
||||
{
|
||||
'model': 'judge.NavigationBar',
|
||||
'icon': 'fa-bars',
|
||||
'children': [
|
||||
'judge.MiscConfig',
|
||||
'judge.License',
|
||||
'sites.Site',
|
||||
'redirects.Redirect',
|
||||
"model": "judge.NavigationBar",
|
||||
"icon": "fa-bars",
|
||||
"children": [
|
||||
"judge.MiscConfig",
|
||||
"judge.License",
|
||||
"sites.Site",
|
||||
"redirects.Redirect",
|
||||
],
|
||||
},
|
||||
('judge.BlogPost', 'fa-rss-square'),
|
||||
('judge.Comment', 'fa-comment-o'),
|
||||
('judge.Ticket', 'fa-exclamation-circle'),
|
||||
('flatpages.FlatPage', 'fa-file-text-o'),
|
||||
('judge.Solution', 'fa-pencil'),
|
||||
("judge.BlogPost", "fa-rss-square"),
|
||||
("judge.Comment", "fa-comment-o"),
|
||||
("judge.Ticket", "fa-exclamation-circle"),
|
||||
("flatpages.FlatPage", "fa-file-text-o"),
|
||||
("judge.Solution", "fa-pencil"),
|
||||
],
|
||||
'dashboard': {
|
||||
'breadcrumbs': True,
|
||||
"dashboard": {
|
||||
"breadcrumbs": True,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
INSTALLED_APPS += (
|
||||
'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',
|
||||
'newsletter',
|
||||
'django.forms',
|
||||
"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",
|
||||
"newsletter",
|
||||
"django.forms",
|
||||
)
|
||||
|
||||
MIDDLEWARE = (
|
||||
'judge.middleware.ShortCircuitMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.locale.LocaleMiddleware',
|
||||
'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',
|
||||
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
|
||||
'judge.social_auth.SocialAuthExceptionMiddleware',
|
||||
'django.contrib.redirects.middleware.RedirectFallbackMiddleware',
|
||||
"judge.middleware.ShortCircuitMiddleware",
|
||||
"django.middleware.common.CommonMiddleware",
|
||||
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||
"django.middleware.locale.LocaleMiddleware",
|
||||
"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",
|
||||
"django.contrib.flatpages.middleware.FlatpageFallbackMiddleware",
|
||||
"judge.social_auth.SocialAuthExceptionMiddleware",
|
||||
"django.contrib.redirects.middleware.RedirectFallbackMiddleware",
|
||||
)
|
||||
|
||||
FORM_RENDERER = 'django.forms.renderers.TemplatesSetting'
|
||||
FORM_RENDERER = "django.forms.renderers.TemplatesSetting"
|
||||
|
||||
IMPERSONATE_REQUIRE_SUPERUSER = True
|
||||
IMPERSONATE_DISABLE_LOGGING = True
|
||||
|
@ -278,226 +282,229 @@ ACCOUNT_ACTIVATION_DAYS = 7
|
|||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
|
||||
},
|
||||
{
|
||||
'NAME': 'judge.utils.pwned.PwnedPasswordsValidator',
|
||||
"NAME": "judge.utils.pwned.PwnedPasswordsValidator",
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
|
||||
},
|
||||
]
|
||||
|
||||
SILENCED_SYSTEM_CHECKS = ['urls.W002', 'fields.W342']
|
||||
SILENCED_SYSTEM_CHECKS = ["urls.W002", "fields.W342"]
|
||||
|
||||
ROOT_URLCONF = 'dmoj.urls'
|
||||
LOGIN_REDIRECT_URL = '/user'
|
||||
WSGI_APPLICATION = 'dmoj.wsgi.application'
|
||||
ROOT_URLCONF = "dmoj.urls"
|
||||
LOGIN_REDIRECT_URL = "/user"
|
||||
WSGI_APPLICATION = "dmoj.wsgi.application"
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django_jinja.backend.Jinja2',
|
||||
'DIRS': [
|
||||
os.path.join(BASE_DIR, 'templates'),
|
||||
"BACKEND": "django_jinja.backend.Jinja2",
|
||||
"DIRS": [
|
||||
os.path.join(BASE_DIR, "templates"),
|
||||
],
|
||||
'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',
|
||||
"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",
|
||||
],
|
||||
'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',
|
||||
"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",
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'APP_DIRS': True,
|
||||
'DIRS': [
|
||||
os.path.join(BASE_DIR, 'templates'),
|
||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||
"APP_DIRS": True,
|
||||
"DIRS": [
|
||||
os.path.join(BASE_DIR, "templates"),
|
||||
],
|
||||
'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',
|
||||
"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",
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
LOCALE_PATHS = [
|
||||
os.path.join(BASE_DIR, 'locale'),
|
||||
os.path.join(BASE_DIR, "locale"),
|
||||
]
|
||||
|
||||
LANGUAGES = [
|
||||
('de', _('German')),
|
||||
('en', _('English')),
|
||||
('es', _('Spanish')),
|
||||
('fr', _('French')),
|
||||
('hr', _('Croatian')),
|
||||
('hu', _('Hungarian')),
|
||||
('ja', _('Japanese')),
|
||||
('ko', _('Korean')),
|
||||
('pt', _('Brazilian Portuguese')),
|
||||
('ro', _('Romanian')),
|
||||
('ru', _('Russian')),
|
||||
('sr-latn', _('Serbian (Latin)')),
|
||||
('tr', _('Turkish')),
|
||||
('vi', _('Vietnamese')),
|
||||
('zh-hans', _('Simplified Chinese')),
|
||||
('zh-hant', _('Traditional Chinese')),
|
||||
("de", _("German")),
|
||||
("en", _("English")),
|
||||
("es", _("Spanish")),
|
||||
("fr", _("French")),
|
||||
("hr", _("Croatian")),
|
||||
("hu", _("Hungarian")),
|
||||
("ja", _("Japanese")),
|
||||
("ko", _("Korean")),
|
||||
("pt", _("Brazilian Portuguese")),
|
||||
("ro", _("Romanian")),
|
||||
("ru", _("Russian")),
|
||||
("sr-latn", _("Serbian (Latin)")),
|
||||
("tr", _("Turkish")),
|
||||
("vi", _("Vietnamese")),
|
||||
("zh-hans", _("Simplified Chinese")),
|
||||
("zh-hant", _("Traditional Chinese")),
|
||||
]
|
||||
|
||||
MARKDOWN_ADMIN_EDITABLE_STYLE = {
|
||||
'safe_mode': False,
|
||||
'use_camo': True,
|
||||
'texoid': True,
|
||||
'math': True,
|
||||
"safe_mode": False,
|
||||
"use_camo": True,
|
||||
"texoid": True,
|
||||
"math": True,
|
||||
}
|
||||
|
||||
MARKDOWN_DEFAULT_STYLE = {
|
||||
'safe_mode': True,
|
||||
'nofollow': True,
|
||||
'use_camo': True,
|
||||
'math': True,
|
||||
"safe_mode": True,
|
||||
"nofollow": True,
|
||||
"use_camo": True,
|
||||
"math": True,
|
||||
}
|
||||
|
||||
MARKDOWN_USER_LARGE_STYLE = {
|
||||
'safe_mode': True,
|
||||
'nofollow': True,
|
||||
'use_camo': True,
|
||||
'math': True,
|
||||
"safe_mode": True,
|
||||
"nofollow": True,
|
||||
"use_camo": True,
|
||||
"math": True,
|
||||
}
|
||||
|
||||
MARKDOWN_STYLES = {
|
||||
'comment': MARKDOWN_DEFAULT_STYLE,
|
||||
'self-description': MARKDOWN_USER_LARGE_STYLE,
|
||||
'problem': MARKDOWN_ADMIN_EDITABLE_STYLE,
|
||||
'contest': MARKDOWN_ADMIN_EDITABLE_STYLE,
|
||||
'language': MARKDOWN_ADMIN_EDITABLE_STYLE,
|
||||
'license': MARKDOWN_ADMIN_EDITABLE_STYLE,
|
||||
'judge': MARKDOWN_ADMIN_EDITABLE_STYLE,
|
||||
'blog': MARKDOWN_ADMIN_EDITABLE_STYLE,
|
||||
'solution': MARKDOWN_ADMIN_EDITABLE_STYLE,
|
||||
'contest_tag': MARKDOWN_ADMIN_EDITABLE_STYLE,
|
||||
'organization-about': MARKDOWN_USER_LARGE_STYLE,
|
||||
'ticket': MARKDOWN_USER_LARGE_STYLE,
|
||||
"comment": MARKDOWN_DEFAULT_STYLE,
|
||||
"self-description": MARKDOWN_USER_LARGE_STYLE,
|
||||
"problem": MARKDOWN_ADMIN_EDITABLE_STYLE,
|
||||
"contest": MARKDOWN_ADMIN_EDITABLE_STYLE,
|
||||
"language": MARKDOWN_ADMIN_EDITABLE_STYLE,
|
||||
"license": MARKDOWN_ADMIN_EDITABLE_STYLE,
|
||||
"judge": MARKDOWN_ADMIN_EDITABLE_STYLE,
|
||||
"blog": MARKDOWN_ADMIN_EDITABLE_STYLE,
|
||||
"solution": MARKDOWN_ADMIN_EDITABLE_STYLE,
|
||||
"contest_tag": MARKDOWN_ADMIN_EDITABLE_STYLE,
|
||||
"organization-about": MARKDOWN_USER_LARGE_STYLE,
|
||||
"ticket": MARKDOWN_USER_LARGE_STYLE,
|
||||
}
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.sqlite3",
|
||||
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
|
||||
},
|
||||
}
|
||||
|
||||
ENABLE_FTS = False
|
||||
|
||||
# Bridged configuration
|
||||
BRIDGED_JUDGE_ADDRESS = [('localhost', 9999)]
|
||||
BRIDGED_JUDGE_ADDRESS = [("localhost", 9999)]
|
||||
BRIDGED_JUDGE_PROXIES = None
|
||||
BRIDGED_DJANGO_ADDRESS = [('localhost', 9998)]
|
||||
BRIDGED_DJANGO_ADDRESS = [("localhost", 9998)]
|
||||
BRIDGED_DJANGO_CONNECT = None
|
||||
|
||||
# Event Server configuration
|
||||
EVENT_DAEMON_USE = False
|
||||
EVENT_DAEMON_POST = 'ws://localhost:9997/'
|
||||
EVENT_DAEMON_GET = 'ws://localhost:9996/'
|
||||
EVENT_DAEMON_POLL = '/channels/'
|
||||
EVENT_DAEMON_POST = "ws://localhost:9997/"
|
||||
EVENT_DAEMON_GET = "ws://localhost:9996/"
|
||||
EVENT_DAEMON_POLL = "/channels/"
|
||||
EVENT_DAEMON_KEY = None
|
||||
EVENT_DAEMON_AMQP_EXCHANGE = 'dmoj-events'
|
||||
EVENT_DAEMON_SUBMISSION_KEY = '6Sdmkx^%pk@GsifDfXcwX*Y7LRF%RGT8vmFpSxFBT$fwS7trc8raWfN#CSfQuKApx&$B#Gh2L7p%W!Ww'
|
||||
EVENT_DAEMON_AMQP_EXCHANGE = "dmoj-events"
|
||||
EVENT_DAEMON_SUBMISSION_KEY = (
|
||||
"6Sdmkx^%pk@GsifDfXcwX*Y7LRF%RGT8vmFpSxFBT$fwS7trc8raWfN#CSfQuKApx&$B#Gh2L7p%W!Ww"
|
||||
)
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/1.11/topics/i18n/
|
||||
|
||||
# Whatever you do, this better be one of the entries in `LANGUAGES`.
|
||||
LANGUAGE_CODE = 'vi'
|
||||
TIME_ZONE = 'Asia/Ho_Chi_Minh'
|
||||
DEFAULT_USER_TIME_ZONE = 'Asia/Ho_Chi_Minh'
|
||||
LANGUAGE_CODE = "vi"
|
||||
TIME_ZONE = "Asia/Ho_Chi_Minh"
|
||||
DEFAULT_USER_TIME_ZONE = "Asia/Ho_Chi_Minh"
|
||||
USE_I18N = True
|
||||
USE_L10N = True
|
||||
USE_TZ = True
|
||||
|
||||
# Cookies
|
||||
SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db'
|
||||
SESSION_ENGINE = "django.contrib.sessions.backends.cached_db"
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/1.11/howto/static-files/
|
||||
|
||||
DMOJ_RESOURCES = os.path.join(BASE_DIR, 'resources')
|
||||
DMOJ_RESOURCES = os.path.join(BASE_DIR, "resources")
|
||||
STATICFILES_FINDERS = (
|
||||
'django.contrib.staticfiles.finders.FileSystemFinder',
|
||||
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
|
||||
"django.contrib.staticfiles.finders.FileSystemFinder",
|
||||
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
|
||||
)
|
||||
STATICFILES_DIRS = [
|
||||
os.path.join(BASE_DIR, 'resources'),
|
||||
os.path.join(BASE_DIR, "resources"),
|
||||
]
|
||||
STATIC_URL = '/static/'
|
||||
STATIC_URL = "/static/"
|
||||
|
||||
# Define a cache
|
||||
CACHES = {}
|
||||
|
||||
# Authentication
|
||||
AUTHENTICATION_BACKENDS = (
|
||||
'social_core.backends.google.GoogleOAuth2',
|
||||
'social_core.backends.facebook.FacebookOAuth2',
|
||||
'judge.social_auth.GitHubSecureEmailOAuth2',
|
||||
'django.contrib.auth.backends.ModelBackend',
|
||||
"social_core.backends.google.GoogleOAuth2",
|
||||
"social_core.backends.facebook.FacebookOAuth2",
|
||||
"judge.social_auth.GitHubSecureEmailOAuth2",
|
||||
"django.contrib.auth.backends.ModelBackend",
|
||||
)
|
||||
|
||||
SOCIAL_AUTH_PIPELINE = (
|
||||
'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',
|
||||
"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",
|
||||
)
|
||||
|
||||
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']
|
||||
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"]
|
||||
SOCIAL_AUTH_SLUGIFY_USERNAMES = True
|
||||
SOCIAL_AUTH_SLUGIFY_FUNCTION = 'judge.social_auth.slugify_username'
|
||||
SOCIAL_AUTH_SLUGIFY_FUNCTION = "judge.social_auth.slugify_username"
|
||||
|
||||
JUDGE_AMQP_PATH = None
|
||||
|
||||
|
@ -529,7 +536,7 @@ NEWSLETTER_BATCH_SIZE = 100
|
|||
REGISTER_NAME_URL = None
|
||||
|
||||
try:
|
||||
with open(os.path.join(os.path.dirname(__file__), 'local_settings.py')) as f:
|
||||
with open(os.path.join(os.path.dirname(__file__), "local_settings.py")) as f:
|
||||
exec(f.read(), globals())
|
||||
except IOError:
|
||||
pass
|
||||
|
|
|
@ -8,8 +8,8 @@ DEFAULT_THROTTLE = (10, 60)
|
|||
|
||||
|
||||
def new_email():
|
||||
cache.add('error_email_throttle', 0, settings.DMOJ_EMAIL_THROTTLING[1])
|
||||
return cache.incr('error_email_throttle')
|
||||
cache.add("error_email_throttle", 0, settings.DMOJ_EMAIL_THROTTLING[1])
|
||||
return cache.incr("error_email_throttle")
|
||||
|
||||
|
||||
class ThrottledEmailHandler(AdminEmailHandler):
|
||||
|
|
1439
dmoj/urls.py
1439
dmoj/urls.py
File diff suppressed because it is too large
Load diff
|
@ -1,5 +1,6 @@
|
|||
import os
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dmoj.settings')
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dmoj.settings")
|
||||
|
||||
try:
|
||||
import MySQLdb # noqa: F401, imported for side effect
|
||||
|
@ -8,5 +9,8 @@ except ImportError:
|
|||
|
||||
pymysql.install_as_MySQLdb()
|
||||
|
||||
from django.core.wsgi import get_wsgi_application # noqa: E402, django must be imported here
|
||||
from django.core.wsgi import (
|
||||
get_wsgi_application,
|
||||
) # noqa: E402, django must be imported here
|
||||
|
||||
application = get_wsgi_application()
|
||||
|
|
|
@ -2,13 +2,17 @@ import os
|
|||
|
||||
import gevent.monkey # noqa: I100, gevent must be imported here
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dmoj.settings')
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dmoj.settings")
|
||||
gevent.monkey.patch_all()
|
||||
|
||||
# noinspection PyUnresolvedReferences
|
||||
import dmoj_install_pymysql # noqa: F401, I100, I202, imported for side effect
|
||||
|
||||
from django.core.wsgi import get_wsgi_application # noqa: E402, I100, I202, django must be imported here
|
||||
from django.core.wsgi import (
|
||||
get_wsgi_application,
|
||||
) # noqa: E402, I100, I202, django must be imported here
|
||||
|
||||
# noinspection PyUnresolvedReferences
|
||||
import django_2_2_pymysql_patch # noqa: I100, F401, I202, imported for side effect
|
||||
|
||||
application = get_wsgi_application()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue