diff --git a/dmoj/throttle_mail.py b/dmoj/throttle_mail.py index 485e5f11af..176dc597b5 100644 --- a/dmoj/throttle_mail.py +++ b/dmoj/throttle_mail.py @@ -8,7 +8,7 @@ def new_email(): - cache.add('error_email_throttle', 0, getattr(settings, 'EMAIL_THROTTLING', DEFAULT_THROTTLE)[1]) + cache.add('error_email_throttle', 0, getattr(settings, 'DMOJ_EMAIL_THROTTLING', DEFAULT_THROTTLE)[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, 'EMAIL_THROTTLING', DEFAULT_THROTTLE)[0] + self.throttle = getattr(settings, 'DMOJ_EMAIL_THROTTLING', DEFAULT_THROTTLE)[0] def emit(self, record): try: diff --git a/judge/admin/contest.py b/judge/admin/contest.py index 7ef336b52f..5414d24690 100644 --- a/judge/admin/contest.py +++ b/judge/admin/contest.py @@ -171,7 +171,7 @@ def rejudge_view(self, request, contest_id, problem_id): 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, 'REJUDGE_SUBMISSION_LIMIT', 10): + len(queryset) > getattr(settings, 'DMOJ_SUBMISSIONS_REJUDGE_LIMIT', 10): self.message_user(request, ugettext('You do not have the permission to rejudge THAT many submissions.'), level=messages.ERROR) return diff --git a/judge/admin/submission.py b/judge/admin/submission.py index 87dfd36aee..f3fd041c7a 100644 --- a/judge/admin/submission.py +++ b/judge/admin/submission.py @@ -135,7 +135,7 @@ def judge(self, request, queryset): return queryset = queryset.order_by('id') if not request.user.has_perm('judge.rejudge_submission_lot') and \ - queryset.count() > getattr(settings, 'REJUDGE_SUBMISSION_LIMIT', 10): + queryset.count() > getattr(settings, 'DMOJ_SUBMISSIONS_REJUDGE_LIMIT', 10): self.message_user(request, ugettext('You do not have the permission to rejudge THAT many submissions.'), level=messages.ERROR) return diff --git a/judge/comments.py b/judge/comments.py index 5bc456e4e3..112c36bc9d 100644 --- a/judge/comments.py +++ b/judge/comments.py @@ -117,6 +117,6 @@ def get_context_data(self, **kwargs): 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, 'COMMENT_VOTE_HIDE_THRESHOLD', -5) + context['vote_hide_threshold'] = getattr(settings, 'DMOJ_COMMENT_VOTE_HIDE_THRESHOLD', -5) return context diff --git a/judge/forms.py b/judge/forms.py index 3fc939b8a9..0607940eef 100644 --- a/judge/forms.py +++ b/judge/forms.py @@ -50,7 +50,7 @@ class Meta: def clean(self): organizations = self.cleaned_data.get('organizations') or [] - max_orgs = getattr(settings, 'MAX_USER_ORGANIZATION_COUNT', 3) + max_orgs = getattr(settings, 'DMOJ_USER_MAX_ORGANIZATION_COUNT', 3) if sum(org.is_open for org in organizations) > max_orgs: raise ValidationError(_('You may not be part of more than {count} public organizations.').format(count=max_orgs)) diff --git a/judge/migrations/0055_add_performance_points.py b/judge/migrations/0055_add_performance_points.py index 5ecd7c98a3..1f7a5af3a3 100644 --- a/judge/migrations/0055_add_performance_points.py +++ b/judge/migrations/0055_add_performance_points.py @@ -11,13 +11,15 @@ def gen_pp(apps, schema_editor): Profile = apps.get_model('judge', 'Profile') Problem = apps.get_model('judge', 'Problem') - table = (lambda x: [pow(x, i) for i in xrange(100)])(getattr(settings, 'PP_STEP', 0.95)) - bonus_function = getattr(settings, 'PP_BONUS_FUNCTION', lambda n: 300 * (1 - 0.997 ** n)) + _pp_step = getattr(settings, 'DMOJ_PP_STEP', 0.95) + table = [pow(_pp_step, i) for i in xrange(getattr(settings, 'DMOJ_PP_ENTRIES', 100))] + bonus_function = getattr(settings, 'DMOJ_PP_BONUS_FUNCTION', lambda n: 300 * (1 - 0.997 ** n)) for row in Profile.objects.all(): data = (Problem.objects.filter(submission__user=row, submission__points__isnull=False, is_public=True) .annotate(max_points=Max('submission__points')).order_by('-max_points') .values_list('max_points', flat=True)) - extradata = Problem.objects.filter(submission__user=row, submission__result='AC', is_public=True).values('id').distinct().count() + extradata = Problem.objects.filter(submission__user=row, submission__result='AC', is_public=True) \ + .values('id').distinct().count() size = min(len(data), len(table)) row.performance_points = sum(map(mul, table[:size], data[:size])) + bonus_function(extradata) row.save() diff --git a/judge/models/profile.py b/judge/models/profile.py index 6e9cea1535..ad727c36b3 100644 --- a/judge/models/profile.py +++ b/judge/models/profile.py @@ -120,13 +120,17 @@ def organization(self): def username(self): return self.user.username - def calculate_points(self, table=(lambda x: [pow(x, i) for i in xrange(100)])(getattr(settings, 'PP_STEP', 0.95))): + _pp_step = getattr(settings, 'DMOJ_PP_STEP', 0.95) + _pp_table = [pow(_pp_step, i) for i in xrange(getattr(settings, 'DMOJ_PP_ENTRIES', 100))] + def calculate_points(self, table=_pp_table): from judge.models import Problem - data = (Problem.objects.filter(submission__user=self, submission__points__isnull=False, is_public=True, is_organization_private=False) - .annotate(max_points=Max('submission__points')).order_by('-max_points') - .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, 'PP_BONUS_FUNCTION', lambda n: 300 * (1 - 0.997 ** n)) + data = (Problem.objects.filter(submission__user=self, submission__points__isnull=False, is_public=True, + is_organization_private=False) + .annotate(max_points=Max('submission__points')).order_by('-max_points') + .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)) points = sum(data) problems = len(data) entries = min(len(data), len(table)) diff --git a/judge/pdf_problems.py b/judge/pdf_problems.py index 5526bdda4a..e56d582d8d 100644 --- a/judge/pdf_problems.py +++ b/judge/pdf_problems.py @@ -19,7 +19,7 @@ PUPPETEER_MODULE = getattr(settings, 'PUPPETEER_MODULE', '/usr/lib/node_modules/puppeteer') HAS_PUPPETEER = os.access(NODE_PATH, os.X_OK) and os.path.isdir(PUPPETEER_MODULE) -HAS_PDF = (os.path.isdir(getattr(settings, 'PROBLEM_PDF_CACHE', '')) and +HAS_PDF = (os.path.isdir(getattr(settings, 'DMOJ_PDF_PROBLEM_CACHE', '')) and (HAS_PHANTOMJS or HAS_SLIMERJS or HAS_PUPPETEER)) EXIFTOOL = getattr(settings, 'EXIFTOOL', '/usr/bin/exiftool') @@ -33,7 +33,7 @@ class BasePdfMaker(object): title = None def __init__(self, dir=None, clean_up=True): - self.dir = dir or os.path.join(getattr(settings, 'PROBLEM_PDF_TEMP_DIR', tempfile.gettempdir()), + self.dir = dir or os.path.join(getattr(settings, 'DMOJ_PDF_PROBLEM_TEMP_DIR', tempfile.gettempdir()), str(uuid.uuid1())) self.proc = None self.log = None diff --git a/judge/performance_points.py b/judge/performance_points.py index dc3d6585ce..f6cf4e5ad9 100644 --- a/judge/performance_points.py +++ b/judge/performance_points.py @@ -6,8 +6,8 @@ from judge.models import Submission from judge.timezone import from_database_time -PP_STEP = getattr(settings, 'PP_STEP', 0.95) -PP_ENTRIES = getattr(settings, 'PP_ENTRIES', 100) +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 xrange(PP_ENTRIES)] PPBreakdown = namedtuple('PPBreakdown', 'points weight scaled_points problem_name problem_code ' @@ -15,7 +15,7 @@ 'sub_short_status sub_long_status sub_lang') -def get_pp_breakdown(user, start=0, end=100): +def get_pp_breakdown(user, start=0, end=PP_ENTRIES): with connection.cursor() as cursor: cursor.execute(''' SELECT max_points_table.problem_code, diff --git a/judge/utils/camo.py b/judge/utils/camo.py index 8006980713..77552b03e3 100644 --- a/judge/utils/camo.py +++ b/judge/utils/camo.py @@ -36,9 +36,9 @@ def update_tree(self, doc): obj.set('data', self.rewrite_url(obj.get('data'))) -if getattr(settings, 'CAMO_URL', None) and getattr(settings, 'CAMO_KEY', None): - client = CamoClient(settings.CAMO_URL, key=settings.CAMO_KEY, - excluded=getattr(settings, 'CAMO_EXCLUDE', ()), - https=getattr(settings, 'CAMO_HTTPS', False)) +if getattr(settings, 'DMOJ_CAMO_URL', None) and getattr(settings, 'DMOJ_CAMO_KEY', None): + client = CamoClient(settings.DMOJ_CAMO_URL, key=settings.DMOJ_CAMO_KEY, + excluded=getattr(settings, 'DMOJ_CAMO_EXCLUDE', ()), + https=getattr(settings, 'DMOJ_CAMO_HTTPS', False)) else: client = None diff --git a/judge/utils/problem_data.py b/judge/utils/problem_data.py index 94feec2c55..de47e0b257 100644 --- a/judge/utils/problem_data.py +++ b/judge/utils/problem_data.py @@ -19,7 +19,7 @@ def split_path_first(path): class ProblemDataStorage(FileSystemStorage): def __init__(self): - super(ProblemDataStorage, self).__init__(getattr(settings, 'PROBLEM_DATA_ROOT', None)) + super(ProblemDataStorage, self).__init__(getattr(settings, 'DMOJ_PROBLEM_DATA_ROOT', None)) def url(self, name): path = split_path_first(name) diff --git a/judge/views/organization.py b/judge/views/organization.py index 6146ae30ca..852c3518db 100644 --- a/judge/views/organization.py +++ b/judge/views/organization.py @@ -126,7 +126,7 @@ def handle(self, request, org, profile): if not org.is_open: return generic_message(request, _('Joining organization'), _('This organization is not open.')) - max_orgs = getattr(settings, 'MAX_USER_ORGANIZATION_COUNT', 3) + max_orgs = getattr(settings, 'DMOJ_USER_MAX_ORGANIZATION_COUNT', 3) if profile.organizations.filter(is_open=True).count() >= max_orgs: return generic_message(request, _('Joining organization'), _('You may not be part of more than {count} public organizations.').format(count=max_orgs))