mirror of
https://github.com/DMOJ/online-judge.git
synced 2024-11-25 16:32:37 +08:00
Moves constants to 'settings.py'; #993
This commit is contained in:
parent
e72ccf3150
commit
f479d87f16
@ -9,8 +9,6 @@ from django.conf import settings
|
||||
from django.forms.utils import flatatt
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
ACE_URL = getattr(settings, 'ACE_URL', '//cdnjs.cloudflare.com/ajax/libs/ace/1.1.3/ext-split.js')
|
||||
|
||||
|
||||
class AceWidget(forms.Textarea):
|
||||
def __init__(self, mode=None, theme=None, wordwrap=False, width='100%', height='300px',
|
||||
@ -25,7 +23,7 @@ class AceWidget(forms.Textarea):
|
||||
|
||||
@property
|
||||
def media(self):
|
||||
js = [urljoin(ACE_URL, 'ace.js')] if self.ace_media else []
|
||||
js = [urljoin(settings.ACE_URL, 'ace.js')] if self.ace_media else []
|
||||
js.append('django_ace/widget.js')
|
||||
css = {
|
||||
'screen': ['django_ace/widget.css'],
|
||||
|
@ -10,6 +10,7 @@ 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
|
||||
@ -31,8 +32,89 @@ ALLOWED_HOSTS = []
|
||||
SITE_ID = 1
|
||||
SITE_NAME = 'DMOJ'
|
||||
SITE_LONG_NAME = 'DMOJ: Modern Online Judge'
|
||||
SITE_ADMIN_EMAIL = False
|
||||
|
||||
|
||||
# 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/ext-split.js'
|
||||
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_RATING_COLORS = False
|
||||
DMOJ_EMAIL_THROTTLING = (10, 60)
|
||||
DMOJ_STATS_LANGUAGE_THRESHOLD = 10
|
||||
DMOJ_SUBMISSIONS_REJUDGE_LIMIT = 10
|
||||
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()
|
||||
|
||||
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 = 'PY2'
|
||||
|
||||
PHANTOMJS = ''
|
||||
PHANTOMJS_PDF_ZOOM = 0.75
|
||||
PHANDOMJS_PDF_TIMEOUT = 5.0
|
||||
PHANTOMJS_PAPER_SIZE = 'Letter'
|
||||
|
||||
SLIMERJS = ''
|
||||
SLIMERJS_PDF_ZOOM = 0.75
|
||||
SLIMERJS_FIREFOX_PATH = ''
|
||||
SLIDERJS_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/2.1.4/jquery.min.js'
|
||||
FONTAWESOME_CSS = '//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css'
|
||||
DMOJ_CANONICAL = ''
|
||||
|
||||
# Application definition
|
||||
|
||||
@ -312,6 +394,7 @@ ENABLE_FTS = False
|
||||
|
||||
# Bridged configuration
|
||||
BRIDGED_JUDGE_ADDRESS = [('localhost', 9999)]
|
||||
BRIDGED_JUDGE_PROXIES = None
|
||||
BRIDGED_DJANGO_ADDRESS = [('localhost', 9998)]
|
||||
BRIDGED_DJANGO_CONNECT = None
|
||||
|
||||
@ -321,6 +404,7 @@ 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
|
||||
|
@ -8,7 +8,7 @@ DEFAULT_THROTTLE = (10, 60)
|
||||
|
||||
|
||||
def new_email():
|
||||
cache.add('error_email_throttle', 0, getattr(settings, 'DMOJ_EMAIL_THROTTLING', DEFAULT_THROTTLE)[1])
|
||||
cache.add('error_email_throttle', 0, settings.DMOJ_EMAIL_THROTTLING[1])
|
||||
return cache.incr('error_email_throttle')
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@ class ThrottledEmailHandler(AdminEmailHandler):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(ThrottledEmailHandler, self).__init__(*args, **kwargs)
|
||||
|
||||
self.throttle = getattr(settings, 'DMOJ_EMAIL_THROTTLING', DEFAULT_THROTTLE)[0]
|
||||
self.throttle = settings.DMOJ_EMAIL_THROTTLING[0]
|
||||
|
||||
def emit(self, record):
|
||||
try:
|
||||
|
@ -182,7 +182,7 @@ class ContestAdmin(VersionAdmin):
|
||||
|
||||
queryset = ContestSubmission.objects.filter(problem_id=problem_id).select_related('submission')
|
||||
if not request.user.has_perm('judge.rejudge_submission_lot') and \
|
||||
len(queryset) > getattr(settings, 'DMOJ_SUBMISSIONS_REJUDGE_LIMIT', 10):
|
||||
len(queryset) > settings.DMOJ_SUBMISSIONS_REJUDGE_LIMIT:
|
||||
self.message_user(request, ugettext('You do not have the permission to rejudge THAT many submissions.'),
|
||||
level=messages.ERROR)
|
||||
return
|
||||
|
@ -151,7 +151,7 @@ class SubmissionAdmin(admin.ModelAdmin):
|
||||
return
|
||||
queryset = queryset.order_by('id')
|
||||
if not request.user.has_perm('judge.rejudge_submission_lot') and \
|
||||
queryset.count() > getattr(settings, 'DMOJ_SUBMISSIONS_REJUDGE_LIMIT', 10):
|
||||
queryset.count() > settings.DMOJ_SUBMISSIONS_REJUDGE_LIMIT:
|
||||
self.message_user(request, gettext('You do not have the permission to rejudge THAT many submissions.'),
|
||||
level=messages.ERROR)
|
||||
return
|
||||
|
@ -117,6 +117,6 @@ class CommentedDetailView(TemplateResponseMixin, SingleObjectMixin, View):
|
||||
context['is_new_user'] = (not self.request.user.is_staff and
|
||||
not profile.submission_set.filter(points=F('problem__points')).exists())
|
||||
context['comment_list'] = queryset
|
||||
context['vote_hide_threshold'] = getattr(settings, 'DMOJ_COMMENT_VOTE_HIDE_THRESHOLD', -5)
|
||||
context['vote_hide_threshold'] = settings.DMOJ_COMMENT_VOTE_HIDE_THRESHOLD
|
||||
|
||||
return context
|
||||
|
@ -2,7 +2,7 @@ from django.conf import settings
|
||||
|
||||
__all__ = ['last', 'post']
|
||||
|
||||
if not getattr(settings, 'EVENT_DAEMON_USE', False):
|
||||
if not settings.EVENT_DAEMON_USE:
|
||||
real = False
|
||||
|
||||
def post(channel, message):
|
||||
|
@ -12,7 +12,7 @@ __all__ = ['EventPoster', 'post', 'last']
|
||||
class EventPoster(object):
|
||||
def __init__(self):
|
||||
self._connect()
|
||||
self._exchange = getattr(settings, 'EVENT_DAEMON_AMQP_EXCHANGE', 'dmoj-events')
|
||||
self._exchange = settings.EVENT_DAEMON_AMQP_EXCHANGE
|
||||
|
||||
def _connect(self):
|
||||
self._conn = pika.BlockingConnection(pika.URLParameters(settings.EVENT_DAEMON_AMQP))
|
||||
|
@ -10,11 +10,9 @@ from judge.models import BlogPost, Comment, Problem
|
||||
|
||||
|
||||
class ProblemFeed(Feed):
|
||||
title = 'Recently Added %s Problems' % getattr(settings, 'SITE_NAME', 'DMOJ')
|
||||
title = 'Recently Added %s Problems' % settings.SITE_NAME
|
||||
link = '/'
|
||||
description = 'The latest problems added on the %s website' % (
|
||||
getattr(settings, 'SITE_LONG_NAME', getattr(settings, 'SITE_NAME', 'DMOJ'))
|
||||
)
|
||||
description = 'The latest problems added on the %s website' % settings.SITE_LONG_NAME
|
||||
|
||||
def items(self):
|
||||
return Problem.objects.filter(is_public=True, is_organization_private=False).order_by('-date', '-id')[:25]
|
||||
@ -42,11 +40,9 @@ class AtomProblemFeed(ProblemFeed):
|
||||
|
||||
|
||||
class CommentFeed(Feed):
|
||||
title = 'Latest %s Comments' % getattr(settings, 'SITE_NAME', 'DMOJ')
|
||||
title = 'Latest %s Comments' % settings.SITE_NAME
|
||||
link = '/'
|
||||
description = 'The latest comments on the %s website' % (
|
||||
getattr(settings, 'SITE_LONG_NAME', getattr(settings, 'SITE_NAME', 'DMOJ'))
|
||||
)
|
||||
description = 'The latest comments on the %s website' % settings.SITE_LONG_NAME
|
||||
|
||||
def items(self):
|
||||
return Comment.most_recent(AnonymousUser(), 25)
|
||||
@ -74,11 +70,9 @@ class AtomCommentFeed(CommentFeed):
|
||||
|
||||
|
||||
class BlogFeed(Feed):
|
||||
title = 'Latest %s Blog Posts' % getattr(settings, 'SITE_NAME', 'DMOJ')
|
||||
title = 'Latest %s Blog Posts' % settings.SITE_NAME
|
||||
link = '/'
|
||||
description = 'The latest blog posts from the %s' % (
|
||||
getattr(settings, 'SITE_LONG_NAME', getattr(settings, 'SITE_NAME', 'DMOJ'))
|
||||
)
|
||||
description = 'The latest blog posts from the %s' % settings.SITE_LONG_NAME
|
||||
|
||||
def items(self):
|
||||
return BlogPost.objects.filter(visible=True, publish_on__lte=timezone.now()).order_by('-sticky', '-publish_on')
|
||||
|
@ -37,7 +37,7 @@ class ProfileForm(ModelForm):
|
||||
'ace_theme': Select2Widget(attrs={'style': 'width:200px'}),
|
||||
}
|
||||
|
||||
has_math_config = bool(getattr(settings, 'MATHOID_URL', False))
|
||||
has_math_config = bool(settings.MATHOID_URL)
|
||||
if has_math_config:
|
||||
fields.append('math_engine')
|
||||
widgets['math_engine'] = Select2Widget(attrs={'style': 'width:200px'})
|
||||
@ -50,7 +50,7 @@ class ProfileForm(ModelForm):
|
||||
|
||||
def clean(self):
|
||||
organizations = self.cleaned_data.get('organizations') or []
|
||||
max_orgs = getattr(settings, 'DMOJ_USER_MAX_ORGANIZATION_COUNT', 3)
|
||||
max_orgs = settings.DMOJ_USER_MAX_ORGANIZATION_COUNT
|
||||
|
||||
if sum(org.is_open for org in organizations) > max_orgs:
|
||||
raise ValidationError(
|
||||
@ -124,7 +124,7 @@ class NoAutoCompleteCharField(forms.CharField):
|
||||
|
||||
|
||||
class TOTPForm(Form):
|
||||
TOLERANCE = getattr(settings, 'DMOJ_TOTP_TOLERANCE_HALF_MINUTES', 1)
|
||||
TOLERANCE = settings.DMOJ_TOTP_TOLERANCE_HALF_MINUTES
|
||||
|
||||
totp_token = NoAutoCompleteCharField(validators=[
|
||||
RegexValidator('^[0-9]{6}$', _('Two Factor Authentication tokens must be 6 decimal digits.')),
|
||||
|
@ -18,7 +18,7 @@ from .. import registry
|
||||
|
||||
logger = logging.getLogger('judge.html')
|
||||
|
||||
NOFOLLOW_WHITELIST = getattr(settings, 'NOFOLLOW_EXCLUDED', set())
|
||||
NOFOLLOW_WHITELIST = settings.NOFOLLOW_EXCLUDED
|
||||
|
||||
|
||||
class CodeSafeInlineGrammar(mistune.InlineGrammar):
|
||||
@ -105,7 +105,7 @@ class AwesomeRenderer(MathRenderer, mistune.Renderer):
|
||||
|
||||
@registry.filter
|
||||
def markdown(value, style, math_engine=None, lazy_load=False):
|
||||
styles = getattr(settings, 'MARKDOWN_STYLES', {}).get(style, getattr(settings, 'MARKDOWN_DEFAULT_STYLE', {}))
|
||||
styles = settings.MARKDOWN_STYLES.get(style, settings.MARKDOWN_DEFAULT_STYLE)
|
||||
escape = styles.get('safe_mode', True)
|
||||
nofollow = styles.get('nofollow', True)
|
||||
texoid = TEXOID_ENABLED and styles.get('texoid', False)
|
||||
|
@ -22,7 +22,7 @@ def _post_update_submission(submission, done=False):
|
||||
|
||||
|
||||
def judge_request(packet, reply=True):
|
||||
sock = socket.create_connection(getattr(settings, 'BRIDGED_DJANGO_CONNECT', None) or
|
||||
sock = socket.create_connection(settings.BRIDGED_DJANGO_CONNECT or
|
||||
settings.BRIDGED_DJANGO_ADDRESS[0])
|
||||
|
||||
output = json.dumps(packet, separators=(',', ':'))
|
||||
|
@ -16,7 +16,7 @@ class Command(BaseCommand):
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
proxies = getattr(settings, 'BRIDGED_JUDGE_PROXIES', None)
|
||||
proxies = settings.BRIDGED_JUDGE_PROXIES
|
||||
if proxies:
|
||||
judge_handler = judge_handler.with_proxy_set(proxies)
|
||||
|
||||
|
@ -76,7 +76,7 @@ class Profile(models.Model):
|
||||
user = models.OneToOneField(User, verbose_name=_('user associated'), on_delete=models.CASCADE)
|
||||
about = models.TextField(verbose_name=_('self-description'), null=True, blank=True)
|
||||
timezone = models.CharField(max_length=50, verbose_name=_('location'), choices=TIMEZONE,
|
||||
default=getattr(settings, 'DEFAULT_USER_TIME_ZONE', 'America/Toronto'))
|
||||
default=settings.DEFAULT_USER_TIME_ZONE)
|
||||
language = models.ForeignKey('Language', verbose_name=_('preferred language'), on_delete=models.CASCADE)
|
||||
points = models.FloatField(default=0, db_index=True)
|
||||
performance_points = models.FloatField(default=0, db_index=True)
|
||||
@ -98,7 +98,7 @@ class Profile(models.Model):
|
||||
current_contest = models.OneToOneField('ContestParticipation', verbose_name=_('current contest'),
|
||||
null=True, blank=True, related_name='+', on_delete=models.SET_NULL)
|
||||
math_engine = models.CharField(verbose_name=_('math engine'), choices=MATH_ENGINES_CHOICES, max_length=4,
|
||||
default=getattr(settings, 'MATHOID_DEFAULT_TYPE', 'auto'),
|
||||
default=settings.MATHOID_DEFAULT_TYPE,
|
||||
help_text=_('the rendering engine used to render math'))
|
||||
is_totp_enabled = models.BooleanField(verbose_name=_('2FA enabled'), default=False,
|
||||
help_text=_('check to enable TOTP-based two factor authentication'))
|
||||
@ -119,8 +119,7 @@ class Profile(models.Model):
|
||||
def username(self):
|
||||
return self.user.username
|
||||
|
||||
_pp_table = [pow(getattr(settings, 'DMOJ_PP_STEP', 0.95), i)
|
||||
for i in range(getattr(settings, 'DMOJ_PP_ENTRIES', 100))]
|
||||
_pp_table = [pow(settings.DMOJ_PP_STEP, i) for i in range(settings.DMOJ_PP_ENTRIES)]
|
||||
|
||||
def calculate_points(self, table=_pp_table):
|
||||
from judge.models import Problem
|
||||
@ -130,7 +129,7 @@ class Profile(models.Model):
|
||||
.values_list('max_points', flat=True).filter(max_points__gt=0))
|
||||
extradata = Problem.objects.filter(submission__user=self, submission__result='AC', is_public=True) \
|
||||
.values('id').distinct().count()
|
||||
bonus_function = getattr(settings, 'DMOJ_PP_BONUS_FUNCTION', lambda n: 300 * (1 - 0.997 ** n))
|
||||
bonus_function = settings.DMOJ_PP_BONUS_FUNCTION
|
||||
points = sum(data)
|
||||
problems = len(data)
|
||||
entries = min(len(data), len(table))
|
||||
@ -164,7 +163,7 @@ class Profile(models.Model):
|
||||
return self.user.username
|
||||
|
||||
@classmethod
|
||||
def get_user_css_class(cls, display_rank, rating, rating_colors=getattr(settings, 'DMOJ_RATING_COLORS', False)):
|
||||
def get_user_css_class(cls, display_rank, rating, rating_colors=settings.DMOJ_RATING_COLORS):
|
||||
if rating_colors:
|
||||
return 'rating %s %s' % (rating_class(rating) if rating is not None else 'rate-none', display_rank)
|
||||
return display_rank
|
||||
|
@ -5,23 +5,22 @@ import logging
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import uuid
|
||||
|
||||
from django.conf import settings
|
||||
from django.utils.translation import gettext
|
||||
|
||||
HAS_PHANTOMJS = os.access(getattr(settings, 'PHANTOMJS', ''), os.X_OK)
|
||||
HAS_SLIMERJS = os.access(getattr(settings, 'SLIMERJS', ''), os.X_OK)
|
||||
HAS_PHANTOMJS = os.access(settings.PHANTOMJS, os.X_OK)
|
||||
HAS_SLIMERJS = os.access(settings.SLIMERJS, os.X_OK)
|
||||
|
||||
NODE_PATH = getattr(settings, 'NODEJS', '/usr/bin/node')
|
||||
PUPPETEER_MODULE = getattr(settings, 'PUPPETEER_MODULE', '/usr/lib/node_modules/puppeteer')
|
||||
NODE_PATH = settings.NODEJS
|
||||
PUPPETEER_MODULE = settings.PUPPETEER_MODULE
|
||||
HAS_PUPPETEER = os.access(NODE_PATH, os.X_OK) and os.path.isdir(PUPPETEER_MODULE)
|
||||
|
||||
HAS_PDF = (os.path.isdir(getattr(settings, 'DMOJ_PDF_PROBLEM_CACHE', '')) and
|
||||
HAS_PDF = (os.path.isdir(settings.DMOJ_PDF_PROBLEM_CACHE) and
|
||||
(HAS_PHANTOMJS or HAS_SLIMERJS or HAS_PUPPETEER))
|
||||
|
||||
EXIFTOOL = getattr(settings, 'EXIFTOOL', '/usr/bin/exiftool')
|
||||
EXIFTOOL = settings.EXIFTOOL
|
||||
HAS_EXIFTOOL = os.access(EXIFTOOL, os.X_OK)
|
||||
|
||||
logger = logging.getLogger('judge.problem.pdf')
|
||||
@ -32,8 +31,7 @@ class BasePdfMaker(object):
|
||||
title = None
|
||||
|
||||
def __init__(self, dir=None, clean_up=True):
|
||||
self.dir = dir or os.path.join(getattr(settings, 'DMOJ_PDF_PROBLEM_TEMP_DIR', tempfile.gettempdir()),
|
||||
str(uuid.uuid1()))
|
||||
self.dir = dir or os.path.join(settings.DMOJ_PDF_PROBLEM_TEMP_DIR, str(uuid.uuid1()))
|
||||
self.proc = None
|
||||
self.log = None
|
||||
self.htmlfile = os.path.join(self.dir, 'input.html')
|
||||
@ -129,10 +127,10 @@ page.open(param.input, function (status) {
|
||||
|
||||
def get_render_script(self):
|
||||
return self.template.replace('{params}', json.dumps({
|
||||
'zoom': getattr(settings, 'PHANTOMJS_PDF_ZOOM', 0.75),
|
||||
'timeout': int(getattr(settings, 'PHANTOMJS_PDF_TIMEOUT', 5.0) * 1000),
|
||||
'zoom': settings.PHANTOMJS_PDF_ZOOM,
|
||||
'timeout': int(settings.PHANTOMJS_PDF_TIMEOUT * 1000),
|
||||
'input': 'input.html', 'output': 'output.pdf',
|
||||
'paper': getattr(settings, 'PHANTOMJS_PAPER_SIZE', 'Letter'),
|
||||
'paper': settings.PHANTOMJS_PAPER_SIZE,
|
||||
'footer': gettext('Page [page] of [topage]'),
|
||||
}))
|
||||
|
||||
@ -182,9 +180,9 @@ try {
|
||||
|
||||
def get_render_script(self):
|
||||
return self.template.replace('{params}', json.dumps({
|
||||
'zoom': getattr(settings, 'SLIMERJS_PDF_ZOOM', 0.75),
|
||||
'zoom': settings.SLIMERJS_PDF_ZOOM,
|
||||
'input': 'input.html', 'output': 'output.pdf',
|
||||
'paper': getattr(settings, 'SLIMERJS_PAPER_SIZE', 'Letter'),
|
||||
'paper': settings.SLIMERJS_PAPER_SIZE,
|
||||
'footer': gettext('Page [page] of [topage]').replace('[page]', '&P').replace('[topage]', '&L'),
|
||||
}))
|
||||
|
||||
@ -193,7 +191,7 @@ try {
|
||||
f.write(self.get_render_script())
|
||||
|
||||
env = None
|
||||
firefox = getattr(settings, 'SLIMERJS_FIREFOX_PATH', '')
|
||||
firefox = settings.SLIMERJS_FIREFOX_PATH
|
||||
if firefox:
|
||||
env = os.environ.copy()
|
||||
env['SLIMERJSLAUNCHER'] = firefox
|
||||
@ -244,7 +242,7 @@ puppeteer.launch().then(browser => Promise.resolve()
|
||||
return self.template.replace('{params}', json.dumps({
|
||||
'input': 'file://' + os.path.abspath(os.path.join(self.dir, 'input.html')),
|
||||
'output': os.path.abspath(os.path.join(self.dir, 'output.pdf')),
|
||||
'paper': getattr(settings, 'PUPPETEER_PAPER_SIZE', 'Letter'),
|
||||
'paper': settings.PUPPETEER_PAPER_SIZE,
|
||||
'footer': gettext('Page [page] of [topage]'),
|
||||
}))
|
||||
|
||||
|
@ -6,16 +6,14 @@ from django.db import connection
|
||||
from judge.models import Submission
|
||||
from judge.timezone import from_database_time
|
||||
|
||||
PP_STEP = getattr(settings, 'DMOJ_PP_STEP', 0.95)
|
||||
PP_ENTRIES = getattr(settings, 'DMOJ_PP_ENTRIES', 100)
|
||||
PP_WEIGHT_TABLE = [pow(PP_STEP, i) for i in range(PP_ENTRIES)]
|
||||
PP_WEIGHT_TABLE = [pow(settings.DMOJ_PP_STEP, i) for i in range(settings.DMOJ_PP_ENTRIES)]
|
||||
|
||||
PPBreakdown = namedtuple('PPBreakdown', 'points weight scaled_points problem_name problem_code '
|
||||
'sub_id sub_date sub_points sub_total sub_result_class '
|
||||
'sub_short_status sub_long_status sub_lang')
|
||||
|
||||
|
||||
def get_pp_breakdown(user, start=0, end=PP_ENTRIES):
|
||||
def get_pp_breakdown(user, start=0, end=settings.DMOJ_PP_ENTRIES):
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute('''
|
||||
SELECT max_points_table.problem_code,
|
||||
|
@ -16,7 +16,7 @@ class FixedSimpleLazyObject(SimpleLazyObject):
|
||||
|
||||
|
||||
def get_resource(request):
|
||||
use_https = getattr(settings, 'DMOJ_SSL', 0)
|
||||
use_https = settings.DMOJ_SSL
|
||||
if use_https == 1:
|
||||
scheme = 'https' if request.is_secure() else 'http'
|
||||
elif use_https > 1:
|
||||
@ -24,14 +24,13 @@ def get_resource(request):
|
||||
else:
|
||||
scheme = 'http'
|
||||
return {
|
||||
'PYGMENT_THEME': getattr(settings, 'PYGMENT_THEME', None),
|
||||
'INLINE_JQUERY': getattr(settings, 'INLINE_JQUERY', True),
|
||||
'INLINE_FONTAWESOME': getattr(settings, 'INLINE_FONTAWESOME', True),
|
||||
'JQUERY_JS': getattr(settings, 'JQUERY_JS', '//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js'),
|
||||
'FONTAWESOME_CSS': getattr(settings, 'FONTAWESOME_CSS',
|
||||
'//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css'),
|
||||
'PYGMENT_THEME': settings.PYGMENT_THEME,
|
||||
'INLINE_JQUERY': settings.INLINE_JQUERY,
|
||||
'INLINE_FONTAWESOME': settings.INLINE_FONTAWESOME,
|
||||
'JQUERY_JS': settings.JQUERY_JS,
|
||||
'FONTAWESOME_CSS': settings.FONTAWESOME_CSS,
|
||||
'DMOJ_SCHEME': scheme,
|
||||
'DMOJ_CANONICAL': getattr(settings, 'DMOJ_CANONICAL', ''),
|
||||
'DMOJ_CANONICAL': settings.DMOJ_CANONICAL,
|
||||
}
|
||||
|
||||
|
||||
@ -43,8 +42,8 @@ def get_profile(request):
|
||||
|
||||
def comet_location(request):
|
||||
if request.is_secure():
|
||||
websocket = getattr(settings, 'EVENT_DAEMON_GET_SSL', settings.EVENT_DAEMON_GET)
|
||||
poll = getattr(settings, 'EVENT_DAEMON_POLL_SSL', settings.EVENT_DAEMON_POLL)
|
||||
websocket = settings.EVENT_DAEMON_GET
|
||||
poll = settings.EVENT_DAEMON_POLL
|
||||
else:
|
||||
websocket = settings.EVENT_DAEMON_GET
|
||||
poll = settings.EVENT_DAEMON_POLL
|
||||
@ -105,9 +104,9 @@ def misc_config(request):
|
||||
|
||||
|
||||
def site_name(request):
|
||||
return {'SITE_NAME': getattr(settings, 'SITE_NAME', 'DMOJ'),
|
||||
'SITE_LONG_NAME': getattr(settings, 'SITE_LONG_NAME', getattr(settings, 'SITE_NAME', 'DMOJ')),
|
||||
'SITE_ADMIN_EMAIL': getattr(settings, 'SITE_ADMIN_EMAIL', False)}
|
||||
return {'SITE_NAME': settings.SITE_NAME,
|
||||
'SITE_LONG_NAME': settings.SITE_LONG_NAME,
|
||||
'SITE_ADMIN_EMAIL': settings.SITE_ADMIN_EMAIL}
|
||||
|
||||
|
||||
def math_setting(request):
|
||||
@ -116,7 +115,7 @@ def math_setting(request):
|
||||
if request.user.is_authenticated:
|
||||
engine = request.profile.math_engine
|
||||
else:
|
||||
engine = getattr(settings, 'MATHOID_DEFAULT_TYPE', 'auto')
|
||||
engine = settings.MATHOID_DEFAULT_TYPE
|
||||
if engine == 'auto':
|
||||
engine = 'mml' if bool(getattr(settings, 'MATHOID_URL', False)) and caniuse.mathml == SUPPORT else 'jax'
|
||||
engine = 'mml' if bool(settings.MATHOID_URL) and caniuse.mathml == SUPPORT else 'jax'
|
||||
return {'MATH_ENGINE': engine, 'REQUIRE_JAX': engine == 'jax', 'caniuse': caniuse}
|
||||
|
@ -10,7 +10,7 @@ class TimezoneMiddleware(object):
|
||||
self.get_response = get_response
|
||||
|
||||
def get_timezone(self, request):
|
||||
tzname = getattr(settings, 'DEFAULT_USER_TIME_ZONE', 'America/Toronto')
|
||||
tzname = settings.DEFAULT_USER_TIME_ZONE
|
||||
if request.profile:
|
||||
tzname = request.profile.timezone
|
||||
return pytz.timezone(tzname)
|
||||
|
@ -39,9 +39,9 @@ class CamoClient(object):
|
||||
obj.set('data', self.rewrite_url(obj.get('data')))
|
||||
|
||||
|
||||
if getattr(settings, 'DMOJ_CAMO_URL', None) and getattr(settings, 'DMOJ_CAMO_KEY', None):
|
||||
if settings.DMOJ_CAMO_URL and settings.DMOJ_CAMO_KEY:
|
||||
client = CamoClient(settings.DMOJ_CAMO_URL, key=settings.DMOJ_CAMO_KEY,
|
||||
excluded=getattr(settings, 'DMOJ_CAMO_EXCLUDE', ()),
|
||||
https=getattr(settings, 'DMOJ_CAMO_HTTPS', False))
|
||||
excluded=settings.DMOJ_CAMO_EXCLUDE,
|
||||
https=settings.DMOJ_CAMO_HTTPS)
|
||||
else:
|
||||
client = None
|
||||
|
@ -49,13 +49,13 @@ class MathoidMathParser(object):
|
||||
self.mathoid_url = settings.MATHOID_URL
|
||||
self.cache = HashFileCache(settings.MATHOID_CACHE_ROOT,
|
||||
settings.MATHOID_CACHE_URL,
|
||||
getattr(settings, 'MATHOID_GZIP', False))
|
||||
settings.MATHOID_GZIP)
|
||||
|
||||
mml_cache = getattr(settings, 'MATHOID_MML_CACHE', None)
|
||||
mml_cache = settings.MATHOID_MML_CACHE
|
||||
self.mml_cache = mml_cache and caches[mml_cache]
|
||||
self.css_cache = caches[getattr(settings, 'MATHOID_CSS_CACHE', 'default')]
|
||||
self.css_cache = caches[settings.MATHOID_CSS_CACHE]
|
||||
|
||||
self.mml_cache_ttl = getattr(settings, 'MATHOID_MML_CACHE_TTL', 86400)
|
||||
self.mml_cache_ttl = settings.MATHOID_MML_CACHE_TTL
|
||||
|
||||
def query_mathoid(self, formula, hash):
|
||||
self.cache.create(hash)
|
||||
|
@ -19,7 +19,7 @@ else:
|
||||
|
||||
class ProblemDataStorage(FileSystemStorage):
|
||||
def __init__(self):
|
||||
super(ProblemDataStorage, self).__init__(getattr(settings, 'DMOJ_PROBLEM_DATA_ROOT', None))
|
||||
super(ProblemDataStorage, self).__init__(settings.DMOJ_PROBLEM_DATA_ROOT)
|
||||
|
||||
def url(self, name):
|
||||
path = split_path_first(name)
|
||||
|
@ -5,4 +5,4 @@ if 'newsletter' in settings.INSTALLED_APPS:
|
||||
else:
|
||||
Subscription = None
|
||||
|
||||
newsletter_id = None if Subscription is None else getattr(settings, 'NEWSLETTER_ID_ON_REGISTER', None)
|
||||
newsletter_id = None if Subscription is None else settings.DMOJ_NEWSLETTER_ID_ON_REGISTER
|
||||
|
@ -19,9 +19,9 @@ class TexoidRenderer(object):
|
||||
def __init__(self):
|
||||
self.cache = HashFileCache(settings.TEXOID_CACHE_ROOT,
|
||||
settings.TEXOID_CACHE_URL,
|
||||
getattr(settings, 'TEXOID_GZIP', False))
|
||||
self.meta_cache = caches[getattr(settings, 'TEXOID_META_CACHE', 'default')]
|
||||
self.meta_cache_ttl = getattr(settings, 'TEXOID_META_CACHE_TTL', 86400)
|
||||
settings.TEXOID_GZIP)
|
||||
self.meta_cache = caches[settings.TEXOID_META_CACHE]
|
||||
self.meta_cache_ttl = settings.TEXOID_META_CACHE_TTL
|
||||
|
||||
def query_texoid(self, document, hash):
|
||||
self.cache.create(hash)
|
||||
|
@ -1,3 +1,4 @@
|
||||
from django.conf import settings
|
||||
from django.db.models import Count, Max, Q
|
||||
from django.http import Http404
|
||||
from django.urls import reverse
|
||||
@ -39,7 +40,7 @@ class PostList(ListView):
|
||||
context['page_prefix'] = reverse('blog_post_list')
|
||||
context['comments'] = Comment.most_recent(self.request.user, 10)
|
||||
context['new_problems'] = Problem.objects.filter(is_public=True, is_organization_private=False) \
|
||||
.order_by('-date', '-id')[:7]
|
||||
.order_by('-date', '-id')[:settings.DMOJ_BLOG_NEW_PROBLEM_COUNT]
|
||||
context['page_titles'] = CacheDict(lambda page: Comment.get_page_title(page))
|
||||
|
||||
context['has_clarifications'] = False
|
||||
@ -71,7 +72,8 @@ class PostList(ListView):
|
||||
.exclude(problem__in=user_completed_ids(user))
|
||||
.values_list('problem__code', 'problem__name', 'problem__points')
|
||||
.annotate(points=Max('points'), latest=Max('date'))
|
||||
.order_by('-latest'))[:7]
|
||||
.order_by('-latest')
|
||||
[:settings.DMOJ_BLOG_RECENTLY_ATTEMPTED_PROBLEMS_COUNT])
|
||||
|
||||
visible_contests = Contest.objects.filter(is_visible=True).order_by('start_time')
|
||||
q = Q(is_private=False, is_organization_private=False)
|
||||
|
@ -115,7 +115,7 @@ class JoinOrganization(OrganizationMembershipChange):
|
||||
if not org.is_open:
|
||||
return generic_message(request, _('Joining organization'), _('This organization is not open.'))
|
||||
|
||||
max_orgs = getattr(settings, 'DMOJ_USER_MAX_ORGANIZATION_COUNT', 3)
|
||||
max_orgs = settings.DMOJ_USER_MAX_ORGANIZATION_COUNT
|
||||
if profile.organizations.filter(is_open=True).count() >= max_orgs:
|
||||
return generic_message(
|
||||
request, _('Joining organization'),
|
||||
|
@ -25,7 +25,6 @@ from django.views.generic import ListView, View
|
||||
from django.views.generic.base import TemplateResponseMixin
|
||||
from django.views.generic.detail import SingleObjectMixin
|
||||
|
||||
from django_ace.widgets import ACE_URL
|
||||
from judge.comments import CommentedDetailView
|
||||
from judge.forms import ProblemCloneForm, ProblemSubmitForm
|
||||
from judge.models import ContestProblem, ContestSubmission, Judge, Language, Problem, ProblemGroup, \
|
||||
@ -642,7 +641,7 @@ def problem_submit(request, problem=None, submission=None):
|
||||
'no_judges': not form.fields['language'].queryset,
|
||||
'submission_limit': submission_limit,
|
||||
'submissions_left': submissions_left,
|
||||
'ACE_URL': ACE_URL,
|
||||
'ACE_URL': settings.ACE_URL,
|
||||
|
||||
'default_lang': default_lang,
|
||||
})
|
||||
|
@ -19,7 +19,7 @@ from judge.utils.subscription import Subscription, newsletter_id
|
||||
from judge.widgets import Select2MultipleWidget, Select2Widget
|
||||
|
||||
valid_id = re.compile(r'^\w+$')
|
||||
bad_mail_regex = list(map(re.compile, getattr(settings, 'BAD_MAIL_PROVIDER_REGEX', ())))
|
||||
bad_mail_regex = list(map(re.compile, settings.BAD_MAIL_PROVIDER_REGEX))
|
||||
|
||||
|
||||
class CustomRegistrationForm(RegistrationForm):
|
||||
@ -46,7 +46,7 @@ class CustomRegistrationForm(RegistrationForm):
|
||||
'is allowed per address.') % self.cleaned_data['email'])
|
||||
if '@' in self.cleaned_data['email']:
|
||||
domain = self.cleaned_data['email'].split('@')[-1].lower()
|
||||
if (domain in getattr(settings, 'BAD_MAIL_PROVIDERS', ()) or
|
||||
if (domain in settings.BAD_MAIL_PROVIDERS or
|
||||
any(regex.match(domain) for regex in bad_mail_regex)):
|
||||
raise forms.ValidationError(gettext('Your email provider is not allowed due to history of abuse. '
|
||||
'Please use a reputable email provider.'))
|
||||
@ -61,11 +61,11 @@ class RegistrationView(OldRegistrationView):
|
||||
def get_context_data(self, **kwargs):
|
||||
if 'title' not in kwargs:
|
||||
kwargs['title'] = self.title
|
||||
tzmap = getattr(settings, 'TIMEZONE_MAP', None)
|
||||
tzmap = settings.TIMEZONE_MAP
|
||||
kwargs['TIMEZONE_MAP'] = tzmap or 'http://momentjs.com/static/img/world.png'
|
||||
kwargs['TIMEZONE_BG'] = getattr(settings, 'TIMEZONE_BG', None if tzmap else '#4E7CAD')
|
||||
kwargs['TIMEZONE_BG'] = settings.TIMEZONE_BG if tzmap else '#4E7CAD'
|
||||
kwargs['password_validators'] = get_default_password_validators()
|
||||
kwargs['tos_url'] = getattr(settings, 'TERMS_OF_SERVICE_URL', None)
|
||||
kwargs['tos_url'] = settings.TERMS_OF_SERVICE_URL
|
||||
return super(RegistrationView, self).get_context_data(**kwargs)
|
||||
|
||||
def register(self, form):
|
||||
@ -86,8 +86,8 @@ class RegistrationView(OldRegistrationView):
|
||||
|
||||
def get_initial(self, *args, **kwargs):
|
||||
initial = super(RegistrationView, self).get_initial(*args, **kwargs)
|
||||
initial['timezone'] = getattr(settings, 'DEFAULT_USER_TIME_ZONE', 'America/Toronto')
|
||||
initial['language'] = Language.objects.get(key=getattr(settings, 'DEFAULT_USER_LANGUAGE', 'PY2'))
|
||||
initial['timezone'] = settings.DEFAULT_USER_TIME_ZONE
|
||||
initial['language'] = Language.objects.get(key=settings.DEFAULT_USER_LANGUAGE)
|
||||
return initial
|
||||
|
||||
|
||||
|
@ -36,7 +36,7 @@ def repeat_chain(iterable):
|
||||
|
||||
def language_data(request, language_count=Language.objects.annotate(count=Count('submission'))):
|
||||
languages = language_count.filter(count__gt=0).values('key', 'name', 'count').order_by('-count')
|
||||
threshold = getattr(settings, 'DMOJ_STATS_LANGUAGE_THRESHOLD', 10)
|
||||
threshold = settings.DMOJ_STATS_LANGUAGE_THRESHOLD
|
||||
num_languages = min(len(languages), threshold)
|
||||
other_count = sum(map(itemgetter('count'), languages[num_languages:]))
|
||||
|
||||
|
@ -24,7 +24,7 @@ from reversion import revisions
|
||||
|
||||
from judge.forms import ProfileForm, newsletter_id
|
||||
from judge.models import Profile, Rating, Submission
|
||||
from judge.performance_points import PP_ENTRIES, get_pp_breakdown
|
||||
from judge.performance_points import get_pp_breakdown
|
||||
from judge.ratings import rating_class, rating_progress
|
||||
from judge.utils.problems import contest_completed_ids, user_completed_ids
|
||||
from judge.utils.ranker import ranker
|
||||
@ -188,7 +188,7 @@ class UserPerformancePointsAjax(UserProblemsPage):
|
||||
context = super(UserPerformancePointsAjax, self).get_context_data(**kwargs)
|
||||
try:
|
||||
start = int(self.request.GET.get('start', 0))
|
||||
end = int(self.request.GET.get('end', PP_ENTRIES))
|
||||
end = int(self.request.GET.get('end', settings.DMOJ_PP_ENTRIES))
|
||||
if start < 0 or end < 0 or start > end:
|
||||
raise ValueError
|
||||
except ValueError:
|
||||
@ -248,12 +248,12 @@ def edit_profile(request):
|
||||
form.fields['newsletter'].initial = subscription.subscribed
|
||||
form.fields['test_site'].initial = request.user.has_perm('judge.test_site')
|
||||
|
||||
tzmap = getattr(settings, 'TIMEZONE_MAP', None)
|
||||
tzmap = settings.TIMEZONE_MAP
|
||||
return render(request, 'user/edit-profile.html', {
|
||||
'form': form, 'title': _('Edit profile'), 'profile': profile,
|
||||
'has_math_config': bool(getattr(settings, 'MATHOID_URL', False)),
|
||||
'has_math_config': bool(settings.MATHOID_URL),
|
||||
'TIMEZONE_MAP': tzmap or 'http://momentjs.com/static/img/world.png',
|
||||
'TIMEZONE_BG': getattr(settings, 'TIMEZONE_BG', None if tzmap else '#4E7CAD'),
|
||||
'TIMEZONE_BG': settings.TIMEZONE_BG if tzmap else '#4E7CAD',
|
||||
})
|
||||
|
||||
|
||||
|
@ -61,7 +61,7 @@ class DetectTimezone(View):
|
||||
raise Http404()
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
backend = getattr(settings, 'TIMEZONE_DETECT_BACKEND', None)
|
||||
backend = settings.TIMEZONE_DETECT_BACKEND
|
||||
try:
|
||||
lat, long = float(request.GET['lat']), float(request.GET['long'])
|
||||
except (ValueError, KeyError):
|
||||
|
@ -34,7 +34,7 @@ class CompressorWidgetMixin(object):
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
if getattr(settings, 'COMPRESS_ENABLED', not getattr(settings, 'DEBUG', False)):
|
||||
if getattr(settings, 'COMPRESS_ENABLED', not settings.DEBUG):
|
||||
@property
|
||||
def media(self):
|
||||
media = super().media
|
||||
|
@ -92,9 +92,8 @@ class Select2Mixin(object):
|
||||
https://docs.djangoproject.com/en/1.8/topics/forms/media/#media-as-a-dynamic-property
|
||||
"""
|
||||
return forms.Media(
|
||||
js=(getattr(settings, 'SELECT2_JS_URL', DEFAULT_SELECT2_JS),
|
||||
'django_select2.js'),
|
||||
css={'screen': (getattr(settings, 'SELECT2_CSS_URL', DEFAULT_SELECT2_CSS),)},
|
||||
js=(settings.SELECT2_JS_URL, 'django_select2.js'),
|
||||
css={'screen': settings.SELECT2_CSS_URL},
|
||||
)
|
||||
|
||||
media = property(_get_media)
|
||||
|
Loading…
Reference in New Issue
Block a user