Cloned DMOJ

This commit is contained in:
thanhluong 2020-01-21 15:35:58 +09:00
parent f623974b58
commit 49dc9ff10c
513 changed files with 132349 additions and 39 deletions

1
dmoj/__init__.py Normal file
View file

@ -0,0 +1 @@
from dmoj.celery import app as celery_app

27
dmoj/celery.py Normal file
View file

@ -0,0 +1,27 @@
import logging
import socket
from celery import Celery
from celery.signals import task_failure
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.conf.broker_url = settings.CELERY_BROKER_URL_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')
@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))

497
dmoj/settings.py Normal file
View file

@ -0,0 +1,497 @@
"""
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!
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
ALLOWED_HOSTS = []
SITE_ID = 1
SITE_NAME = 'DMOJ'
SITE_LONG_NAME = 'DMOJ: Modern Online Judge'
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
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'
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
DMOJ_RATING_COLORS = False
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 = 2
DMOJ_BLOG_NEW_PROBLEM_COUNT = 7
DMOJ_BLOG_RECENTLY_ATTEMPTED_PROBLEMS_COUNT = 7
DMOJ_TOTP_TOLERANCE_HALF_MINUTES = 1
DMOJ_USER_MAX_ORGANIZATION_COUNT = 3
DMOJ_COMMENT_VOTE_HIDE_THRESHOLD = -5
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',
}
MARKDOWN_STYLES = {}
MARKDOWN_DEFAULT_STYLE = {}
MATHOID_URL = False
MATHOID_GZIP = False
MATHOID_MML_CACHE = None
MATHOID_CSS_CACHE = 'default'
MATHOID_DEFAULT_TYPE = 'auto'
MATHOID_MML_CACHE_TTL = 86400
MATHOID_CACHE_ROOT = ''
MATHOID_CACHE_URL = False
TEXOID_GZIP = False
TEXOID_META_CACHE = 'default'
TEXOID_META_CACHE_TTL = 86400
DMOJ_NEWSLETTER_ID_ON_REGISTER = None
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
DEFAULT_USER_LANGUAGE = 'PY3'
PHANTOMJS = ''
PHANTOMJS_PDF_ZOOM = 0.75
PHANTOMJS_PDF_TIMEOUT = 5.0
PHANTOMJS_PAPER_SIZE = 'Letter'
SLIMERJS = ''
SLIMERJS_PDF_ZOOM = 0.75
SLIMERJS_FIREFOX_PATH = ''
SLIMERJS_PAPER_SIZE = 'Letter'
PUPPETEER_MODULE = '/usr/lib/node_modules/puppeteer'
PUPPETEER_PAPER_SIZE = 'Letter'
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 = ''
# Application definition
INSTALLED_APPS = ()
try:
import wpadmin
except ImportError:
pass
else:
del wpadmin
INSTALLED_APPS += ('wpadmin',)
WPADMIN = {
'admin': {
'title': 'DMOJ Admin',
'menu': {
'top': 'wpadmin.menu.menus.BasicTopMenu',
'left': 'wpadmin.menu.custom.CustomModelLeftMenuWithDashboard',
},
'custom_menu': [
{
'model': 'judge.Problem',
'icon': 'fa-question-circle',
'children': [
'judge.ProblemGroup',
'judge.ProblemType',
],
},
{
'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': 'auth.User',
'icon': 'fa-user',
'children': [
'auth.Group',
'registration.RegistrationProfile',
],
},
{
'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',
],
},
('judge.BlogPost', 'fa-rss-square'),
('judge.Comment', 'fa-comment-o'),
('flatpages.FlatPage', 'fa-file-text-o'),
('judge.Solution', 'fa-pencil'),
],
'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',
'django_social_share',
'social_django',
'compressor',
'django_ace',
'pagedown',
'sortedm2m',
'statici18n',
'impersonate',
'django_jinja',
)
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',
)
IMPERSONATE_REQUIRE_SUPERUSER = True
IMPERSONATE_DISABLE_LOGGING = True
ACCOUNT_ACTIVATION_DAYS = 7
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'judge.utils.pwned.PwnedPasswordsValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
SILENCED_SYSTEM_CHECKS = ['urls.W002', 'fields.W342']
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'),
],
'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',
],
},
},
{
'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',
],
},
},
]
LOCALE_PATHS = [
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')),
]
MARKDOWN_ADMIN_EDITABLE_STYLE = {
'safe_mode': False,
'use_camo': True,
'texoid': True,
'math': True,
}
MARKDOWN_DEFAULT_STYLE = {
'safe_mode': True,
'nofollow': True,
'use_camo': True,
'math': True,
}
MARKDOWN_USER_LARGE_STYLE = {
'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,
}
# 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'),
},
}
ENABLE_FTS = False
# Bridged configuration
BRIDGED_JUDGE_ADDRESS = [('localhost', 9999)]
BRIDGED_JUDGE_PROXIES = None
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_KEY = None
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 = 'en'
TIME_ZONE = 'UTC'
DEFAULT_USER_TIME_ZONE = 'America/Toronto'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Cookies
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')
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'resources'),
]
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_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_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'
JUDGE_AMQP_PATH = None
MOSS_API_KEY = None
CELERY_WORKER_HIJACK_ROOT_LOGGER = False
try:
with open(os.path.join(os.path.dirname(__file__), 'local_settings.py')) as f:
exec(f.read(), globals())
except IOError:
pass

29
dmoj/throttle_mail.py Normal file
View file

@ -0,0 +1,29 @@
import traceback
from django.conf import settings
from django.core.cache import cache
from django.utils.log import AdminEmailHandler
DEFAULT_THROTTLE = (10, 60)
def new_email():
cache.add('error_email_throttle', 0, settings.DMOJ_EMAIL_THROTTLING[1])
return cache.incr('error_email_throttle')
class ThrottledEmailHandler(AdminEmailHandler):
def __init__(self, *args, **kwargs):
super(ThrottledEmailHandler, self).__init__(*args, **kwargs)
self.throttle = settings.DMOJ_EMAIL_THROTTLING[0]
def emit(self, record):
try:
count = new_email()
except Exception:
traceback.print_exc()
else:
if count >= self.throttle:
return
AdminEmailHandler.emit(self, record)

387
dmoj/urls.py Normal file
View file

@ -0,0 +1,387 @@
from django.conf import settings
from django.conf.urls import include, url
from django.contrib import admin
from django.contrib.auth import views as auth_views
from django.contrib.sitemaps.views import sitemap
from django.http import Http404, HttpResponsePermanentRedirect
from django.templatetags.static import static
from django.urls import reverse
from django.utils.functional import lazystr
from django.utils.translation import ugettext_lazy as _
from django.views.generic import RedirectView
from judge.feed import AtomBlogFeed, AtomCommentFeed, AtomProblemFeed, BlogFeed, CommentFeed, ProblemFeed
from judge.forms import CustomAuthenticationForm
from judge.sitemap import BlogPostSitemap, ContestSitemap, HomePageSitemap, OrganizationSitemap, ProblemSitemap, \
SolutionSitemap, UrlSitemap, UserSitemap
from judge.views import TitledTemplateView, api, blog, comment, contests, language, license, mailgun, organization, \
preview, problem, problem_manage, ranked_submission, register, stats, status, submission, tasks, ticket, totp, \
user, widgets
from judge.views.problem_data import ProblemDataView, ProblemSubmissionDiff, \
problem_data_file, problem_init_view
from judge.views.register import ActivationView, RegistrationView
from judge.views.select2 import AssigneeSelect2View, CommentSelect2View, ContestSelect2View, \
ContestUserSearchSelect2View, OrganizationSelect2View, ProblemSelect2View, TicketUserSelect2View, \
UserSearchSelect2View, UserSelect2View
admin.autodiscover()
register_patterns = [
url(r'^activate/complete/$',
TitledTemplateView.as_view(template_name='registration/activation_complete.html',
title='Activation Successful!'),
name='registration_activation_complete'),
# Activation keys get matched by \w+ instead of the more specific
# [a-fA-F0-9]{40} because a bad activation key should still get to the view;
# that way it can return a sensible "invalid key" message instead of a
# confusing 404.
url(r'^activate/(?P<activation_key>\w+)/$',
ActivationView.as_view(title='Activation key invalid'),
name='registration_activate'),
url(r'^register/$',
RegistrationView.as_view(title='Register'),
name='registration_register'),
url(r'^register/complete/$',
TitledTemplateView.as_view(template_name='registration/registration_complete.html',
title='Registration Completed'),
name='registration_complete'),
url(r'^register/closed/$',
TitledTemplateView.as_view(template_name='registration/registration_closed.html',
title='Registration not allowed'),
name='registration_disallowed'),
url(r'^login/$', auth_views.LoginView.as_view(
template_name='registration/login.html',
extra_context={'title': _('Login')},
authentication_form=CustomAuthenticationForm,
redirect_authenticated_user=True,
), name='auth_login'),
url(r'^logout/$', user.UserLogoutView.as_view(), name='auth_logout'),
url(r'^password/change/$', auth_views.PasswordChangeView.as_view(
template_name='registration/password_change_form.html',
), name='password_change'),
url(r'^password/change/done/$', auth_views.PasswordChangeDoneView.as_view(
template_name='registration/password_change_done.html',
), name='password_change_done'),
url(r'^password/reset/$', auth_views.PasswordResetView.as_view(
template_name='registration/password_reset.html',
html_email_template_name='registration/password_reset_email.html',
email_template_name='registration/password_reset_email.txt',
), name='password_reset'),
url(r'^password/reset/confirm/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$',
auth_views.PasswordResetConfirmView.as_view(
template_name='registration/password_reset_confirm.html',
), name='password_reset_confirm'),
url(r'^password/reset/complete/$', auth_views.PasswordResetCompleteView.as_view(
template_name='registration/password_reset_complete.html',
), name='password_reset_complete'),
url(r'^password/reset/done/$', auth_views.PasswordResetDoneView.as_view(
template_name='registration/password_reset_done.html',
), name='password_reset_done'),
url(r'^social/error/$', register.social_auth_error, name='social_auth_error'),
url(r'^2fa/$', totp.TOTPLoginView.as_view(), name='login_2fa'),
url(r'^2fa/enable/$', totp.TOTPEnableView.as_view(), name='enable_2fa'),
url(r'^2fa/disable/$', totp.TOTPDisableView.as_view(), name='disable_2fa'),
]
def exception(request):
if not request.user.is_superuser:
raise Http404()
raise RuntimeError('@Xyene asked me to cause this')
def paged_list_view(view, name):
return include([
url(r'^$', view.as_view(), name=name),
url(r'^(?P<page>\d+)$', view.as_view(), name=name),
])
urlpatterns = [
url(r'^$', blog.PostList.as_view(template_name='home.html', title=_('Home')), kwargs={'page': 1}, name='home'),
url(r'^500/$', exception),
url(r'^admin/', admin.site.urls),
url(r'^i18n/', include('django.conf.urls.i18n')),
url(r'^accounts/', include(register_patterns)),
url(r'^', include('social_django.urls')),
url(r'^problems/$', problem.ProblemList.as_view(), name='problem_list'),
url(r'^problems/random/$', problem.RandomProblem.as_view(), name='problem_random'),
url(r'^problem/(?P<problem>[^/]+)', include([
url(r'^$', problem.ProblemDetail.as_view(), name='problem_detail'),
url(r'^/editorial$', problem.ProblemSolution.as_view(), name='problem_editorial'),
url(r'^/raw$', problem.ProblemRaw.as_view(), name='problem_raw'),
url(r'^/pdf$', problem.ProblemPdfView.as_view(), name='problem_pdf'),
url(r'^/pdf/(?P<language>[a-z-]+)$', problem.ProblemPdfView.as_view(), name='problem_pdf'),
url(r'^/clone', problem.ProblemClone.as_view(), name='problem_clone'),
url(r'^/submit$', problem.problem_submit, name='problem_submit'),
url(r'^/resubmit/(?P<submission>\d+)$', problem.problem_submit, name='problem_submit'),
url(r'^/rank/', paged_list_view(ranked_submission.RankedSubmissions, 'ranked_submissions')),
url(r'^/submissions/', paged_list_view(submission.ProblemSubmissions, 'chronological_submissions')),
url(r'^/submissions/(?P<user>\w+)/', paged_list_view(submission.UserProblemSubmissions, 'user_submissions')),
url(r'^/$', lambda _, problem: HttpResponsePermanentRedirect(reverse('problem_detail', args=[problem]))),
url(r'^/test_data$', ProblemDataView.as_view(), name='problem_data'),
url(r'^/test_data/init$', problem_init_view, name='problem_data_init'),
url(r'^/test_data/diff$', ProblemSubmissionDiff.as_view(), name='problem_submission_diff'),
url(r'^/data/(?P<path>.+)$', problem_data_file, name='problem_data_file'),
url(r'^/tickets$', ticket.ProblemTicketListView.as_view(), name='problem_ticket_list'),
url(r'^/tickets/new$', ticket.NewProblemTicketView.as_view(), name='new_problem_ticket'),
url(r'^/manage/submission', include([
url('^$', problem_manage.ManageProblemSubmissionView.as_view(), name='problem_manage_submissions'),
url('^/rejudge$', problem_manage.RejudgeSubmissionsView.as_view(), name='problem_submissions_rejudge'),
url('^/rejudge/preview$', problem_manage.PreviewRejudgeSubmissionsView.as_view(),
name='problem_submissions_rejudge_preview'),
url('^/rejudge/success/(?P<task_id>[A-Za-z0-9-]*)$', problem_manage.rejudge_success,
name='problem_submissions_rejudge_success'),
url('^/rescore/all$', problem_manage.RescoreAllSubmissionsView.as_view(),
name='problem_submissions_rescore_all'),
url('^/rescore/success/(?P<task_id>[A-Za-z0-9-]*)$', problem_manage.rescore_success,
name='problem_submissions_rescore_success'),
])),
])),
url(r'^submissions/', paged_list_view(submission.AllSubmissions, 'all_submissions')),
url(r'^submissions/user/(?P<user>\w+)/', paged_list_view(submission.AllUserSubmissions, 'all_user_submissions')),
url(r'^src/(?P<submission>\d+)$', submission.SubmissionSource.as_view(), name='submission_source'),
url(r'^src/(?P<submission>\d+)/raw$', submission.SubmissionSourceRaw.as_view(), name='submission_source_raw'),
url(r'^submission/(?P<submission>\d+)', include([
url(r'^$', submission.SubmissionStatus.as_view(), name='submission_status'),
url(r'^/abort$', submission.abort_submission, name='submission_abort'),
url(r'^/html$', submission.single_submission),
])),
url(r'^users/', include([
url(r'^$', user.users, name='user_list'),
url(r'^(?P<page>\d+)$', lambda request, page:
HttpResponsePermanentRedirect('%s?page=%s' % (reverse('user_list'), page))),
url(r'^find$', user.user_ranking_redirect, name='user_ranking_redirect'),
])),
url(r'^user$', user.UserAboutPage.as_view(), name='user_page'),
url(r'^edit/profile/$', user.edit_profile, name='user_edit_profile'),
url(r'^user/(?P<user>\w+)', include([
url(r'^$', user.UserAboutPage.as_view(), name='user_page'),
url(r'^/solved', include([
url(r'^$', user.UserProblemsPage.as_view(), name='user_problems'),
url(r'/ajax$', user.UserPerformancePointsAjax.as_view(), name='user_pp_ajax'),
])),
url(r'^/submissions/', paged_list_view(submission.AllUserSubmissions, 'all_user_submissions_old')),
url(r'^/submissions/', lambda _, user:
HttpResponsePermanentRedirect(reverse('all_user_submissions', args=[user]))),
url(r'^/$', lambda _, user: HttpResponsePermanentRedirect(reverse('user_page', args=[user]))),
])),
url(r'^comments/upvote/$', comment.upvote_comment, name='comment_upvote'),
url(r'^comments/downvote/$', comment.downvote_comment, name='comment_downvote'),
url(r'^comments/hide/$', comment.comment_hide, name='comment_hide'),
url(r'^comments/(?P<id>\d+)/', include([
url(r'^edit$', comment.CommentEdit.as_view(), name='comment_edit'),
url(r'^history/ajax$', comment.CommentRevisionAjax.as_view(), name='comment_revision_ajax'),
url(r'^edit/ajax$', comment.CommentEditAjax.as_view(), name='comment_edit_ajax'),
url(r'^votes/ajax$', comment.CommentVotesAjax.as_view(), name='comment_votes_ajax'),
url(r'^render$', comment.CommentContent.as_view(), name='comment_content'),
])),
url(r'^contests/', paged_list_view(contests.ContestList, 'contest_list')),
url(r'^contests/(?P<year>\d+)/(?P<month>\d+)/$', contests.ContestCalendar.as_view(), name='contest_calendar'),
url(r'^contests/tag/(?P<name>[a-z-]+)', include([
url(r'^$', contests.ContestTagDetail.as_view(), name='contest_tag'),
url(r'^/ajax$', contests.ContestTagDetailAjax.as_view(), name='contest_tag_ajax'),
])),
url(r'^contest/(?P<contest>\w+)', include([
url(r'^$', contests.ContestDetail.as_view(), name='contest_view'),
url(r'^/moss$', contests.ContestMossView.as_view(), name='contest_moss'),
url(r'^/moss/delete$', contests.ContestMossDelete.as_view(), name='contest_moss_delete'),
url(r'^/clone$', contests.ContestClone.as_view(), name='contest_clone'),
url(r'^/ranking/$', contests.ContestRanking.as_view(), name='contest_ranking'),
url(r'^/ranking/ajax$', contests.contest_ranking_ajax, name='contest_ranking_ajax'),
url(r'^/join$', contests.ContestJoin.as_view(), name='contest_join'),
url(r'^/leave$', contests.ContestLeave.as_view(), name='contest_leave'),
url(r'^/stats$', contests.ContestStats.as_view(), name='contest_stats'),
url(r'^/rank/(?P<problem>\w+)/',
paged_list_view(ranked_submission.ContestRankedSubmission, 'contest_ranked_submissions')),
url(r'^/submissions/(?P<user>\w+)/(?P<problem>\w+)/',
paged_list_view(submission.UserContestSubmissions, 'contest_user_submissions')),
url(r'^/participations$', contests.ContestParticipationList.as_view(), name='contest_participation_own'),
url(r'^/participations/(?P<user>\w+)$',
contests.ContestParticipationList.as_view(), name='contest_participation'),
url(r'^/participation/disqualify$', contests.ContestParticipationDisqualify.as_view(),
name='contest_participation_disqualify'),
url(r'^/$', lambda _, contest: HttpResponsePermanentRedirect(reverse('contest_view', args=[contest]))),
])),
url(r'^organizations/$', organization.OrganizationList.as_view(), name='organization_list'),
url(r'^organization/(?P<pk>\d+)-(?P<slug>[\w-]*)', include([
url(r'^$', organization.OrganizationHome.as_view(), name='organization_home'),
url(r'^/users$', organization.OrganizationUsers.as_view(), name='organization_users'),
url(r'^/join$', organization.JoinOrganization.as_view(), name='join_organization'),
url(r'^/leave$', organization.LeaveOrganization.as_view(), name='leave_organization'),
url(r'^/edit$', organization.EditOrganization.as_view(), name='edit_organization'),
url(r'^/kick$', organization.KickUserWidgetView.as_view(), name='organization_user_kick'),
url(r'^/request$', organization.RequestJoinOrganization.as_view(), name='request_organization'),
url(r'^/request/(?P<rpk>\d+)$', organization.OrganizationRequestDetail.as_view(),
name='request_organization_detail'),
url(r'^/requests/', include([
url(r'^pending$', organization.OrganizationRequestView.as_view(), name='organization_requests_pending'),
url(r'^log$', organization.OrganizationRequestLog.as_view(), name='organization_requests_log'),
url(r'^approved$', organization.OrganizationRequestLog.as_view(states=('A',), tab='approved'),
name='organization_requests_approved'),
url(r'^rejected$', organization.OrganizationRequestLog.as_view(states=('R',), tab='rejected'),
name='organization_requests_rejected'),
])),
url(r'^/$', lambda _, pk, slug: HttpResponsePermanentRedirect(reverse('organization_home', args=[pk, slug]))),
])),
url(r'^runtimes/$', language.LanguageList.as_view(), name='runtime_list'),
url(r'^runtimes/matrix/$', status.version_matrix, name='version_matrix'),
url(r'^status/$', status.status_all, name='status_all'),
url(r'^api/', include([
url(r'^contest/list$', api.api_v1_contest_list),
url(r'^contest/info/(\w+)$', api.api_v1_contest_detail),
url(r'^problem/list$', api.api_v1_problem_list),
url(r'^problem/info/(\w+)$', api.api_v1_problem_info),
url(r'^user/list$', api.api_v1_user_list),
url(r'^user/info/(\w+)$', api.api_v1_user_info),
url(r'^user/submissions/(\w+)$', api.api_v1_user_submissions),
])),
url(r'^blog/', paged_list_view(blog.PostList, 'blog_post_list')),
url(r'^post/(?P<id>\d+)-(?P<slug>.*)$', blog.PostView.as_view(), name='blog_post'),
url(r'^license/(?P<key>[-\w.]+)$', license.LicenseDetail.as_view(), name='license'),
url(r'^mailgun/mail_activate/$', mailgun.MailgunActivationView.as_view(), name='mailgun_activate'),
url(r'^widgets/', include([
url(r'^rejudge$', widgets.rejudge_submission, name='submission_rejudge'),
url(r'^single_submission$', submission.single_submission_query, name='submission_single_query'),
url(r'^submission_testcases$', submission.SubmissionTestCaseQuery.as_view(), name='submission_testcases_query'),
url(r'^detect_timezone$', widgets.DetectTimezone.as_view(), name='detect_timezone'),
url(r'^status-table$', status.status_table, name='status_table'),
url(r'^template$', problem.LanguageTemplateAjax.as_view(), name='language_template_ajax'),
url(r'^select2/', include([
url(r'^user_search$', UserSearchSelect2View.as_view(), name='user_search_select2_ajax'),
url(r'^contest_users/(?P<contest>\w+)$', ContestUserSearchSelect2View.as_view(),
name='contest_user_search_select2_ajax'),
url(r'^ticket_user$', TicketUserSelect2View.as_view(), name='ticket_user_select2_ajax'),
url(r'^ticket_assignee$', AssigneeSelect2View.as_view(), name='ticket_assignee_select2_ajax'),
])),
url(r'^preview/', include([
url(r'^problem$', preview.ProblemMarkdownPreviewView.as_view(), name='problem_preview'),
url(r'^blog$', preview.BlogMarkdownPreviewView.as_view(), name='blog_preview'),
url(r'^contest$', preview.ContestMarkdownPreviewView.as_view(), name='contest_preview'),
url(r'^comment$', preview.CommentMarkdownPreviewView.as_view(), name='comment_preview'),
url(r'^profile$', preview.ProfileMarkdownPreviewView.as_view(), name='profile_preview'),
url(r'^organization$', preview.OrganizationMarkdownPreviewView.as_view(), name='organization_preview'),
url(r'^solution$', preview.SolutionMarkdownPreviewView.as_view(), name='solution_preview'),
url(r'^license$', preview.LicenseMarkdownPreviewView.as_view(), name='license_preview'),
url(r'^ticket$', preview.TicketMarkdownPreviewView.as_view(), name='ticket_preview'),
])),
])),
url(r'^feed/', include([
url(r'^problems/rss/$', ProblemFeed(), name='problem_rss'),
url(r'^problems/atom/$', AtomProblemFeed(), name='problem_atom'),
url(r'^comment/rss/$', CommentFeed(), name='comment_rss'),
url(r'^comment/atom/$', AtomCommentFeed(), name='comment_atom'),
url(r'^blog/rss/$', BlogFeed(), name='blog_rss'),
url(r'^blog/atom/$', AtomBlogFeed(), name='blog_atom'),
])),
url(r'^stats/', include([
url('^language/', include([
url('^$', stats.language, name='language_stats'),
url('^data/all/$', stats.language_data, name='language_stats_data_all'),
url('^data/ac/$', stats.ac_language_data, name='language_stats_data_ac'),
url('^data/status/$', stats.status_data, name='stats_data_status'),
url('^data/ac_rate/$', stats.ac_rate, name='language_stats_data_ac_rate'),
])),
])),
url(r'^tickets/', include([
url(r'^$', ticket.TicketList.as_view(), name='ticket_list'),
url(r'^ajax$', ticket.TicketListDataAjax.as_view(), name='ticket_ajax'),
])),
url(r'^ticket/(?P<pk>\d+)', include([
url(r'^$', ticket.TicketView.as_view(), name='ticket'),
url(r'^/ajax$', ticket.TicketMessageDataAjax.as_view(), name='ticket_message_ajax'),
url(r'^/open$', ticket.TicketStatusChangeView.as_view(open=True), name='ticket_open'),
url(r'^/close$', ticket.TicketStatusChangeView.as_view(open=False), name='ticket_close'),
url(r'^/notes$', ticket.TicketNotesEditView.as_view(), name='ticket_notes'),
])),
url(r'^sitemap\.xml$', sitemap, {'sitemaps': {
'problem': ProblemSitemap,
'user': UserSitemap,
'home': HomePageSitemap,
'contest': ContestSitemap,
'organization': OrganizationSitemap,
'blog': BlogPostSitemap,
'solutions': SolutionSitemap,
'pages': UrlSitemap([
{'location': '/about/', 'priority': 0.9},
]),
}}),
url(r'^judge-select2/', include([
url(r'^profile/$', UserSelect2View.as_view(), name='profile_select2'),
url(r'^organization/$', OrganizationSelect2View.as_view(), name='organization_select2'),
url(r'^problem/$', ProblemSelect2View.as_view(), name='problem_select2'),
url(r'^contest/$', ContestSelect2View.as_view(), name='contest_select2'),
url(r'^comment/$', CommentSelect2View.as_view(), name='comment_select2'),
])),
url(r'^tasks/', include([
url(r'^status/(?P<task_id>[A-Za-z0-9-]*)$', tasks.task_status, name='task_status'),
url(r'^ajax_status$', tasks.task_status_ajax, name='task_status_ajax'),
url(r'^success$', tasks.demo_success),
url(r'^failure$', tasks.demo_failure),
url(r'^progress$', tasks.demo_progress),
])),
]
favicon_paths = ['apple-touch-icon-180x180.png', 'apple-touch-icon-114x114.png', 'android-chrome-72x72.png',
'apple-touch-icon-57x57.png', 'apple-touch-icon-72x72.png', 'apple-touch-icon.png', 'mstile-70x70.png',
'android-chrome-36x36.png', 'apple-touch-icon-precomposed.png', 'apple-touch-icon-76x76.png',
'apple-touch-icon-60x60.png', 'android-chrome-96x96.png', 'mstile-144x144.png', 'mstile-150x150.png',
'safari-pinned-tab.svg', 'android-chrome-144x144.png', 'apple-touch-icon-152x152.png',
'favicon-96x96.png',
'favicon-32x32.png', 'favicon-16x16.png', 'android-chrome-192x192.png', 'android-chrome-48x48.png',
'mstile-310x150.png', 'apple-touch-icon-144x144.png', 'browserconfig.xml', 'manifest.json',
'apple-touch-icon-120x120.png', 'mstile-310x310.png']
for favicon in favicon_paths:
urlpatterns.append(url(r'^%s$' % favicon, RedirectView.as_view(
url=lazystr(lambda: static('icons/' + favicon)),
)))
handler404 = 'judge.views.error.error404'
handler403 = 'judge.views.error.error403'
handler500 = 'judge.views.error.error500'
if 'newsletter' in settings.INSTALLED_APPS:
urlpatterns.append(url(r'^newsletter/', include('newsletter.urls')))
if 'impersonate' in settings.INSTALLED_APPS:
urlpatterns.append(url(r'^impersonate/', include('impersonate.urls')))

12
dmoj/wsgi.py Normal file
View file

@ -0,0 +1,12 @@
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dmoj.settings')
try:
import MySQLdb # noqa: F401, imported for side effect
except ImportError:
import pymysql
pymysql.install_as_MySQLdb()
from django.core.wsgi import get_wsgi_application # noqa: E402, django must be imported here
application = get_wsgi_application()

14
dmoj/wsgi_async.py Normal file
View file

@ -0,0 +1,14 @@
import os
import gevent.monkey # noqa: I100, gevent must be imported here
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
# noinspection PyUnresolvedReferences
import django_2_2_pymysql_patch # noqa: I100, F401, I202, imported for side effect
application = get_wsgi_application()